public bool TryGetValue(UnitDefinition unit, out CreatureSpriteCollection collection)
        {
            CreatureSpriteCollection.Special special = CreatureSpriteCollection.Special.Normal;
            UnitFlags3 flags3 = (UnitFlags3)unit.flags3;

            if ((flags3 & UnitFlags3.ghostly) == UnitFlags3.ghostly)
            {
                special = CreatureSpriteCollection.Special.Ghost;
            }
            else if (unit.inventory.FindIndex(x => x.mode == InventoryMode.Weapon) >= 0)
            {
                special = CreatureSpriteCollection.Special.Military;
            }
            CasteDictionary dict;

            if (TryGetValue(special, out dict) && dict.TryGetValue(unit, out collection))
            {
                return(true);
            }
            else if (TryGetValue(CreatureSpriteCollection.Special.Normal, out dict) && dict.TryGetValue(unit, out collection))
            {
                return(true);
            }
            collection = default(CreatureSpriteCollection);
            return(false);
        }
        public bool TryGetValue(UnitDefinition unit, out CreatureSpriteCollection collection)
        {
            SpecialDictionary dict;

            if (TryGetValue((profession)unit.profession_id, out dict) && dict.TryGetValue(unit, out collection))
            {
                return(true);
            }
            else if (TryGetValue(profession.NONE, out dict) && dict.TryGetValue(unit, out collection))
            {
                return(true);
            }
            collection = default(CreatureSpriteCollection);
            return(false);
        }
        public bool TryGetValue(UnitDefinition unit, out CreatureSpriteCollection collection)
        {
            ProfessionDictionary dict;

            if (TryGetValue(unit.race.mat_type, out dict) && dict.TryGetValue(unit, out collection))
            {
                return(true);
            }
            else if (TryGetValue(-1, out dict) && dict.TryGetValue(unit, out collection))
            {
                return(true);
            }
            collection = default(CreatureSpriteCollection);
            return(false);
        }
Ejemplo n.º 4
0
    private static void ConvertCreatureXML(XElement doc)
    {
        foreach (var creature in doc.Elements())
        {
            string race         = creature.Attribute("gameID").Value;
            var    creatureFile = creature.Attribute("file");
            foreach (var variant in creature.Elements("variant"))
            {
                CreatureSpriteCollection spriteCollection = ScriptableObject.CreateInstance <CreatureSpriteCollection>();

                spriteCollection.race = race;
                var special = variant.Attribute("special");
                if (special == null)
                {
                    spriteCollection.special = CreatureSpriteCollection.Special.Normal;
                }
                else
                {
                    spriteCollection.special = (CreatureSpriteCollection.Special)Enum.Parse(typeof(CreatureSpriteCollection.Special), special.Value);
                }

                var sex = variant.Attribute("sex");
                if (sex != null)
                {
                    switch (sex.Value)
                    {
                    case "M":
                        spriteCollection.caste = "MALE";
                        break;

                    case "F":
                        spriteCollection.caste = "FEMALE";
                        break;

                    default:
                        spriteCollection.caste = sex.Value;
                        break;
                    }
                }

                var prof = variant.Attribute("prof");
                if (prof != null)
                {
                    spriteCollection.profession = (profession)Enum.Parse((typeof(profession)), prof.Value);
                }

                var variantFile = variant.Attribute("file");

                spriteCollection.spriteLayers = new List <CreatureSpriteLayer>();

                foreach (var subsprite in variant.Elements("subsprite"))
                {
                    var sheetIndex = subsprite.Attribute("sheetIndex");
                    if (sheetIndex == null)
                    {
                        continue;
                    }
                    int index = int.Parse(sheetIndex.Value);

                    string spriteName;

                    var layerFile = subsprite.Attribute("file");
                    if (layerFile != null)
                    {
                        spriteName = Path.GetFileNameWithoutExtension(layerFile.Value) + "-" + index;
                    }
                    else if (variantFile != null)
                    {
                        spriteName = Path.GetFileNameWithoutExtension(variantFile.Value) + "-" + index;
                    }
                    else if (creatureFile != null)
                    {
                        spriteName = Path.GetFileNameWithoutExtension(creatureFile.Value) + "-" + index;
                    }
                    else
                    {
                        Debug.LogError("Could not find matching file");
                        continue;
                    }

                    var matchingSprites = AssetDatabase.FindAssets(spriteName + " t:Sprite");
                    if (matchingSprites == null || matchingSprites.Length == 0)
                    {
                        Debug.LogWarning("Could not find any sprite named " + spriteName);
                        continue;
                    }

                    CreatureSpriteLayer layer = new CreatureSpriteLayer();

                    layer.spriteTexture = AssetDatabase.LoadAssetAtPath <Sprite>(AssetDatabase.GUIDToAssetPath(matchingSprites[0]));
                    layer.preview       = true;

                    Color32 color = new Color32(128, 128, 128, 128);

                    foreach (var attribute in subsprite.Attributes())
                    {
                        switch (attribute.Name.LocalName)
                        {
                        case "sheetIndex":
                        case "file":
                            break;     //already taken care of

                        case "zoom":
                        case "equipment_class":
                            break;     //not used

                        case "color":
                            switch (attribute.Value)
                            {
                            case "bodypart":
                                layer.spriteSource = CreatureSpriteLayer.SpriteSource.Bodypart;
                                layer.colorSource  = CreatureSpriteLayer.ColorSource.Material;
                                break;

                            case "equipment":
                                layer.spriteSource = CreatureSpriteLayer.SpriteSource.Equipment;
                                layer.colorSource  = CreatureSpriteLayer.ColorSource.Material;
                                break;

                            case "xml":
                                layer.spriteSource = CreatureSpriteLayer.SpriteSource.Static;
                                layer.colorSource  = CreatureSpriteLayer.ColorSource.Fixed;
                                break;

                            default:
                                Debug.LogError("Unknown creature sprite layer color attribute: " + attribute);
                                break;
                            }
                            break;

                        case "bodypart":
                        case "equipment_name":
                            layer.token = attribute.Value;
                            break;

                        case "red":
                            color.r = byte.Parse(attribute.Value);
                            break;

                        case "green":
                            color.g = byte.Parse(attribute.Value);
                            break;

                        case "blue":
                            color.b = byte.Parse(attribute.Value);
                            break;

                        case "alpha":
                            color.a = (byte)(byte.Parse(attribute.Value) / 2);
                            break;

                        case "pattern_index":
                            layer.patternIndex = int.Parse(attribute.Value);
                            break;

                        case "hair_min":
                            layer.hairMin = int.Parse(attribute.Value);
                            break;

                        case "hair_max":
                            layer.hairMax = int.Parse(attribute.Value);
                            break;

                        case "hair_type":
                            switch (attribute.Value)
                            {
                            case "hair":
                                layer.hairType = CreatureSpriteLayer.HairType.Hair;
                                break;

                            case "sideburns":
                                layer.hairType = CreatureSpriteLayer.HairType.Sideburns;
                                break;

                            case "beard":
                                layer.hairType = CreatureSpriteLayer.HairType.Beard;
                                break;

                            case "moustache":
                                layer.hairType = CreatureSpriteLayer.HairType.Moustache;
                                break;

                            default:
                                layer.hairType = CreatureSpriteLayer.HairType.None;
                                break;
                            }
                            break;

                        case "hair_style":
                            switch (attribute.Value)
                            {
                            case "unkempt":
                                layer.hairStyle = RemoteFortressReader.HairStyle.UNKEMPT;
                                break;

                            case "combed":
                                layer.hairStyle = RemoteFortressReader.HairStyle.NEATLY_COMBED;
                                break;

                            case "braid":
                                layer.hairStyle = RemoteFortressReader.HairStyle.BRAIDED;
                                break;

                            case "two_braid":
                                layer.hairStyle = RemoteFortressReader.HairStyle.DOUBLE_BRAID;
                                break;

                            case "ponytails":
                                layer.hairStyle = RemoteFortressReader.HairStyle.PONY_TAILS;
                                break;

                            default:
                                break;
                            }
                            break;

                        case "material":
                            switch (attribute.Value)
                            {
                            case "Metal":
                                layer.metal = true;
                                break;

                            default:
                                break;
                            }
                            break;

                        case "offsety":
                            layer.positionOffset.y = float.Parse(attribute.Value) / -16.0f;
                            break;

                        case "offsetx":
                            layer.positionOffset.x = float.Parse(attribute.Value) / -16.0f;
                            break;

                        default:
                            Debug.LogError("Unknown creature sprite layer attribute: " + attribute);
                            break;
                        }
                    }

                    layer.color = color;

                    spriteCollection.spriteLayers.Add(layer);
                }

                Directory.CreateDirectory("Assets/Resources/Creatures/" + spriteCollection.race + "/");
                AssetDatabase.CreateAsset(spriteCollection, "Assets/Resources/Creatures/" + spriteCollection.race + "/" + spriteCollection.caste + "-" + spriteCollection.special + "-" + spriteCollection.profession + ".asset");
            }
        }
        AssetDatabase.Refresh();
    }