コード例 #1
0
        public void AssignDefaults(IReadOnlyList <string> construction)
        {
            Color              = LoadMethods.ParseColor32(construction[0]);
            Uncivilized        = LoadMethods.YesNoConverter(construction[1]);
            CanReduceMilitancy = LoadMethods.YesNoConverter(construction[2]);

            if (!DateTime.TryParse(construction[3], out var dateResult))
            {
                throw new Exception("Unknown date. " + construction[3]);
            }
            int.TryParse("9" + dateResult.ToString("yyyyMMdd"), out Date);
        }
コード例 #2
0
        public static (Entity, Entity, List <string>, List <string>) Main()
        {
            var goods             = new NativeList <EntityWrapper>(Allocator.Temp);
            var goodsCategory     = new NativeList <EntityWrapper>(Allocator.Temp);
            var goodNames         = new List <string>();
            var goodCategoryNames = new List <string>();

            var fileTree = new List <KeyValuePair <int, object> >();
            var values   = new List <string>();

            var em = World.Active.EntityManager;
            var currentCategory = new Entity();

            FileUnpacker.ParseFile(Path.Combine(Application.streamingAssetsPath, "Common", "goods.txt"), fileTree,
                                   values, GoodsMagicOverride);

            foreach (var category in fileTree)
            {
                foreach (var goodKvp in (List <KeyValuePair <int, object> >)category.Value)
                {
                    var currentEntity = goods[goodKvp.Key - (int)MagicUnifiedNumbers.Goods];
                    var currentGood   = em.GetComponentData <GoodsEntity>(currentEntity);

                    foreach (var goodProperty in (List <KeyValuePair <int, object> >)goodKvp.Value)
                    {
                        var targetStr = values[(int)goodProperty.Value];
                        switch ((LoadVariables)goodProperty.Key)
                        {
                        case LoadVariables.Cost:
                            float.TryParse(targetStr, out var cost);
                            currentGood.Cost = cost;
                            break;

                        case LoadVariables.Color:
                            currentGood.Color = LoadMethods.ParseColor32(targetStr);
                            break;

                        case LoadVariables.AvailableFromStart:
                            currentGood.Availability = LoadMethods.YesNoConverter(targetStr);
                            break;

                        case LoadVariables.OverseasPenalty:
                            currentGood.OverseasPenalty = LoadMethods.YesNoConverter(targetStr);
                            break;

                        case LoadVariables.Money:
                            currentGood.Money = LoadMethods.YesNoConverter(targetStr);
                            break;

                        case LoadVariables.Tradeable:
                            currentGood.Tradable = LoadMethods.YesNoConverter(targetStr);
                            break;
                        }
                    }

                    em.SetComponentData(currentEntity, currentGood);
                }
            }

            var goodCollectorEntity = FileUnpacker.GetCollector <GoodsCollection>(goods);

            goods.Dispose();

            var categoryCollectorEntity = FileUnpacker.GetCollector <GoodsCategoryCollection>(goodsCategory);

            goodsCategory.Dispose();

            return(goodCollectorEntity, categoryCollectorEntity, goodNames, goodCategoryNames);

            int GoodsMagicOverride(int parent, string target)
            {
                switch (parent)
                {
                case -1:
                    var targetCategory = em.CreateEntity(typeof(GoodsCategoryEntity));
                    em.SetComponentData(targetCategory, new GoodsCategoryEntity {
                        Index = goodCategoryNames.Count
                    });
                    goodsCategory.Add(targetCategory);
                    currentCategory = targetCategory;
                    goodCategoryNames.Add(target);
                    return((int)MagicUnifiedNumbers.Placeholder);

                case (int)MagicUnifiedNumbers.Placeholder:
                    var targetGood = em.CreateEntity(typeof(GoodsEntity));
                    em.SetComponentData(targetGood,
                                        new GoodsEntity {
                        Index = goodNames.Count, Category = currentCategory
                    });
                    goods.Add(targetGood);
                    goodNames.Add(target);
                    return((int)MagicUnifiedNumbers.Goods + goodNames.Count - 1);

                default:
                    return((int)MagicUnifiedNumbers.ContinueMagicNumbers);
                }
            }
        }
コード例 #3
0
ファイル: AreasLoad.cs プロジェクト: KornFlaks/TestUIT
        public void Generate(string areasPath, List <int> idIndices, DistinctColorList distinctColorList)
        {
            const string colorPattern =
                @"(?<areaName>(?<=\}|^)\w+?)\s*?\=\s*?\{\s*?color\s*?\=\s*?\{(?<color>.*?(?=\}))";
            const string blockPattern        = @"(?<areaName>(?<=^|\}).*?(?=\=)).*?(?<provIds>(?<=\{).*?(?=\}))";
            const string colorRemovalPattern = @"color.*?}";

            ProvinceToAreas = new int[idIndices.Count];
            Names           = new List <string>();
            AreaColors      = new List <Color32>();
            var customColors = new Dictionary <string, Color32>();

            var idLookup = new Dictionary <int, int>(idIndices.Count);

            for (var index = 0; index < idIndices.Count; index++)
            {
                idLookup[idIndices[index]] = index;
            }

            var areaFile = File.ReadAllText(areasPath);

            // Triplicate remover.
            LoadMethods.EntireAllInOneRemover(ref areaFile);

            // Finding colors needs to be first.
            var colors = Regex.Match(areaFile, colorPattern);

            while (colors.Success)
            {
                customColors[colors.Groups["areaName"].Value.Trim()] =
                    LoadMethods.ParseColor32(colors.Groups["color"].Value);

                colors = colors.NextMatch();
            }

            // Removing colors.
            areaFile = Regex.Replace(areaFile, colorRemovalPattern, "");

            // Adding Unknown as default area.
            Names.Add("unknown");
            AreaColors.Add(Color.white);

            // Get blocks.
            var blocks = Regex.Match(areaFile, blockPattern);

            while (blocks.Success)
            {
                var name = blocks.Groups["areaName"].Value.Trim();
                Names.Add(name);

                if (customColors.TryGetValue(name, out var predefinedColor))
                {
                    AreaColors.Add(predefinedColor);
                }
                else
                {
                    AreaColors.Add(distinctColorList.GetNextColor());
                }

                var provinces = blocks.Groups["provIds"].Value.Trim()
                                .Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

                foreach (var idString in provinces)
                {
                    if (!int.TryParse(idString, out var id))
                    {
                        throw new Exception(
                                  $"Invalid province id '{idString}' found in area '{Names.Last()}' parsing.");
                    }

                    if (idLookup.TryGetValue(id, out var index))
                    {
                        ProvinceToAreas[index] = Names.Count - 1;
                    }
                }

                blocks = blocks.NextMatch();
            }

            distinctColorList.ResetColorList();
        }
コード例 #4
0
 public void AssignDefaults(IReadOnlyList <string> construction)
 {
     Color        = LoadMethods.ParseColor32(construction[0]);
     MovementCost = float.Parse(construction[1]);
     //Index = (int) construction[2];
 }
コード例 #5
0
ファイル: PopTypesLoad.cs プロジェクト: KornFlaks/NTTC
        public static (Entity, List <string>) Main()
        {
            var popFiles = Directory.GetFiles(Path.Combine(Application.streamingAssetsPath, "PopTypes"), "*.txt");

            // Output arrays
            var popTypes = new NativeList <EntityWrapper>(Allocator.Temp);
            var popNames = new List <string>();

            popNames.AddRange(popFiles.Select(Path.GetFileNameWithoutExtension));

            var em = World.Active.EntityManager;

            using (var needsList = new NativeList <DataGood>(Allocator.Temp))
                using (var popRebels = new NativeList <DataValue>(Allocator.Temp))
                {
                    for (var index = 0; index < popTypes.Length; index++)
                    {
                        // Generating file tree
                        var fileTree = new List <KeyValuePair <int, object> >();
                        var values   = new List <string>();

                        FileUnpacker.ParseFile(popFiles[index], fileTree, values,
                                               (i, s) => (int)MagicUnifiedNumbers.ContinueMagicNumbers);

                        var currentEntity  = em.CreateEntity(typeof(PopTypeEntity));
                        var currentPopType = new PopTypeEntity {
                            Index = index
                        };

                        foreach (var topLevel in fileTree)
                        {
                            switch ((LoadVariables)topLevel.Key)
                            {
                            case LoadVariables.Sprite:
                                // Skipping sprite
                                break;

                            case LoadVariables.Color:
                                currentPopType.Color = LoadMethods.ParseColor32(values[(int)topLevel.Value]);
                                break;

                            case LoadVariables.Strata:
                                if (!Enum.TryParse(values[(int)topLevel.Value], true,
                                                   out PopTypeEntity.Standing strata))
                                {
                                    throw new Exception("Strata unknown: " + values[(int)topLevel.Value]);
                                }
                                currentPopType.Strata = strata;
                                break;

                            case LoadVariables.StateCapitalOnly:
                                currentPopType.StateCapitalOnly =
                                    LoadMethods.YesNoConverter(values[(int)topLevel.Value]);
                                break;

                            case LoadVariables.Rebel:
                                RebelParser(topLevel);
                                em.AddBuffer <DataValue>(currentEntity).AddRange(popRebels);
                                popRebels.Clear();
                                break;

                            case LoadVariables.CountryMigrationTarget:
                            case LoadVariables.MigrationTarget:
                            case LoadVariables.PromoteTo:
                            case LoadVariables.Ideologies:
                                var collapsedList = new List <float2>();
                                RestParser(topLevel, collapsedList);
                                break;

                            case LoadVariables.LifeNeeds:
                            case LoadVariables.EverydayNeeds:
                            case LoadVariables.LuxuryNeeds:
                                NeedsParser(topLevel);
                                break;
                            }
                        }

                        em.AddBuffer <DataGood>(currentEntity).AddRange(needsList);
                        em.SetComponentData(currentEntity, currentPopType);
                        popTypes.Add(currentEntity);
                        needsList.Clear();

                        // DEBUG
                        //break;

                        void RestParser(KeyValuePair <int, object> currentBranch, List <float2> targetList)
                        {
                        }

                        void NeedsParser(KeyValuePair <int, object> currentBranch)
                        {
                            // There should be no nested values within needs.
                            var startingNeeds = needsList.Length;

                            foreach (var goodsKvp in (List <KeyValuePair <int, object> >)currentBranch.Value)
                            {
                                if (!float.TryParse(values[(int)goodsKvp.Value], out var goodsNeeded))
                                {
                                    throw new Exception("Unknown goods needed: " + values[(int)goodsKvp.Value]);
                                }

                                needsList.Add(new DataGood(goodsKvp.Key - (int)MagicUnifiedNumbers.Goods, goodsNeeded));
                            }

                            switch ((LoadVariables)currentBranch.Key)
                            {
                            case LoadVariables.LifeNeeds:
                                currentPopType.lifeRange = new int2(startingNeeds, needsList.Length);
                                break;

                            case LoadVariables.EverydayNeeds:
                                currentPopType.everydayRange = new int2(startingNeeds, needsList.Length);
                                break;

                            case LoadVariables.LuxuryNeeds:
                                currentPopType.luxuryRange = new int2(startingNeeds, needsList.Length);
                                break;
                            }
                        }

                        void RebelParser(KeyValuePair <int, object> currentBranch)
                        {
                            foreach (var armyKvp in (List <KeyValuePair <int, object> >)currentBranch.Value)
                            {
                                if (!float.TryParse(values[(int)armyKvp.Value], out var armyRatio))
                                {
                                    throw new Exception("Unknown army ratio: " + values[(int)armyKvp.Value]);
                                }

                                if (armyRatio < 0.001)
                                {
                                    continue;
                                }

                                popRebels.Add(new DataValue(armyKvp.Key - (int)MagicUnifiedNumbers.Unit, armyRatio));
                            }
                        }
                    }
                }

            var popTypeCollectorEntity = FileUnpacker.GetCollector <PopTypeCollection>(popTypes);

            popTypes.Dispose();

            return(popTypeCollectorEntity, popNames);
        }
コード例 #6
0
        public static (List <string>, List <string>) Main(bool cache)
        {
            var cultures          = new List <CultureEntity>();
            var cultureNames      = new List <string>();
            var cultureGroupNames = new List <string>();

            if (cache)
            {
                (cultureNames, cultureGroupNames, cultures) = JsonUtility.FromJson <CulturesOutput>(
                    LoadMethods.Unzip(File.ReadAllBytes(Path.Combine(Application.streamingAssetsPath, "JsonData", "cultures.txt"))));

                LoadMethods.GenerateCacheEntities <CultureEntity, CultureCollection>(cultures, cultureNames, cultureGroupNames);

                return(cultureNames, cultureGroupNames);
            }

            var em = World.DefaultGameObjectInjectionWorld.EntityManager;

            bool groupToggle   = false,
                 cultureToggle = false,
                 ignoreToggle  = false;
            var currentCulture = new CultureEntity();

            foreach (var line in File.ReadLines(Path.Combine(Application.streamingAssetsPath, "common",
                                                             "cultures.txt")))
            {
                if (LoadMethods.CommentDetector(line, out var commentSplit))
                {
                    continue;
                }

                if (ignoreToggle)
                {
                    if (commentSplit.Contains("}"))
                    {
                        ignoreToggle = false;
                    }

                    // Assuming no values defined after end brackets
                    continue;
                }

                var equalsSplit = Regex.Match(commentSplit, @"^.+?(?=\=)");
                var preEquals   = equalsSplit.Success ? equalsSplit.Value.Trim() : "";

                if (commentSplit.Contains("{"))
                {
                    if (!groupToggle)
                    {
                        groupToggle = true;
                        cultureGroupNames.Add(preEquals);
                        continue;
                    }

                    if (!commentSplit.Contains("_names") && !commentSplit.Contains("color"))
                    {
                        cultureToggle = true;
                        var name = preEquals.Trim();
                        cultureNames.Add(name);
                        currentCulture = new CultureEntity {
                            Group = cultureGroupNames.Last(), Name = name
                        };
                    }
                }

                switch (preEquals)
                {
                case "union":
                    currentCulture.Union =
                        LookupDictionaries.CountryTags[commentSplit.Substring(equalsSplit.Length + 1).Trim()];
                    continue;

                case "first_names":
                case "last_names":
                    // TODO: Implement names generation, someday.
                    if (!commentSplit.Contains("}"))
                    {
                        ignoreToggle = true;
                    }
                    continue;

                case "color":
                    currentCulture.Color =
                        LoadMethods.ParseColor32(commentSplit.Substring(equalsSplit.Length + 1));
                    continue;

                case "leader":
                case "unit":
                    continue;

                case "radicalism":
                    if (!float.TryParse(commentSplit.Substring(equalsSplit.Length + 1), out var radical))
                    {
                        throw new Exception("Unknown radicalism: " +
                                            commentSplit.Substring(equalsSplit.Length + 1));
                    }

                    currentCulture.Radicalism = radical;
                    continue;

                case "primary":
                    currentCulture.Primary =
                        LookupDictionaries.CountryTags[commentSplit.Substring(equalsSplit.Length + 1).Trim()];
                    continue;
                }

                if (!commentSplit.Contains("}"))
                {
                    continue;
                }

                if (cultureToggle)
                {
                    cultureToggle = false;
                    var targetCulture = em.CreateEntity(typeof(CultureEntity));
                    em.SetComponentData(targetCulture, currentCulture);

                    cultures.Add(currentCulture);
                    continue;
                }

                groupToggle = false;
            }

            File.WriteAllBytes(Path.Combine(Application.streamingAssetsPath, "JsonData", "cultures.txt"),
                               LoadMethods.Zip(JsonUtility.ToJson(
                                                   new CulturesOutput(cultureNames, cultureGroupNames, cultures))));

            FileUnpacker.GetCollector <CultureCollection>();

            return(cultureNames, cultureGroupNames);
        }
コード例 #7
0
        public static (List <string>, List <string>) Main(bool cache)
        {
            var groupNames       = new List <string>();
            var religionNames    = new List <string>();
            var religionEntities = new List <ReligionEntity>();

            if (cache)
            {
                (religionNames, groupNames, religionEntities) = JsonUtility.FromJson <ReligionsOutput>(
                    LoadMethods.Unzip(File.ReadAllBytes(Path.Combine(Application.streamingAssetsPath, "JsonData", "religion.txt"))));

                LoadMethods.GenerateCacheEntities <ReligionEntity, ReligionCollection>(religionEntities, religionNames, groupNames);

                return(religionNames, groupNames);
            }

            var em = World.DefaultGameObjectInjectionWorld.EntityManager;

            bool groupToggle = false, religionToggle = false, colorToggle = false;
            var  currentReligion = new ReligionEntity();

            foreach (var line in File.ReadLines(Path.Combine(Application.streamingAssetsPath, "Common",
                                                             "religion.txt")))
            {
                if (LoadMethods.CommentDetector(line, out var commentSplit))
                {
                    continue;
                }

                var equalsSplit = commentSplit.Split(new[] { "=" }, StringSplitOptions.RemoveEmptyEntries);

                if (commentSplit.Contains("{"))
                {
                    if (!groupToggle)
                    {
                        groupToggle = true;

                        groupNames.Add(equalsSplit[0].Trim());
                        continue;
                    }

                    if (!religionToggle)
                    {
                        religionToggle  = true;
                        currentReligion = new ReligionEntity {
                            Group = groupNames.Last()
                        };
                        religionNames.Add(equalsSplit[0].Trim());
                        continue;
                    }

                    if (!colorToggle)
                    {
                        colorToggle = true;
                    }
                }

                switch (equalsSplit[0].Trim())
                {
                case "color":
                    // Why religion colors are in float, I have absolutely no idea.
                    currentReligion.Color = LoadMethods.ParseColor32(equalsSplit[1]);
                    break;
                }

                if (!commentSplit.Contains("}"))
                {
                    continue;
                }

                if (colorToggle)
                {
                    colorToggle = false;
                    continue;
                }

                if (religionToggle)
                {
                    religionToggle = false;

                    var targetEntity = em.CreateEntity(typeof(ReligionEntity));
                    em.SetComponentData(targetEntity, currentReligion);
                    religionEntities.Add(currentReligion);

                    continue;
                }

                groupToggle = false;
            }

            FileUnpacker.GetCollector <ReligionCollection>();

            File.WriteAllBytes(Path.Combine(Application.streamingAssetsPath, "JsonData", "religion.txt"),
                               LoadMethods.Zip(JsonUtility.ToJson(new ReligionsOutput(groupNames, religionNames, religionEntities))));

            /*
             * var test = em.GetBuffer<EntityWrapper>(religionCollectorEntity);
             * foreach (var religion in test.AsNativeArray())
             * {
             *  var religionEntity = em.GetComponentData<ReligionEntity>(religion.Entity);
             *  Debug.Log(religionNames[religionEntity.Index]
             + " of group " + groupNames[em.GetComponentData<ReligionGroupEntity>(religionEntity.Group).Index]);
             + }
             */

            return(religionNames, groupNames);
        }