|
|
@@ -6,12 +6,14 @@ using System.Reflection; |
|
|
|
using System.Threading.Tasks; |
|
|
|
using IllusionPlugin; |
|
|
|
using Newtonsoft.Json; |
|
|
|
using Svelto.Tasks; |
|
|
|
using Svelto.Tasks.ExtraLean; |
|
|
|
using TechbloxModdingAPI; |
|
|
|
using TechbloxModdingAPI.App; |
|
|
|
using TechbloxModdingAPI.Blocks; |
|
|
|
using TechbloxModdingAPI.Commands; |
|
|
|
using TechbloxModdingAPI.Tasks; |
|
|
|
using TechbloxModdingAPI.Utility; |
|
|
|
using Unity.Mathematics; |
|
|
|
using UnityEngine; |
|
|
|
using uREPL; |
|
|
@@ -23,9 +25,10 @@ namespace GCMC |
|
|
|
public override string Name { get; } = Assembly.GetExecutingAssembly().GetName().Name; |
|
|
|
public override string Version { get; } = Assembly.GetExecutingAssembly().GetName().Version.ToString(); |
|
|
|
|
|
|
|
private readonly Dictionary<string, BlockType> mapping = new Dictionary<string, BlockType>(10); |
|
|
|
private JsonSerializer _serializer = JsonSerializer.Create(); |
|
|
|
private JsonTraceWriter _traceWriter = new JsonTraceWriter(); |
|
|
|
private readonly Dictionary<string, BlockType> _mapping = new Dictionary<string, BlockType>(10); |
|
|
|
private readonly List<(Block, SimBody, float3)> _simulationBlocks = new List<(Block, SimBody, float3)>(); |
|
|
|
private readonly JsonSerializer _serializer = JsonSerializer.Create(); |
|
|
|
private readonly JsonTraceWriter _traceWriter = new JsonTraceWriter(); |
|
|
|
|
|
|
|
private async void ImportWorld(string name) |
|
|
|
{ |
|
|
@@ -34,7 +37,7 @@ namespace GCMC |
|
|
|
Log.Output("Reading block mappings..."); |
|
|
|
var parser = new IniParser.FileIniDataParser(); |
|
|
|
var ini = parser.ReadFile("BlockTypes.ini"); |
|
|
|
mapping.Clear(); |
|
|
|
_mapping.Clear(); |
|
|
|
foreach (var section in ini.Sections) |
|
|
|
{ |
|
|
|
var mcblocks = section.SectionName.Split(','); |
|
|
@@ -76,7 +79,7 @@ namespace GCMC |
|
|
|
|
|
|
|
foreach (var mcblock in mcblocks) |
|
|
|
{ |
|
|
|
mapping.Add(mcblock.ToUpper(), new BlockType |
|
|
|
_mapping.Add(mcblock.ToUpper(), new BlockType |
|
|
|
{ |
|
|
|
Material = mcblock.ToUpper(), |
|
|
|
Type = type, |
|
|
@@ -98,7 +101,7 @@ namespace GCMC |
|
|
|
for (i = 0; i < blocksArray.Length; i++) |
|
|
|
{ |
|
|
|
var blocks = blocksArray[i]; |
|
|
|
if (!mapping.TryGetValue(blocks.Material, out var type)) |
|
|
|
if (!_mapping.TryGetValue(blocks.Material, out var type)) |
|
|
|
{ |
|
|
|
Console.WriteLine("Unknown block: " + blocks.Material); |
|
|
|
continue; |
|
|
@@ -109,9 +112,12 @@ namespace GCMC |
|
|
|
var block = new Block(type.Type, (blocks.Start + blocks.End) / 10 * 3 + new float3(5000, 0, 5000)) |
|
|
|
{ |
|
|
|
Color = type.Color, |
|
|
|
Scale = (blocks.End - blocks.Start + 1) * 3 |
|
|
|
Scale = (blocks.End - blocks.Start + 1) * 3, |
|
|
|
//Static = true - Doesn't seem to work |
|
|
|
}; |
|
|
|
_simulationBlocks.Add((block, null, default)); |
|
|
|
} |
|
|
|
Game.Simulate += GameOnSimulate; |
|
|
|
|
|
|
|
Log.Output(i + " blocks placed."); |
|
|
|
} |
|
|
@@ -122,6 +128,38 @@ namespace GCMC |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private void GameOnSimulate(object sender, GameEventArgs e) |
|
|
|
{ |
|
|
|
Game.Simulate -= GameOnSimulate; |
|
|
|
GameWhileSimulating().RunOn(Scheduler.extraLeanRunner); |
|
|
|
} |
|
|
|
|
|
|
|
private IEnumerator GameWhileSimulating() |
|
|
|
{ |
|
|
|
while (!GameState.IsSimulationMode()) |
|
|
|
yield return Yield.It; |
|
|
|
|
|
|
|
for (var i = 0; i < _simulationBlocks.Count; i++) |
|
|
|
{ |
|
|
|
var (block, body, _) = _simulationBlocks[i]; |
|
|
|
if (body is null) body = block.GetSimBody(); |
|
|
|
_simulationBlocks[i] = (block, body, body.Position); |
|
|
|
} |
|
|
|
|
|
|
|
while (GameState.IsSimulationMode()) |
|
|
|
{ |
|
|
|
foreach (var (_, body, pos) in _simulationBlocks) |
|
|
|
{ |
|
|
|
body.Velocity = 0; |
|
|
|
body.AngularVelocity = 0; |
|
|
|
body.Position = pos; |
|
|
|
body.Rotation = float3.zero; |
|
|
|
} |
|
|
|
|
|
|
|
yield return Yield.It; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public override void OnApplicationStart() |
|
|
|
{ |
|
|
|
TechbloxModdingAPI.Main.Init(); |
|
|
|