Implemented importing, it works!

This commit is contained in:
Norbi Peti 2020-01-06 20:53:18 +01:00
parent b05197fa36
commit 562cea3d49
No known key found for this signature in database
GPG key ID: DBA4C4549A927E56
4 changed files with 79 additions and 0 deletions

11
GCMC/Blocks.cs Normal file
View file

@ -0,0 +1,11 @@
using Unity.Mathematics;
namespace GCMC
{
public struct Blocks
{
public float3 Start { get; set; }
public float3 End { get; set; }
public string Material { get; set; }
}
}

View file

@ -1,6 +1,8 @@
using System;
using System.IO;
using DataLoader;
using GamecraftModdingAPI.Blocks;
using Newtonsoft.Json;
using RobocraftX.Blocks;
using RobocraftX.Blocks.Ghost;
using RobocraftX.Blocks.Scaling;
@ -31,6 +33,60 @@ namespace GCMC
private void ImportWorld(string name)
{
try
{
Log.Output("Starting...");
var blocksArray = JsonSerializer.Create()
.Deserialize<Blocks[]>(new JsonTextReader(File.OpenText(name)));
int C = 0;
foreach (var blocks in blocksArray)
{
BlockIDs id;
BlockColors color;
byte darkness = 0;
switch (blocks.Material)
{
case "DIRT":
id = BlockIDs.DirtCube;
color = BlockColors.Default;
break;
case "GRASS":
id = BlockIDs.GrassCube;
color = BlockColors.Default;
break;
case "STONE":
id = BlockIDs.ConcreteCube;
color = BlockColors.White;
darkness = 5;
break;
case "LEAVES":
id = BlockIDs.AluminiumCube;
color = BlockColors.Green;
darkness = 5;
break;
case "AIR":
continue;
case "LOG":
id = BlockIDs.WoodCube;
color = BlockColors.Default;
break;
default:
Log.Output("Unknown block: " + blocks.Material);
continue;
}
Placement.PlaceBlock(id, (blocks.Start + blocks.End) / 2, color: color, darkness: darkness,
scale: (blocks.End - blocks.Start + 1) * 5, rotation: quaternion.identity);
C++;
}
Log.Output(C + " blocks placed.");
}
catch (Exception e)
{
Console.WriteLine(e);
Log.Error(e.Message);
}
}
private void PlaceBlock(string args)

View file

@ -27,6 +27,9 @@
<Reference Include="IllusionPlugin, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null">
<HintPath>IllusionPlugin.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=8.0.0.0, Culture=neutral, PublicKeyToken=null">
<HintPath>..\..\GamecraftModdingAPI\GamecraftModdingAPI\bin\Debug\net48\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="RobocraftX.Blocks, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
<HintPath>..\ref\RobocraftX.Blocks.dll</HintPath>
</Reference>

9
GCMC/Location.cs Normal file
View file

@ -0,0 +1,9 @@
namespace GCMC
{
public struct Location
{
public int X { get; set; }
public int Y { get; set; }
public int Z { get; set; }
}
}