Read the mappings from the file

The file needs to be in the game dir
This commit is contained in:
Norbi Peti 2020-05-26 02:51:14 +02:00
parent 3e3fd0c767
commit 37d31e9ae3
3 changed files with 63 additions and 73 deletions

View file

@ -21,7 +21,7 @@ ignore=true
type=WoodCube type=WoodCube
[Water] [Water]
type=AluminiumCube type=GlassCube
color=Blue color=Blue
[Sand] [Sand]

View file

@ -1,21 +1,13 @@
using System; using System;
using System.Collections.Generic;
using System.IO; using System.IO;
using DataLoader;
using GamecraftModdingAPI; using GamecraftModdingAPI;
using GamecraftModdingAPI.Blocks; using GamecraftModdingAPI.Blocks;
using Newtonsoft.Json; 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.Input;
using RobocraftX.Common.Utilities; using RobocraftX.Common.Utilities;
using RobocraftX.CR.MachineEditing;
using RobocraftX.StateSync; using RobocraftX.StateSync;
using Svelto.ECS; using Svelto.ECS;
using Svelto.ECS.EntityStructs;
using Unity.Jobs; using Unity.Jobs;
using Unity.Mathematics; using Unity.Mathematics;
using uREPL; using uREPL;
@ -35,77 +27,69 @@ namespace GCMC
{ {
try try
{ {
Log.Output("Reading block mappings...");
var parser = new IniParser.FileIniDataParser();
var ini = parser.ReadFile("BlockTypes.ini");
var mapping = new Dictionary<string, BlockType>(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..."); Log.Output("Starting...");
var blocksArray = JsonSerializer.Create() var blocksArray = JsonSerializer.Create()
.Deserialize<Blocks[]>(new JsonTextReader(File.OpenText(name))); .Deserialize<Blocks[]>(new JsonTextReader(File.OpenText(name)));
int C = 0; int C = 0;
foreach (var blocks in blocksArray) foreach (var blocks in blocksArray)
{ {
BlockIDs id; if (!mapping.TryGetValue(blocks.Material, out var type))
BlockColors color;
byte darkness = 0;
switch (blocks.Material)
{ {
case "DIRT": Console.WriteLine("Unknown block: " + blocks.Material);
id = BlockIDs.DirtCube; continue;
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;
} }
Block.PlaceNew(id, (blocks.Start + blocks.End) / 10 * 3, color: color, darkness: darkness, Block.PlaceNew(type.Type, (blocks.Start + blocks.End) / 10 * 3, color: type.Color.Color,
scale: (blocks.End - blocks.Start + 1) * 3, rotation: float3.zero); darkness: type.Color.Darkness, scale: (blocks.End - blocks.Start + 1) * 3,
rotation: float3.zero);
C++; C++;
} }

View file

@ -21,7 +21,7 @@
<Reference Include="DataLoader, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"> <Reference Include="DataLoader, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
<HintPath>..\..\ref\Gamecraft_Data\Managed\DataLoader.dll</HintPath> <HintPath>..\..\ref\Gamecraft_Data\Managed\DataLoader.dll</HintPath>
</Reference> </Reference>
<Reference Include="GamecraftModdingAPI, Version=1.0.2.0, Culture=neutral, PublicKeyToken=null"> <Reference Include="GamecraftModdingAPI, Version=1.1.0.0, Culture=neutral, PublicKeyToken=null">
<HintPath>..\..\GamecraftModdingAPI\GamecraftModdingAPI\bin\Debug\net472\GamecraftModdingAPI.dll</HintPath> <HintPath>..\..\GamecraftModdingAPI\GamecraftModdingAPI\bin\Debug\net472\GamecraftModdingAPI.dll</HintPath>
</Reference> </Reference>
<Reference Include="IllusionPlugin, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"> <Reference Include="IllusionPlugin, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null">
@ -72,6 +72,12 @@
</Reference> </Reference>
</ItemGroup> </ItemGroup>
<ItemGroup>
<None Update="BlockTypes.ini">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
<Import Project="Sdk.targets" Sdk="Microsoft.NET.Sdk" /> <Import Project="Sdk.targets" Sdk="Microsoft.NET.Sdk" />
<Target Name="AfterBuild"> <Target Name="AfterBuild">
<!-- the ILMergePath property points to the location of ILMerge.exe console application --> <!-- the ILMergePath property points to the location of ILMerge.exe console application -->