From ab169fb87c33e87a74c558dceaf71a30c1f750fe Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Sun, 20 Sep 2020 23:23:33 +0200 Subject: [PATCH] (Re)load blueprints from file, t3 shields Blueprints can be loaded and reloaded from a file in the game's directory except in a release version --- Pixi/Common/BlueprintUtility.cs | 13 ++++++++++--- Pixi/PixiPlugin.cs | 4 +++- Pixi/Robots/RobotBlueprintProvider.cs | 7 +++++++ 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/Pixi/Common/BlueprintUtility.cs b/Pixi/Common/BlueprintUtility.cs index 382556d..a09af23 100644 --- a/Pixi/Common/BlueprintUtility.cs +++ b/Pixi/Common/BlueprintUtility.cs @@ -14,11 +14,18 @@ namespace Pixi.Common StreamReader bluemap = new StreamReader(File.OpenRead(name)); return JsonConvert.DeserializeObject>(bluemap.ReadToEnd()); } - + public static Dictionary ParseBlueprintResource(string name) { - StreamReader bluemap = new StreamReader(Assembly.GetExecutingAssembly().GetManifestResourceStream(name)); - return JsonConvert.DeserializeObject>(bluemap.ReadToEnd()); + StreamReader bluemap; +#if DEBUG + if (File.Exists(name)) + bluemap = File.OpenText(name); + else +#endif + bluemap = new StreamReader(Assembly.GetExecutingAssembly().GetManifestResourceStream(name)); + using (bluemap) + return JsonConvert.DeserializeObject>(bluemap.ReadToEnd()); } public static ProcessedVoxelObjectNotation[][] ProcessAndExpandBlocks(string name, BlockJsonInfo[] blocks, BlueprintProvider blueprints) diff --git a/Pixi/PixiPlugin.cs b/Pixi/PixiPlugin.cs index f93dfe5..133a007 100644 --- a/Pixi/PixiPlugin.cs +++ b/Pixi/PixiPlugin.cs @@ -47,12 +47,14 @@ namespace Pixi root.Inject(new ImageTextBlockImporter()); root.Inject(new ImageCommandImporter()); // Robot functionality - root.Inject(new RobotInternetImporter()); + var robot = new RobotInternetImporter(); + root.Inject(robot); //RobotCommands.CreateRobotCRFCommand(); //RobotCommands.CreateRobotFileCommand(); #if DEBUG // Development functionality RobotCommands.CreatePartDumpCommand(); + ((RobotBlueprintProvider) robot.BlueprintProvider).AddReloadCommand(); #endif } } diff --git a/Pixi/Robots/RobotBlueprintProvider.cs b/Pixi/Robots/RobotBlueprintProvider.cs index 3e617d3..8b8d6ff 100644 --- a/Pixi/Robots/RobotBlueprintProvider.cs +++ b/Pixi/Robots/RobotBlueprintProvider.cs @@ -6,6 +6,7 @@ using Unity.Mathematics; using UnityEngine; using GamecraftModdingAPI.Blocks; +using GamecraftModdingAPI.Commands; using GamecraftModdingAPI.Utility; using Pixi.Common; @@ -96,5 +97,11 @@ namespace Pixi.Robots } return adjustedBlueprint; } + + public void AddReloadCommand() + { + CommandBuilder.Builder("PixiReload", "Reloads the robot blueprints") + .Action(() => botprints = null).Build(); + } } } \ No newline at end of file