public Tile(string s) : base(s) { locationSpecified = true; Game game = Game.Get(); foreach (KeyValuePair <string, TileSideData> kv in game.cd.tileSides) { typeDynamic = type; tileType = kv.Value; } }
public Tile(string name, Dictionary <string, string> data, Game game) : base(name, data) { locationSpecified = true; typeDynamic = type; // Get rotation if specified if (data.ContainsKey("rotation")) { rotation = int.Parse(data["rotation"]); } // Find the tileside that is used if (data.ContainsKey("side")) { // 'TileSide' prefix is optional, test both if (game.cd.tileSides.ContainsKey(data["side"])) { tileType = game.cd.tileSides[data["side"]]; } else if (game.cd.tileSides.ContainsKey("TileSide" + data["side"])) { tileType = game.cd.tileSides["TileSide" + data["side"]]; } else { // Fatal if not found Debug.Log("Error: Failed to located TileSide: " + data["side"] + "in quest component: " + name); Application.Quit(); } } else { // Fatal if missing Debug.Log("Error: No TileSide specified in quest component: " + name); Application.Quit(); } Draw(); }
// Add a section of an ini file to game content // name is from the ini file and must start with the type // path is relative and is used for images or other paths in the content void AddContent(string name, Dictionary <string, string> content, string path, string packID) { // Is this a "TileSide" entry? if (name.IndexOf(TileSideData.type) == 0) { TileSideData d = new TileSideData(name, content, path); // Ignore invalid entry if (d.name.Equals("")) { return; } // If we don't already have one then add this if (!tileSides.ContainsKey(name)) { tileSides.Add(name, d); d.sets.Add(packID); } // If we do replace if this has higher priority else if (tileSides[name].priority < d.priority) { tileSides.Remove(name); tileSides.Add(name, d); } // items of the same priority belong to multiple packs else if (tileSides[name].priority == d.priority) { tileSides[name].sets.Add(packID); } } // Is this a "Hero" entry? if (name.IndexOf(HeroData.type) == 0) { HeroData d = new HeroData(name, content, path); // Ignore invalid entry if (d.name.Equals("")) { return; } // If we don't already have one then add this if (!heros.ContainsKey(name)) { heros.Add(name, d); d.sets.Add(packID); } // If we do replace if this has higher priority else if (heros[name].priority < d.priority) { heros.Remove(name); heros.Add(name, d); } // items of the same priority belong to multiple packs else if (heros[name].priority == d.priority) { heros[name].sets.Add(packID); } } // Is this a "Monster" entry? if (name.IndexOf(MonsterData.type) == 0) { MonsterData d = new MonsterData(name, content, path); // Ignore invalid entry if (d.name.Equals("")) { return; } // Ignore monster activations if (name.IndexOf(ActivationData.type) != 0) { // If we don't already have one then add this if (!monsters.ContainsKey(name)) { monsters.Add(name, d); d.sets.Add(packID); } // If we do replace if this has higher priority else if (monsters[name].priority < d.priority) { monsters.Remove(name); monsters.Add(name, d); } // items of the same priority belong to multiple packs else if (monsters[name].priority == d.priority) { monsters[name].sets.Add(packID); } } } // Is this a "Activation" entry? if (name.IndexOf(ActivationData.type) == 0) { ActivationData d = new ActivationData(name, content, path); // Ignore invalid entry if (d.name.Equals("")) { return; } // If we don't already have one then add this if (!activations.ContainsKey(name)) { activations.Add(name, d); d.sets.Add(packID); } // If we do replace if this has higher priority else if (activations[name].priority < d.priority) { activations.Remove(name); activations.Add(name, d); } // items of the same priority belong to multiple packs else if (activations[name].priority == d.priority) { activations[name].sets.Add(packID); } } // Is this a "Token" entry? if (name.IndexOf(TokenData.type) == 0) { TokenData d = new TokenData(name, content, path); // Ignore invalid entry if (d.name.Equals("")) { return; } // If we don't already have one then add this if (!tokens.ContainsKey(name)) { tokens.Add(name, d); d.sets.Add(packID); } // If we do replace if this has higher priority else if (tokens[name].priority < d.priority) { tokens.Remove(name); tokens.Add(name, d); } // items of the same priority belong to multiple packs else if (tokens[name].priority == d.priority) { tokens[name].sets.Add(packID); } } // Is this a "Peril" entry? if (name.IndexOf(PerilData.type) == 0) { PerilData d = new PerilData(name, content); // Ignore invalid entry if (d.name.Equals("")) { return; } // If we don't already have one then add this if (!perils.ContainsKey(name)) { perils.Add(name, d); } // If we do replace if this has higher priority else if (perils[name].priority < d.priority) { perils.Remove(name); perils.Add(name, d); } } }
// Add a section of an ini file to game content // name is from the ini file and must start with the type // path is relative and is used for images or other paths in the content void AddContent(string name, Dictionary <string, string> content, string path, string packID) { // Is this a "PackType" entry? if (name.IndexOf(PackTypeData.type) == 0) { PackTypeData d = new PackTypeData(name, content, path); // Ignore invalid entry if (d.name.Equals("")) { return; } // If we don't already have one then add this if (!packTypes.ContainsKey(name)) { packTypes.Add(name, d); d.sets.Add(packID); } // If we do replace if this has higher priority else if (packTypes[name].priority < d.priority) { packTypes.Remove(name); packTypes.Add(name, d); } // items of the same priority belong to multiple packs else if (packTypes[name].priority == d.priority) { packTypes[name].sets.Add(packID); } } // Is this a "TileSide" entry? if (name.IndexOf(TileSideData.type) == 0) { TileSideData d = new TileSideData(name, content, path); // Ignore invalid entry if (d.name.Equals("")) { return; } // If we don't already have one then add this if (!tileSides.ContainsKey(name)) { tileSides.Add(name, d); d.sets.Add(packID); } // If we do replace if this has higher priority else if (tileSides[name].priority < d.priority) { tileSides.Remove(name); tileSides.Add(name, d); } // items of the same priority belong to multiple packs else if (tileSides[name].priority == d.priority) { tileSides[name].sets.Add(packID); } } // Is this a "Hero" entry? if (name.IndexOf(HeroData.type) == 0) { HeroData d = new HeroData(name, content, path); // Ignore invalid entry if (d.name.Equals("")) { return; } // If we don't already have one then add this if (!heroes.ContainsKey(name)) { heroes.Add(name, d); d.sets.Add(packID); } // If we do replace if this has higher priority else if (heroes[name].priority < d.priority) { heroes.Remove(name); heroes.Add(name, d); } // items of the same priority belong to multiple packs else if (heroes[name].priority == d.priority) { heroes[name].sets.Add(packID); } } // Is this a "Class" entry? if (name.IndexOf(ClassData.type) == 0) { ClassData d = new ClassData(name, content, path); // Ignore invalid entry if (d.name.Equals("")) { return; } // If we don't already have one then add this if (!classes.ContainsKey(name)) { classes.Add(name, d); d.sets.Add(packID); } // If we do replace if this has higher priority else if (classes[name].priority < d.priority) { classes.Remove(name); classes.Add(name, d); } // items of the same priority belong to multiple packs else if (classes[name].priority == d.priority) { classes[name].sets.Add(packID); } } // Is this a "Skill" entry? if (name.IndexOf(SkillData.type) == 0) { SkillData d = new SkillData(name, content, path); // Ignore invalid entry if (d.name.Equals("")) { return; } // If we don't already have one then add this if (!skills.ContainsKey(name)) { skills.Add(name, d); d.sets.Add(packID); } // If we do replace if this has higher priority else if (skills[name].priority < d.priority) { skills.Remove(name); skills.Add(name, d); } // items of the same priority belong to multiple packs else if (skills[name].priority == d.priority) { skills[name].sets.Add(packID); } } // Is this a "Item" entry? if (name.IndexOf(ItemData.type) == 0) { ItemData d = new ItemData(name, content, path); // Ignore invalid entry if (d.name.Equals("")) { return; } // If we don't already have one then add this if (!items.ContainsKey(name)) { items.Add(name, d); d.sets.Add(packID); } // If we do replace if this has higher priority else if (items[name].priority < d.priority) { items.Remove(name); items.Add(name, d); } // items of the same priority belong to multiple packs else if (items[name].priority == d.priority) { items[name].sets.Add(packID); } } // Is this a "Monster" entry? if (name.IndexOf(MonsterData.type) == 0) { MonsterData d = new MonsterData(name, content, path); // Ignore invalid entry if (d.name.Equals("")) { return; } // Ignore monster activations if (name.IndexOf(ActivationData.type) != 0) { // If we don't already have one then add this if (!monsters.ContainsKey(name)) { monsters.Add(name, d); d.sets.Add(packID); } // If we do replace if this has higher priority else if (monsters[name].priority < d.priority) { monsters.Remove(name); monsters.Add(name, d); } // items of the same priority belong to multiple packs else if (monsters[name].priority == d.priority) { monsters[name].sets.Add(packID); } } } // Is this a "Activation" entry? if (name.IndexOf(ActivationData.type) == 0) { ActivationData d = new ActivationData(name, content, path); // Ignore invalid entry if (d.name.Equals("")) { return; } // If we don't already have one then add this if (!activations.ContainsKey(name)) { activations.Add(name, d); d.sets.Add(packID); } // If we do replace if this has higher priority else if (activations[name].priority < d.priority) { activations.Remove(name); activations.Add(name, d); } // items of the same priority belong to multiple packs else if (activations[name].priority == d.priority) { activations[name].sets.Add(packID); } } // Is this a "Attack" entry? if (name.IndexOf(AttackData.type) == 0) { AttackData d = new AttackData(name, content, path); // Ignore invalid entry if (d.name.Equals("")) { return; } // If we don't already have one then add this if (!investigatorAttacks.ContainsKey(name)) { investigatorAttacks.Add(name, d); d.sets.Add(packID); } // If we do replace if this has higher priority else if (investigatorAttacks[name].priority < d.priority) { investigatorAttacks.Remove(name); investigatorAttacks.Add(name, d); } // items of the same priority belong to multiple packs else if (investigatorAttacks[name].priority == d.priority) { investigatorAttacks[name].sets.Add(packID); } } // Is this a "Evade" entry? if (name.IndexOf(EvadeData.type) == 0) { EvadeData d = new EvadeData(name, content, path); // Ignore invalid entry if (d.name.Equals("")) { return; } // If we don't already have one then add this if (!investigatorEvades.ContainsKey(name)) { investigatorEvades.Add(name, d); d.sets.Add(packID); } // If we do replace if this has higher priority else if (investigatorEvades[name].priority < d.priority) { investigatorEvades.Remove(name); investigatorEvades.Add(name, d); } // items of the same priority belong to multiple packs else if (investigatorEvades[name].priority == d.priority) { investigatorEvades[name].sets.Add(packID); } } // Is this a "Horror" entry? if (name.IndexOf(HorrorData.type) == 0) { HorrorData d = new HorrorData(name, content, path); // Ignore invalid entry if (d.name.Equals("")) { return; } // If we don't already have one then add this if (!horrorChecks.ContainsKey(name)) { horrorChecks.Add(name, d); d.sets.Add(packID); } // If we do replace if this has higher priority else if (horrorChecks[name].priority < d.priority) { horrorChecks.Remove(name); horrorChecks.Add(name, d); } // items of the same priority belong to multiple packs else if (horrorChecks[name].priority == d.priority) { horrorChecks[name].sets.Add(packID); } } // Is this a "Token" entry? if (name.IndexOf(TokenData.type) == 0) { TokenData d = new TokenData(name, content, path); // Ignore invalid entry if (d.name.Equals("")) { return; } // If we don't already have one then add this if (!tokens.ContainsKey(name)) { tokens.Add(name, d); d.sets.Add(packID); } // If we do replace if this has higher priority else if (tokens[name].priority < d.priority) { tokens.Remove(name); tokens.Add(name, d); } // items of the same priority belong to multiple packs else if (tokens[name].priority == d.priority) { tokens[name].sets.Add(packID); } } // Is this a "Peril" entry? if (name.IndexOf(PerilData.type) == 0) { PerilData d = new PerilData(name, content); // Ignore invalid entry if (d.sectionName.Equals("")) { return; } // If we don't already have one then add this if (!perils.ContainsKey(name)) { perils.Add(name, d); } // If we do replace if this has higher priority else if (perils[name].priority < d.priority) { perils.Remove(name); perils.Add(name, d); } } // Is this a "Puzzle" entry? if (name.IndexOf(PuzzleData.type) == 0) { PuzzleData d = new PuzzleData(name, content, path); // Ignore invalid entry if (d.name.Equals("")) { return; } // If we don't already have one then add this if (!puzzles.ContainsKey(name)) { puzzles.Add(name, d); d.sets.Add(packID); } // If we do replace if this has higher priority else if (puzzles[name].priority < d.priority) { puzzles.Remove(name); puzzles.Add(name, d); } // items of the same priority belong to multiple packs else if (puzzles[name].priority == d.priority) { puzzles[name].sets.Add(packID); } } // Is this a "Image" entry? if (name.IndexOf(ImageData.type) == 0) { ImageData d = new ImageData(name, content, path); // Ignore invalid entry if (d.name.Equals("")) { return; } // If we don't already have one then add this if (!images.ContainsKey(name)) { images.Add(name, d); d.sets.Add(packID); } // If we do replace if this has higher priority else if (images[name].priority < d.priority) { images.Remove(name); images.Add(name, d); } // items of the same priority belong to multiple packs else if (images[name].priority == d.priority) { images[name].sets.Add(packID); } } // Is this a "Audio" entry? if (name.IndexOf(AudioData.type) == 0) { AudioData d = new AudioData(name, content, path); // Ignore invalid entry if (d.name.Equals("")) { return; } // If we don't already have one then add this if (!audio.ContainsKey(name)) { audio.Add(name, d); } // If we do replace if this has higher priority else if (audio[name].priority < d.priority) { audio.Remove(name); audio.Add(name, d); } } }
// Construct with data from the quest, pass Game for speed public Tile(QuestData.Tile questTile, Game gameObject) : base(gameObject) { qTile = questTile; // Search for tile in content if (game.cd.tileSides.ContainsKey(qTile.tileSideName)) { cTile = game.cd.tileSides[qTile.tileSideName]; } else if (game.cd.tileSides.ContainsKey("TileSide" + qTile.tileSideName)) { cTile = game.cd.tileSides["TileSide" + qTile.tileSideName]; } else { // Fatal if not found Debug.Log("Error: Failed to located TileSide: " + qTile.tileSideName + " in quest component: " + qTile.name); Application.Quit(); } // Attempt to load image Texture2D newTex = ContentData.FileToTexture(game.cd.tileSides[qTile.tileSideName].image); if (newTex == null) { // Fatal if missing Debug.Log("Error: cannot open image file for TileSide: " + game.cd.tileSides[qTile.tileSideName].image); Application.Quit(); } // Create a unity object for the tile unityObject = new GameObject("Object" + qTile.name); unityObject.tag = "board"; unityObject.transform.parent = game.boardCanvas.transform; // Add image to object image = unityObject.AddComponent <UnityEngine.UI.Image>(); // Create sprite from texture Sprite tileSprite = Sprite.Create(newTex, new Rect(0, 0, newTex.width, newTex.height), Vector2.zero, 1); // Set image sprite image.sprite = tileSprite; // Move to get the top left square corner at 0,0 float vPPS = game.cd.tileSides[qTile.tileSideName].pxPerSquare; float hPPS = vPPS; // manual aspect control // We need this for the 3x2 MoM tiles because they don't have square pixels!! if (game.cd.tileSides[qTile.tileSideName].aspect != 0) { hPPS = (vPPS * newTex.width / newTex.height) / game.cd.tileSides[qTile.tileSideName].aspect; } // Perform alignment move unityObject.transform.Translate(Vector3.right * ((newTex.width / 2) - cTile.left) / hPPS, Space.World); unityObject.transform.Translate(Vector3.down * ((newTex.height / 2) - cTile.top) / vPPS, Space.World); // Move to get the middle of the top left square at 0,0 // We don't do this for MoM because it spaces differently if (game.gameType.TileOnGrid()) { unityObject.transform.Translate(new Vector3(-(float)0.5, (float)0.5, 0), Space.World); } // Set the size to the image size image.rectTransform.sizeDelta = new Vector2((float)newTex.width / hPPS, (float)newTex.height / vPPS); // Rotate around 0,0 rotation amount unityObject.transform.RotateAround(Vector3.zero, Vector3.forward, qTile.rotation); // Move tile into target location (Space.World is needed because tile has been rotated) unityObject.transform.Translate(new Vector3(qTile.location.x, qTile.location.y, 0), Space.World); image.color = new Color(1, 1, 1, 0); }
// Add a section of an ini file to game content // name is from the ini file and must start with the type // path is relative and is used for images or other paths in the content void AddContent(string name, Dictionary <string, string> content, string path) { // Is this a "TileSide" entry? if (name.IndexOf(TileSideData.type) == 0) { TileSideData d = new TileSideData(name, content, path); // Ignore invalid entry if (d.name.Equals("")) { return; } // If we don't already have one then add this if (!tileSides.ContainsKey(d.name)) { tileSides.Add(name, d); } // If we do replace if this has higher priority else if (tileSides[d.name].priority < d.priority) { tileSides.Remove(name); tileSides.Add(name, d); } } // Is this a "Hero" entry? if (name.IndexOf(HeroData.type) == 0) { HeroData d = new HeroData(name, content, path); // Ignore invalid entry if (d.name.Equals("")) { return; } // If we don't already have one then add this if (!heros.ContainsKey(d.name)) { heros.Add(name, d); } // If we do replace if this has higher priority else if (heros[d.name].priority < d.priority) { heros.Remove(name); heros.Add(name, d); } } // Is this a "Monster" entry? if (name.IndexOf(MonsterData.type) == 0) { MonsterData d = new MonsterData(name, content, path); // Ignore invalid entry if (d.name.Equals("")) { return; } // Ignore monster activations if (name.IndexOf(ActivationData.type) != 0) { // If we don't already have one then add this if (!monsters.ContainsKey(d.name)) { monsters.Add(name, d); } // If we do replace if this has higher priority else if (monsters[d.name].priority < d.priority) { monsters.Remove(name); monsters.Add(name, d); } } } // Is this a "Activation" entry? if (name.IndexOf(ActivationData.type) == 0) { ActivationData d = new ActivationData(name, content, path); // Ignore invalid entry if (d.name.Equals("")) { return; } // If we don't already have one then add this if (!activations.ContainsKey(d.name)) { activations.Add(name, d); } // If we do replace if this has higher priority else if (activations[d.name].priority < d.priority) { activations.Remove(name); activations.Add(name, d); } } }