From 37d31e9ae3e2f9d785c0b3d65fa31c9dfeffd5c5 Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Tue, 26 May 2020 02:51:14 +0200 Subject: [PATCH] Read the mappings from the file The file needs to be in the game dir --- GCMC/BlockTypes.ini | 2 +- GCMC/CubePlacerEngine.cs | 126 +++++++++++++++++---------------------- GCMC/GCMC.csproj | 8 ++- 3 files changed, 63 insertions(+), 73 deletions(-) diff --git a/GCMC/BlockTypes.ini b/GCMC/BlockTypes.ini index effc81f..42f672a 100644 --- a/GCMC/BlockTypes.ini +++ b/GCMC/BlockTypes.ini @@ -21,7 +21,7 @@ ignore=true type=WoodCube [Water] -type=AluminiumCube +type=GlassCube color=Blue [Sand] diff --git a/GCMC/CubePlacerEngine.cs b/GCMC/CubePlacerEngine.cs index 45e7c55..64e47bd 100644 --- a/GCMC/CubePlacerEngine.cs +++ b/GCMC/CubePlacerEngine.cs @@ -1,21 +1,13 @@ using System; +using System.Collections.Generic; using System.IO; -using DataLoader; using GamecraftModdingAPI; using GamecraftModdingAPI.Blocks; using Newtonsoft.Json; -using RobocraftX.Blocks; -using RobocraftX.Blocks.Ghost; -using RobocraftX.Blocks.Scaling; -using RobocraftX.Character; -using RobocraftX.CommandLine.Custom; -using RobocraftX.Common; using RobocraftX.Common.Input; using RobocraftX.Common.Utilities; -using RobocraftX.CR.MachineEditing; using RobocraftX.StateSync; using Svelto.ECS; -using Svelto.ECS.EntityStructs; using Unity.Jobs; using Unity.Mathematics; using uREPL; @@ -35,77 +27,69 @@ namespace GCMC { try { + Log.Output("Reading block mappings..."); + var parser = new IniParser.FileIniDataParser(); + var ini = parser.ReadFile("BlockTypes.ini"); + var mapping = new Dictionary(10); + foreach (var section in ini.Sections) + { + var mcblocks = section.SectionName.Split(','); + if (section.Keys["type"] == null) + { + if (section.Keys["ignore"] != "true") + Log.Warn("Block type not specified for " + section.SectionName); + continue; + } + if (!Enum.TryParse(section.Keys["type"], out BlockIDs type)) + { + Log.Warn("Block type specified in ini not found: " + section.Keys["type"]); + continue; + } + + BlockColors color; + if (section.Keys["color"] == null) + color = BlockColors.Default; + else if (!Enum.TryParse(section.Keys["color"], out color)) + { + Log.Warn("Block color specified in ini not found: " + section.Keys["color"]); + continue; + } + + byte darkness; + if (section.Keys["darkness"] == null) + darkness = 0; + else if (!byte.TryParse(section.Keys["darkness"], out darkness) || darkness > 9) + { + Log.Warn("Block darkness specified in ini isn't a number between 0 and 9: " + + section.Keys["darkness"]); + continue; + } + + foreach (var mcblock in mcblocks) + { + mapping.Add(mcblock.ToUpper(), new BlockType + { + Material = mcblock.ToUpper(), + Type = type, + Color = new BlockColor {Color = color, Darkness = darkness} + }); + } + } Log.Output("Starting..."); var blocksArray = JsonSerializer.Create() .Deserialize(new JsonTextReader(File.OpenText(name))); int C = 0; foreach (var blocks in blocksArray) { - BlockIDs id; - BlockColors color; - byte darkness = 0; - switch (blocks.Material) + if (!mapping.TryGetValue(blocks.Material, out var type)) { - case "DIRT": - id = BlockIDs.DirtCube; - color = BlockColors.Default; - break; - case "GRASS": - id = BlockIDs.GrassCube; - color = BlockColors.Default; - break; - case "STONE": - case "COAL_ORE": - case "IRON_ORE": - id = BlockIDs.ConcreteCube; - color = BlockColors.White; - darkness = 5; - break; - case "LEAVES": - id = BlockIDs.AluminiumCube; - color = BlockColors.Green; - darkness = 5; - break; - case "AIR": - case "DOUBLE_PLANT": - continue; - case "LOG": - id = BlockIDs.WoodCube; - color = BlockColors.Default; - break; - case "WATER": - id = BlockIDs.AluminiumCube; - color = BlockColors.Blue; - break; - case "SAND": - id = BlockIDs.AluminiumCube; - color = BlockColors.Yellow; - break; - case "LONG_GRASS": - id = BlockIDs.Flower1; - color = BlockColors.Default; - break; - case "YELLOW_FLOWER": - id = BlockIDs.Flower2; - color = BlockColors.Default; - break; - case "GRAVEL": - id = BlockIDs.ConcreteCube; - color = BlockColors.White; - darkness = 7; - break; - case "CLAY": - id = BlockIDs.ConcreteCube; - color = BlockColors.White; - darkness = 4; - break; - default: - Console.WriteLine("Unknown block: " + blocks.Material); - continue; + Console.WriteLine("Unknown block: " + blocks.Material); + continue; } - Block.PlaceNew(id, (blocks.Start + blocks.End) / 10 * 3, color: color, darkness: darkness, - scale: (blocks.End - blocks.Start + 1) * 3, rotation: float3.zero); + Block.PlaceNew(type.Type, (blocks.Start + blocks.End) / 10 * 3, color: type.Color.Color, + darkness: type.Color.Darkness, scale: (blocks.End - blocks.Start + 1) * 3, + rotation: float3.zero); C++; } diff --git a/GCMC/GCMC.csproj b/GCMC/GCMC.csproj index f9b1095..da26ccc 100644 --- a/GCMC/GCMC.csproj +++ b/GCMC/GCMC.csproj @@ -21,7 +21,7 @@ ..\..\ref\Gamecraft_Data\Managed\DataLoader.dll - + ..\..\GamecraftModdingAPI\GamecraftModdingAPI\bin\Debug\net472\GamecraftModdingAPI.dll @@ -72,6 +72,12 @@ + + + PreserveNewest + + +