TileType GetTileType(XElement growsIn, GamePack package) { string typeNameOrID = growsIn.Attribute(typeAttr)?.Value; if (typeNameOrID == null) { Urho.IO.Log.Write(LogLevel.Warning, $"Invalid element in {Name} building type's extension element: {growsInElem} element missing {typeAttr} attribute."); return(null); } try { if (int.TryParse(typeNameOrID, out int id)) { return(package.GetTileType(id)); } return(package.GetTileType(typeNameOrID)); } catch (ArgumentOutOfRangeException) { Urho.IO.Log.Write(LogLevel.Warning, $"Invalid element in {Name} building type's extension element: {growsInElem} element invalid value in {typeAttr} attribute."); return(null); } }
public GeometryMaterials(XElement element, GamePack package) { if (element.Name != MaterialXml.Inst.GeometryMaterial) { throw new ArgumentException($"Invalid element, expected {MaterialXml.Inst.GeometryMaterial}, got {element.Name}"); } this.materials = new List <Tuple <uint, Material> >(); foreach (XElement pathElement in element.Elements()) { XAttribute indexAttr = pathElement.Attribute(GeometryMaterialXml.Inst.IndexAttribute) ?? throw new ArgumentException("GeometryMaterials element is not valid according to GamePack.xsd, missing index attribute"); uint index = uint.TryParse(indexAttr.Value, out var value) ? value : throw new ArgumentException("GeometryMaterials element is not valid according to GamePack.xsd, invalid index value type"); Material material; try { string path = FileManager.ReplaceDirectorySeparators(pathElement.Value); material = package.PackageManager.GetMaterial(path); } catch (Exception e) { throw new ArgumentException("Loading material failed, probably wrong path in the MaterialPath element", e); } materials.Add(Tuple.Create(index, material)); } }
public void UnloadActivePack() { var activePackage = ActivePackage; ActivePackage = null; UnloadPackage(activePackage); }
/// <summary> /// Loads a binary prefab based on the <paramref name="assetsElement"/>. /// </summary> /// <param name="assetsElement">XML containing the path to the binary prefab.</param> /// <param name="package">GamePack of the level.</param> /// <exception cref="ArgumentNullException">Thrown when <paramref name="assetsElement"/> is null</exception> /// <exception cref="ArgumentException">Thrown when <paramref name="assetsElement"/> xml element is not valid, either is not the <see cref="EntityXml.Inst.Assets"/> element /// or has a wrong type specified</exception> /// <exception cref="IOException">When the file specified by the path in the <see cref="AssetsElementXml.Inst.Path"/> cannot be opened</exception> /// <exception cref="ResourceLoadingException"> Thrown when the file could not be found </exception> public BinaryPrefabAssetContainer(XElement assetsElement, GamePack package) { CheckWithType(assetsElement, AssetsXml.BinaryPrefabType); var relativePath = GetPath(assetsElement); this.file = package.PackageManager.GetFile(relativePath, true); }
/// <summary> /// Loads building type from the given <paramref name="xml"/> element. /// Expects that the <paramref name="xml"/> is validated against the <see cref="PackageManager.schemas"/>. /// </summary> /// <param name="xml">The XML element to load the building from.</param> /// <param name="package">The package this Xml element is from.</param> public void Load(XElement xml, GamePack package) { Package = package; XElement extensionElem = null; string assemblyPath = null; try { ID = XmlHelpers.GetID(xml); Name = XmlHelpers.GetName(xml); IconRectangle = XmlHelpers.GetIconRectangle(xml); Size = XmlHelpers.GetIntVector2(xml.Element(BuildingTypeXml.Inst.Size)); assemblyPath = XmlHelpers.GetPath(xml.Element(BuildingTypeXml.Inst.AssemblyPath)); extensionElem = XmlHelpers.GetExtensionElement(xml); } catch (Exception e) { LoadError($"Building type loading failed: Invalid XML of the package {package.Name}", e); } try { Assets = AssetContainer.FromXml(xml.Element(BuildingTypeXml.Inst.Assets), package); } catch (Exception e) { LoadError($"Building type \"{Name}\"[{ID}] loading failed: Asset instantiation failed with exception: {e.Message}", e); } try { Plugin = TypePlugin.LoadTypePlugin <BuildingTypePlugin>(assemblyPath, package, Name, ID, extensionElem); } catch (Exception e) { LoadError($"Building type \"{Name}\"[{ID}] loading failed: Plugin loading failed with exception: {e.Message}", e); } }
/// <summary> /// Loads collision shape described by the XML <paramref name="element"/>. /// </summary> /// <param name="element">XML describing the collision shape.</param> /// <param name="package">Source of the XML.</param> /// <returns></returns> /// <exception cref="ArgumentNullException">Thrown when the <paramref name="element"/> is null</exception> /// <exception cref="ArgumentException">Throw when the <paramref name="element"/> does not conform to the xml schema</exception> public static CollisionShapeLoader Load(XElement element, GamePack package) { if (element == null) { throw new ArgumentNullException(nameof(element), "Element was null"); } if (element.Name != AssetsXml.Inst.CollisionShape) { throw new ArgumentException("Invalid element", nameof(element)); } XElement child = element.Elements().First(); ConcreteShape newShape; if (dispatch.TryGetValue(child.Name, out var loadShape)) { newShape = loadShape(child, package); } else { throw new ArgumentException($"Element {element} was not valid according to GamePack.xml, unexpected child {child}", nameof(element)); } return(new CollisionShapeLoader(newShape)); }
/// <summary> /// Loads the PlayerType contents from the <paramref name="xml"/>. /// </summary> /// <param name="xml">The xml data to load.</param> /// <param name="package">Tha source package of the xml.</param> public void Load(XElement xml, GamePack package) { Package = package; string path = null; XElement extensionElem = null; try { ID = XmlHelpers.GetID(xml); Category = StringToCategory(xml.Attribute("category").Value); Name = XmlHelpers.GetName(xml); IconRectangle = XmlHelpers.GetIconRectangle(xml); path = XmlHelpers.GetPath(xml.Element(PlayerAITypeXml.Inst.AssemblyPath)); extensionElem = XmlHelpers.GetExtensionElement(xml); } catch (Exception e) { LoadError($"Player type loading failed: Invalid XML of the package {package.Name}", e); } try { Plugin = TypePlugin.LoadTypePlugin <PlayerAITypePlugin>(path, package, Name, ID, extensionElem); } catch (Exception e) { LoadError($"Player type \"{Name}\"[{ID}] loading failed: Plugin loading failed with exception: {e.Message}", e); } }
/// <summary> /// Loads the level logic type from the package Xml. /// </summary> /// <param name="xml">Xml element holding the data for this level logic type.</param> /// <param name="package">The source package of the Xml.</param> public void Load(XElement xml, GamePack package) { Package = package; string assemblyPath = null; XElement extensionElem = null; try { ID = XmlHelpers.GetID(xml); Name = XmlHelpers.GetName(xml); assemblyPath = XmlHelpers.GetPath(xml.Element(LevelLogicTypeXml.Inst.AssemblyPath)); extensionElem = xml.Element(LevelLogicTypeXml.Inst.Extension); } catch (Exception e) { LoadError($"Level logic type loading failed: Invalid XML of the package {package.Name}", e); } try { Plugin = TypePlugin.LoadTypePlugin <LevelLogicTypePlugin>(assemblyPath, package, Name, ID, extensionElem); } catch (Exception e) { LoadError($"Level logic type \"{Name}\"[{ID}] loading failed: Plugin loading failed with exception: {e.Message}", e); } }
protected override void Initialize(XElement extensionElement, GamePack package) { XElement canPass = extensionElement.Element(package.PackageManager.GetQualifiedXName(PassableTileTypesElement)); PassableTileTypes = ViableTileTypes.FromXml(canPass, package); }
/// <summary> /// <para>Unloads the <see cref="ActivePackage"/> if there is any and then loads /// the package represented by <paramref name="package"/></para> /// /// <para>Optionally can signal loading progress if provided with <paramref name="loadingProgress"/></para> /// </summary> /// <param name="package">Representation of the package to be loaded</param> /// <param name="loadingProgress">Optional watcher of the loading progress</param> /// <returns>A task that represents the asynchronous loading of the package</returns> /// <exception cref="PackageLoadingException">Thrown when the loading of the new package failed</exception> public async Task <GamePack> LoadPackage(GamePackRep package, IProgressEventWatcher loadingProgress = null) { const double clearPartSize = 10; const double loadPartSize = 90; if (loadingProgress == null) { loadingProgress = new ProgressWatcher(); } loadingProgress.SendTextUpdate("Clearing previous games"); if (ActivePackage != null) { UnloadActivePack(); } loadingProgress.SendUpdate(clearPartSize, "Cleared previous games"); resourceCache.AddResourceDir(Path.Combine(App.Files.DynamicDirPath, package.XmlDirectoryPath), 1); loadingProgress.SendTextUpdate("Loading new package"); ActivePackage = await package.LoadPack(schemas, new ProgressWatcher(loadingProgress, loadPartSize)); loadingProgress.SendFinished(); return(ActivePackage); }
/// <summary> /// /// </summary> /// <param name="assetsElement"></param> /// <exception cref="ResourceNotFoundException">Thrown when the xml prefab file could not be found</exception> public XmlPrefabAssetContainer(XElement assetsElement, GamePack package) { CheckWithType(assetsElement, AssetsXml.XmlPrefabType); string relativePath = GetPath(assetsElement); this.file = package.PackageManager.GetXmlFile(relativePath, true); }
public async Task <IActionResult> AddGamePack([FromBody] GamePack gamePack) { int authorizedId = User.GetUserId(); SyncBase answer = await gameService.AddGamePackAsync(authorizedId, gamePack); return(Ok(answer)); }
public async Task <IActionResult> UpdateGame(int gameId) { string source = System.IO.File.ReadAllText("AppData/CardsGames.txt"); var parser = new TextParser(source); GamePack gamePack = parser.GetGameObject(gameId); SyncBase answer = await gameService.AddGamePackAsync(122, gamePack); return(Ok(gamePack)); }
private static GamePack ParseTheme(string theme) { var gamePack = new GamePack { CreationInfo = GetCreationInfo(theme), LevelPacks = GetLevelPacks(theme) }; return(gamePack); }
public GamePackVM(GamePack gamePack) { Data = gamePack; GameSets = new List <GameSetVM>(); foreach (var gameSet in gamePack.GameSets) { GameSets.Add(new GameSetVM(gameSet)); } }
protected override void Initialize(XElement extensionElement, GamePack package) { Chicken = (ChickenType)package.GetUnitType(ChickenType.TypeID).Plugin; Wolf = (WolfType)package.GetUnitType(WolfType.TypeID).Plugin; Gate = (GateType)package.GetBuildingType(GateType.TypeID).Plugin; Tower = (TowerType)package.GetBuildingType(TowerType.TypeID).Plugin; Keep = (KeepType)package.GetBuildingType(KeepType.TypeID).Plugin; Wall = (WallType)package.GetBuildingType(WallType.TypeID).Plugin; TreeCutter = (TreeCutterType)package.GetBuildingType(TreeCutterType.TypeID).Plugin; }
public void Setup(GameInfoExtended game, string text, GamePack gamePack) { linkedGame = game; button.GetComponentInChildren <Text>().text = text; completedIcon.SetActive(game.completed); bool isAvailable = game.IsAvailable(gamePack); lockedIcon.SetActive(!isAvailable); button.interactable = isAvailable; button.onClick.AddListener(Clicked); }
void InitCheckbox(Spawner spawner, GamePack package) { var checkBox = ui.SelectionBar.CreateCheckBox(); checkBox.SetStyle("SelectionBarCheckBox"); checkBox.Texture = package.BuildingIconTexture; checkBox.ImageRect = spawner.UnitType.IconRectangle; checkBox.HoverOffset = new IntVector2(spawner.UnitType.IconRectangle.Width(), 0); checkBox.CheckedOffset = new IntVector2(2 * spawner.UnitType.IconRectangle.Width(), 0); checkBoxes.AddCheckBox(checkBox); spawners.Add(checkBox, spawner); }
public static Sphere FromXml(XElement sphereElement, GamePack package) { if (sphereElement.Name != ElementName) { throw new ArgumentException($"Expected element {ElementName}, got {sphereElement.Name}", nameof(sphereElement)); } float diameter = sphereElement.Element(CollisionShapeXml.Inst.Diameter).GetFloat(); Vector3 position = GetPosition(sphereElement); Quaternion rotation = GetRotation(sphereElement); return(new Sphere(diameter, position, rotation)); }
protected override void Initialize(XElement extensionElement, GamePack package) { MyTypeInstance = package.GetBuildingType(ID); XElement costElem = extensionElement.Element(package.PackageManager.GetQualifiedXName(CostElement)); Cost = Cost.FromXml(costElem, package); XElement canBuildOnElem = extensionElement.Element(package.PackageManager.GetQualifiedXName(CanBuildOnElement)); ViableTileTypes = ViableTileTypes.FromXml(canBuildOnElem, package); }
public static Box FromXml(XElement boxElement, GamePack package) { if (boxElement.Name != ElementName) { throw new ArgumentException($"Expected element {ElementName}, got {boxElement.Name}", nameof(boxElement)); } Vector3 size = boxElement.Element(CollisionShapeXml.Inst.Size).GetVector3(); Vector3 position = GetPosition(boxElement); Quaternion rotation = GetRotation(boxElement); return(new Box(size, position, rotation)); }
protected override void Initialize(XElement extensionElement, GamePack package) { XElement costElem = extensionElement.Element(package.PackageManager.GetQualifiedXName(CostElement)); cost = Cost.FromXml(costElem, package); XElement canPass = extensionElement.Element(package.PackageManager.GetQualifiedXName(PassableTileTypesElement)); PassableTileTypes = ViableTileTypes.FromXml(canPass, package); myType = package.GetUnitType(ID); }
/// <summary> /// Provided for construction of mock types for auxiliary uses. /// </summary> /// <param name="id">Identifier.</param> /// <param name="name">Name.</param> /// <param name="package">Package.</param> /// <param name="assets">Asset container.</param> /// <param name="iconRectangle">Icon rectangle in the <see cref="GamePack.UnitIconTexture"/></param> /// <param name="plugin">Plugin.</param> public UnitType(int id, string name, GamePack package, AssetContainer assets, IntRect iconRectangle, UnitTypePlugin plugin) { this.ID = id; this.Name = name; this.Package = package; this.Assets = assets; this.IconRectangle = iconRectangle; this.Plugin = plugin; }
public static ViableTileTypes FromXml(XElement viableTileTypesElement, GamePack package) { var tileTypes = new HashSet <TileType>(); foreach (var child in viableTileTypesElement.Elements()) { string tileTypeName = child.Name.LocalName; TileType tileType = package.GetTileType(tileTypeName); tileTypes.Add(tileType); } return(new ViableTileTypes(tileTypes)); }
public static Cylinder FromXml(XElement cylinderElement, GamePack package) { if (cylinderElement.Name != ElementName) { throw new ArgumentException($"Expected element {ElementName}, got {cylinderElement.Name}", nameof(cylinderElement)); } float diameter = cylinderElement.Element(CollisionShapeXml.Inst.Diameter).GetFloat(); float height = cylinderElement.Element(CollisionShapeXml.Inst.Height).GetFloat(); Vector3 position = GetPosition(cylinderElement); Quaternion rotation = GetRotation(cylinderElement); return(new Cylinder(diameter, height, position, rotation)); }
private GamePack CreateGamePack(string player1Name, string player2Name) { var gameBoard = new GameBoard(); var tilePack = CreateTilePack(); var player1Rack = new Rack(player1Name, true); var player2Rack = new Rack(player2Name, false); var dictionary = _englishDictionaryService.GetWords(); var gamePack = new GamePack(gameBoard, tilePack, player1Rack, player2Rack, dictionary); return(gamePack); }
/// <summary> /// Loads data of this resource type from the xml element from the package. /// </summary> /// <param name="xml">The xml element of the resource type.</param> /// <param name="package">The source package of the xml.</param> public void Load(XElement xml, GamePack package) { Package = package; try { ID = XmlHelpers.GetID(xml); Name = XmlHelpers.GetName(xml); IconRectangle = XmlHelpers.GetIconRectangle(xml); } catch (Exception e) { string message = $"Resource type loading failed: Invalid XML of the package {package.Name}"; Urho.IO.Log.Write(LogLevel.Error, message); throw new PackageLoadingException(message, e); } }
public static Cost FromXml(XElement costElem, GamePack package) { var costs = new Dictionary <ResourceType, double>(); foreach (var child in costElem.Elements()) { string resourceName = child.Name.LocalName; float resourceAmount = float.Parse(child.Value); ResourceType resourceType = package.GetResourceType(resourceName); costs.Add(resourceType, resourceAmount); } return(new Cost(costs)); }
/// <summary> /// Opens a file on the <paramref name="relativePath"/> in the <paramref name="package"/> directory /// /// If no package is specified, the <see cref="PackageManager.ActivePackage"/> is used /// </summary> /// <param name="relativePath">Path of the file relative to the package directory</param> /// <param name="fileMode"></param> /// <param name="fileAccess"></param> /// <param name="package"></param> /// <returns></returns> public Stream OpenDynamicFileInPackage(string relativePath, System.IO.FileMode fileMode, FileAccess fileAccess, GamePack package = null) { if (package == null) { package = MHUrhoApp.Instance.PackageManager.ActivePackage; } string basePath = package.DirectoryPath; string dynamicPath = Path.Combine(basePath, relativePath); return(OpenDynamicFile(dynamicPath, fileMode, fileAccess)); }
protected override void Initialize(XElement extensionElement, GamePack package) { MyTypeInstance = package.GetBuildingType(ID); XElement canBuildOnElem = extensionElement.Element(package.PackageManager.GetQualifiedXName(CanBuildOnElement)); ViableTileTypes = ViableTileTypes.FromXml(canBuildOnElem, package); XElement producedResourceElem = extensionElement.Element(package.PackageManager.GetQualifiedXName(ProducedResourceElement)); ProducedResource = package.GetResourceType(producedResourceElem.Value); ProductionRate = double.Parse(producedResourceElem.Attribute(ProductionRateAttribute).Value); }