From 9ff2445be647dff86394c68f32cf44dc125c78c2 Mon Sep 17 00:00:00 2001 From: neitsa Date: Mon, 26 Dec 2016 16:45:04 +0100 Subject: [PATCH 01/12] Create README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..f97c68b --- /dev/null +++ b/README.md @@ -0,0 +1,2 @@ +# RemoteTech-CommandHandler +Command handler for RemoteTech modules. From d5b6224364affb74f8c917f46c314a9f13c47533 Mon Sep 17 00:00:00 2001 From: Yamori Yuki Date: Wed, 28 Dec 2016 12:03:32 +0100 Subject: [PATCH 02/12] project setup --- .gitattributes | 25 ++ .gitignore | 279 ++++++++++++++++++ .../Properties/AssemblyInfo.cs | 36 +++ .../RemoteTech-CommandHandler.csproj | 68 +++++ 4 files changed, 408 insertions(+) create mode 100644 .gitattributes create mode 100644 .gitignore create mode 100644 src/RemoteTech-CommandHandler/Properties/AssemblyInfo.cs create mode 100644 src/RemoteTech-CommandHandler/RemoteTech-CommandHandler.csproj diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..8f3c49c --- /dev/null +++ b/.gitattributes @@ -0,0 +1,25 @@ +############################################################################### +# Set default behavior to automatically normalize line endings. +############################################################################### +* text=auto +*.cfg text eol=crlf +*.version text eol=crlf +*.txt text eol=crlf + +############################################################################### +# These files are text and should be normalized (convert crlf => lf) +############################################################################### +*.cs text=auto diff=csharp + +############################################################################### +# Images should be treated as binary +# (binary is a macro for -text -diff) +############################################################################### +*.png binary +*.jepg binary + +############################################################################### +# Visual Studio +############################################################################### +*.csproj text=auto merge=union +*.sln -text merge=union \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..bacc070 --- /dev/null +++ b/.gitignore @@ -0,0 +1,279 @@ +# RemoteTech specific + + +############################################################################### +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. +## +## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore +################################################################################ +# User-specific files +*.suo +*.user +*.userosscache +*.sln.docstates +*.vcxproj.filters + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +bld/ +[Bb]in/ +[Oo]bj/ +[Ll]og/ + +# Visual Studio 2015 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUNIT +*.VisualState.xml +TestResult.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# .NET Core +project.lock.json +project.fragment.lock.json +artifacts/ +**/Properties/launchSettings.json + +*_i.c +*_p.c +*_i.h +*.ilk +*.meta +*.obj +*.pch +*.pdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# JustCode is a .NET coding add-in +.JustCode + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# Visual Studio code coverage results +*.coverage +*.coveragexml + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# TODO: Comment the next line if you want to checkin your web deploy settings +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# The packages folder can be ignored because of Package Restore +**/packages/* +# except build/, which is used as an MSBuild target. +!**/packages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/packages/repositories.config +# NuGet v3's project.json files produces more ignoreable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.jfm +*.pfx +*.publishsettings +node_modules/ +orleans.codegen.cs + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm + +# SQL Server files +*.mdf +*.ldf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) +*.vbw + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# JetBrains Rider +.idea/ +*.sln.iml + +# CodeRush +.cr/ + +# Python Tools for Visual Studio (PTVS) +__pycache__/ +*.pyc + +# Cake - Uncomment if you are using it +# tools/ \ No newline at end of file diff --git a/src/RemoteTech-CommandHandler/Properties/AssemblyInfo.cs b/src/RemoteTech-CommandHandler/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..048ea8f --- /dev/null +++ b/src/RemoteTech-CommandHandler/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("RemoteTech-CommandHandler")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("RemoteTech-CommandHandler")] +[assembly: AssemblyCopyright("Copyright © 2016")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("0d0e27a8-16c4-4526-9df8-07c2f8fcb20a")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/src/RemoteTech-CommandHandler/RemoteTech-CommandHandler.csproj b/src/RemoteTech-CommandHandler/RemoteTech-CommandHandler.csproj new file mode 100644 index 0000000..31995af --- /dev/null +++ b/src/RemoteTech-CommandHandler/RemoteTech-CommandHandler.csproj @@ -0,0 +1,68 @@ + + + + + Debug + AnyCPU + {0D0E27A8-16C4-4526-9DF8-07C2F8FCB20A} + Library + Properties + RemoteTech.CommandHandler + RemoteTech-CommandHandler + v3.5 + 512 + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\..\..\KSP_Assemblies\Assembly-CSharp.dll + False + + + ..\..\..\KSP_Assemblies\Assembly-CSharp-firstpass.dll + False + + + + + ..\..\..\KSP_Assemblies\UnityEngine.dll + False + + + ..\..\..\KSP_Assemblies\UnityEngine.UI.dll + False + + + + + + + + + + + + + \ No newline at end of file From e91ad755c1ec74e60f0ca13ed74243c937e9fc42 Mon Sep 17 00:00:00 2001 From: Yamori Yuki Date: Thu, 29 Dec 2016 00:45:06 +0100 Subject: [PATCH 03/12] days end commit plenty of work left --- .../CommandManager.cs | 69 +++++++++++++++++++ .../CommandPlanner.cs | 15 ++++ src/RemoteTech-CommandHandler/DataScenario.cs | 37 ++++++++++ src/RemoteTech-CommandHandler/ICommand.cs | 6 ++ .../ICommandProvider.cs | 12 ++++ src/RemoteTech-CommandHandler/ICondition.cs | 11 +++ .../PlannedCommand.cs | 17 +++++ .../RemoteTech-CommandHandler.csproj | 4 +- 8 files changed, 170 insertions(+), 1 deletion(-) create mode 100644 src/RemoteTech-CommandHandler/CommandManager.cs create mode 100644 src/RemoteTech-CommandHandler/CommandPlanner.cs create mode 100644 src/RemoteTech-CommandHandler/DataScenario.cs create mode 100644 src/RemoteTech-CommandHandler/ICommand.cs create mode 100644 src/RemoteTech-CommandHandler/ICommandProvider.cs create mode 100644 src/RemoteTech-CommandHandler/ICondition.cs create mode 100644 src/RemoteTech-CommandHandler/PlannedCommand.cs diff --git a/src/RemoteTech-CommandHandler/CommandManager.cs b/src/RemoteTech-CommandHandler/CommandManager.cs new file mode 100644 index 0000000..95318b1 --- /dev/null +++ b/src/RemoteTech-CommandHandler/CommandManager.cs @@ -0,0 +1,69 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using UnityEngine; + +namespace RemoteTech.CommandHandler +{ + [KSPAddon(KSPAddon.Startup.MainMenu, true)] + public class CommandManager : MonoBehaviour + { + public const string configNodeName = "CommandManager"; + + private const int initialListSize = 50; + + private static CommandManager instance; + + public static CommandManager Instance + { + get + { + return instance; + } + } + + private List plannedCommands = new List(initialListSize); + private bool needToLoad = true; + + public void Awake() + { + GameEvents.onGameStateLoad.Add(new EventData.OnEvent(GameLoadEvent)); + } + + public void OnDestroy() + { + GameEvents.onGameStateLoad.Remove(new EventData.OnEvent(GameLoadEvent)); + } + + public bool RegisterCommandProvider(ICommandProvider provider) + { + return true; + } + + public bool AddCommand(ICommand command) + { + return true; + } + + public void LoadFromConfigNode(ConfigNode node) + { + if ( !needToLoad || !node.HasNode(PlannedCommand.configNodeName)) + { + return; + } + plannedCommands.Clear(); + var nodes = node.GetNodes(PlannedCommand.configNodeName); + for (var i=0; i < nodes.Length; i++) + { + plannedCommands.Add(new PlannedCommand(nodes[i])); + } + needToLoad = false; + } + + public void GameLoadEvent(ConfigNode node) + { + needToLoad = true; + } + } +} diff --git a/src/RemoteTech-CommandHandler/CommandPlanner.cs b/src/RemoteTech-CommandHandler/CommandPlanner.cs new file mode 100644 index 0000000..914248a --- /dev/null +++ b/src/RemoteTech-CommandHandler/CommandPlanner.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace RemoteTech.CommandHandler +{ + class CommandPlanner //: MonoBehaviour + { + public void LoadFromConfigNode(ConfigNode node) + { + + } + } +} diff --git a/src/RemoteTech-CommandHandler/DataScenario.cs b/src/RemoteTech-CommandHandler/DataScenario.cs new file mode 100644 index 0000000..f61e18b --- /dev/null +++ b/src/RemoteTech-CommandHandler/DataScenario.cs @@ -0,0 +1,37 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace RemoteTech.CommandHandler +{ + [KSPScenario(ScenarioCreationOptions.AddToAllGames, GameScenes.FLIGHT, GameScenes.SPACECENTER)] + class DataScenario : ScenarioModule + { + public override void OnLoad(ConfigNode node) + { + base.OnLoad(node); + if (node.HasNode(CommandManager.configNodeName)) + { + CommandManager.Instance.LoadFromConfigNode(node.GetNode(CommandManager.configNodeName)); + } + else + { + CommandManager.Instance.LoadFromConfigNode(new ConfigNode()); + } + //if (node.HasNode(CommandPlanner.configNodeName)) + //{ + // CommandPlanner.Instance.LoadFromConfigNode(node.GetNode(CommandPlanner.configNodeName)); + //} + //else + //{ + // CommandPlanner.Instance.LoadFromConfigNode(new ConfigNode()); + //} + } + + public override void OnSave(ConfigNode node) + { + base.OnSave(node); + } + } +} diff --git a/src/RemoteTech-CommandHandler/ICommand.cs b/src/RemoteTech-CommandHandler/ICommand.cs new file mode 100644 index 0000000..ab68197 --- /dev/null +++ b/src/RemoteTech-CommandHandler/ICommand.cs @@ -0,0 +1,6 @@ +namespace RemoteTech.CommandHandler +{ + public interface ICommand + { + } +} \ No newline at end of file diff --git a/src/RemoteTech-CommandHandler/ICommandProvider.cs b/src/RemoteTech-CommandHandler/ICommandProvider.cs new file mode 100644 index 0000000..b04d8a2 --- /dev/null +++ b/src/RemoteTech-CommandHandler/ICommandProvider.cs @@ -0,0 +1,12 @@ +namespace RemoteTech.CommandHandler +{ + public interface ICommandProvider + { + string Name + { + get; + } + + ICommand LoadCommand(ConfigNode node); + } +} \ No newline at end of file diff --git a/src/RemoteTech-CommandHandler/ICondition.cs b/src/RemoteTech-CommandHandler/ICondition.cs new file mode 100644 index 0000000..a74fb5a --- /dev/null +++ b/src/RemoteTech-CommandHandler/ICondition.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace RemoteTech.CommandHandler +{ + interface ICondition + { + } +} diff --git a/src/RemoteTech-CommandHandler/PlannedCommand.cs b/src/RemoteTech-CommandHandler/PlannedCommand.cs new file mode 100644 index 0000000..224f1b9 --- /dev/null +++ b/src/RemoteTech-CommandHandler/PlannedCommand.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace RemoteTech.CommandHandler +{ + class PlannedCommand + { + public const string configNodeName = "PlannedCommand"; + + public PlannedCommand(ConfigNode node) + { + + } + } +} diff --git a/src/RemoteTech-CommandHandler/RemoteTech-CommandHandler.csproj b/src/RemoteTech-CommandHandler/RemoteTech-CommandHandler.csproj index 31995af..d1e2620 100644 --- a/src/RemoteTech-CommandHandler/RemoteTech-CommandHandler.csproj +++ b/src/RemoteTech-CommandHandler/RemoteTech-CommandHandler.csproj @@ -52,9 +52,11 @@ - + + + From bead72a5b97bd581818152e45c66d44291fc708a Mon Sep 17 00:00:00 2001 From: Yamori Yuki Date: Thu, 5 Jan 2017 17:18:04 +0100 Subject: [PATCH 04/12] some progress slowly getting there --- src/RemoteTech-CommandHandler/Command.cs | 70 +++++++++++++++++++ .../CommandManager.cs | 16 ++++- src/RemoteTech-CommandHandler/Condition.cs | 11 +++ src/RemoteTech-CommandHandler/DataScenario.cs | 2 +- src/RemoteTech-CommandHandler/ICommand.cs | 22 ++++++ src/RemoteTech-CommandHandler/ICondition.cs | 11 ++- .../{ICommandProvider.cs => IProvider.cs} | 3 +- .../PlannedCommand.cs | 16 +++++ .../ProviderManager.cs | 30 ++++++++ 9 files changed, 175 insertions(+), 6 deletions(-) create mode 100644 src/RemoteTech-CommandHandler/Command.cs create mode 100644 src/RemoteTech-CommandHandler/Condition.cs rename src/RemoteTech-CommandHandler/{ICommandProvider.cs => IProvider.cs} (65%) create mode 100644 src/RemoteTech-CommandHandler/ProviderManager.cs diff --git a/src/RemoteTech-CommandHandler/Command.cs b/src/RemoteTech-CommandHandler/Command.cs new file mode 100644 index 0000000..a718493 --- /dev/null +++ b/src/RemoteTech-CommandHandler/Command.cs @@ -0,0 +1,70 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace RemoteTech.CommandHandler +{ + class Command : IConfigNode + { + private const string commandNodeName = "Command"; + private ICommand extCommand; + private Command[] subCommands; + + //public Command(){} + + public Command(ConfigNode node) + { + Load(node); + } + + public void Save(ConfigNode node) + { + node.AddValue(ProviderManager.providerConfigLabelName, extCommand.providerName); + var extNode = new ConfigNode(ProviderManager.providerDataNodeName); + extCommand.Save(extNode); + node.AddNode(extNode); + for(var i = 0; i < subCommands.Length; i++) + { + extNode = new ConfigNode(commandNodeName); + subCommands[i].Save(extNode); + node.AddNode(extNode); + } + } + + public void Load(ConfigNode node) + { + string providerName = string.Empty; + ConfigNode extNode = null; + if (node.TryGetValue(ProviderManager.providerConfigLabelName, ref providerName) && node.TryGetNode(ProviderManager.providerDataNodeName, ref extNode)) + { + var provider = ProviderManager.Instance.FindProvider(providerName); + if (provider != null) + { + extCommand = provider.LoadCommand(extNode); + } + else + { + // log "Unable to find provider with name 'providerName'" + } + var subnodes = node.GetNodes(commandNodeName); + subCommands = new Command[subnodes.Length]; + for (var i = 0; i < subnodes.Length; i++) + { + subCommands[i] = new Command(subnodes[i]); + } + } + else + { + if(providerName == string.Empty) + { + // log "Unable to get provider name from config node" + } + if (extNode == null) + { + // log "Unable to get provider data from config node" + } + } + } + } +} diff --git a/src/RemoteTech-CommandHandler/CommandManager.cs b/src/RemoteTech-CommandHandler/CommandManager.cs index 95318b1..2bd2788 100644 --- a/src/RemoteTech-CommandHandler/CommandManager.cs +++ b/src/RemoteTech-CommandHandler/CommandManager.cs @@ -24,6 +24,7 @@ public static CommandManager Instance } private List plannedCommands = new List(initialListSize); + private List delayedCommands = new List(initialListSize); private bool needToLoad = true; public void Awake() @@ -36,12 +37,17 @@ public void OnDestroy() GameEvents.onGameStateLoad.Remove(new EventData.OnEvent(GameLoadEvent)); } - public bool RegisterCommandProvider(ICommandProvider provider) + /// + /// Adds command to the CommandPlanner if capture is on, otherwise queues the command for active vessel + /// + /// + /// + public bool AddCommand(ICommand command) { return true; } - public bool AddCommand(ICommand command) + public bool AddPlannedCommand(ICommand command, ICondition condition) { return true; } @@ -61,9 +67,13 @@ public void LoadFromConfigNode(ConfigNode node) needToLoad = false; } - public void GameLoadEvent(ConfigNode node) + private void GameLoadEvent(ConfigNode node) { needToLoad = true; } + + public void FixedUpdate() + { + } } } diff --git a/src/RemoteTech-CommandHandler/Condition.cs b/src/RemoteTech-CommandHandler/Condition.cs new file mode 100644 index 0000000..9ebeae5 --- /dev/null +++ b/src/RemoteTech-CommandHandler/Condition.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace RemoteTech.CommandHandler +{ + class Condition : IConfigNode + { + } +} diff --git a/src/RemoteTech-CommandHandler/DataScenario.cs b/src/RemoteTech-CommandHandler/DataScenario.cs index f61e18b..583107d 100644 --- a/src/RemoteTech-CommandHandler/DataScenario.cs +++ b/src/RemoteTech-CommandHandler/DataScenario.cs @@ -6,7 +6,7 @@ namespace RemoteTech.CommandHandler { [KSPScenario(ScenarioCreationOptions.AddToAllGames, GameScenes.FLIGHT, GameScenes.SPACECENTER)] - class DataScenario : ScenarioModule + class RTCommandHandlerDataScenario : ScenarioModule { public override void OnLoad(ConfigNode node) { diff --git a/src/RemoteTech-CommandHandler/ICommand.cs b/src/RemoteTech-CommandHandler/ICommand.cs index ab68197..4378829 100644 --- a/src/RemoteTech-CommandHandler/ICommand.cs +++ b/src/RemoteTech-CommandHandler/ICommand.cs @@ -2,5 +2,27 @@ { public interface ICommand { + void Run(); + bool IsReady + { + get; + } + bool IsRunning + { + get; + } + bool HasFinished + { + get; + } + bool HasFailed + { + get; + } + string providerName + { + get; + } + void Save(ConfigNode node); } } \ No newline at end of file diff --git a/src/RemoteTech-CommandHandler/ICondition.cs b/src/RemoteTech-CommandHandler/ICondition.cs index a74fb5a..bfd1a8b 100644 --- a/src/RemoteTech-CommandHandler/ICondition.cs +++ b/src/RemoteTech-CommandHandler/ICondition.cs @@ -5,7 +5,16 @@ namespace RemoteTech.CommandHandler { - interface ICondition + public interface ICondition { + bool IsFulfilled + { + get; + } + string providerName + { + get; + } + void Save(ConfigNode node); } } diff --git a/src/RemoteTech-CommandHandler/ICommandProvider.cs b/src/RemoteTech-CommandHandler/IProvider.cs similarity index 65% rename from src/RemoteTech-CommandHandler/ICommandProvider.cs rename to src/RemoteTech-CommandHandler/IProvider.cs index b04d8a2..88ca175 100644 --- a/src/RemoteTech-CommandHandler/ICommandProvider.cs +++ b/src/RemoteTech-CommandHandler/IProvider.cs @@ -1,6 +1,6 @@ namespace RemoteTech.CommandHandler { - public interface ICommandProvider + public interface IProvider { string Name { @@ -8,5 +8,6 @@ string Name } ICommand LoadCommand(ConfigNode node); + ICondition LoadCondition(ConfigNode node); } } \ No newline at end of file diff --git a/src/RemoteTech-CommandHandler/PlannedCommand.cs b/src/RemoteTech-CommandHandler/PlannedCommand.cs index 224f1b9..f3a7ba5 100644 --- a/src/RemoteTech-CommandHandler/PlannedCommand.cs +++ b/src/RemoteTech-CommandHandler/PlannedCommand.cs @@ -9,9 +9,25 @@ class PlannedCommand { public const string configNodeName = "PlannedCommand"; + public readonly Command command; + public readonly Condition condition; + public readonly Guid vesselId; + public PlannedCommand(ConfigNode node) { } + + public PlannedCommand(Command cmd, Condition cond, Guid vesselGuid) + { + command = cmd; + condition = cond; + vesselId = vesselGuid; + } + + public void Save(ConfigNode node) + { + node.AddNode(""); + } } } diff --git a/src/RemoteTech-CommandHandler/ProviderManager.cs b/src/RemoteTech-CommandHandler/ProviderManager.cs new file mode 100644 index 0000000..2cf3472 --- /dev/null +++ b/src/RemoteTech-CommandHandler/ProviderManager.cs @@ -0,0 +1,30 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using UnityEngine; + +namespace RemoteTech.CommandHandler +{ + [KSPAddon(KSPAddon.Startup.MainMenu, true)] + class ProviderManager : MonoBehaviour + { + public const string providerConfigLabelName = "provider"; + public const string providerDataNodeName = "providerData"; + + public static ProviderManager Instance + { + get; + private set; + } + + public bool RegisterProvider(IProvider provider) + { + return true; + } + public IProvider FindProvider(string name) + { + return null; + } + } +} From 1af5a8e9e2621669765343734c38c48957f70385 Mon Sep 17 00:00:00 2001 From: Yamori Yuki Date: Fri, 6 Jan 2017 13:27:12 +0100 Subject: [PATCH 05/12] save/load cond/cmd - figured out the save/load mechanism that won't require too much messing around - sorted out parts of object structure for Command/Condition trees --- src/RemoteTech-CommandHandler/Command.cs | 22 ++++--- src/RemoteTech-CommandHandler/Condition.cs | 65 +++++++++++++++++++ src/RemoteTech-CommandHandler/ICommand.cs | 7 +- src/RemoteTech-CommandHandler/ICondition.cs | 9 +++ .../RemoteTech-CommandHandler.csproj | 5 +- 5 files changed, 98 insertions(+), 10 deletions(-) diff --git a/src/RemoteTech-CommandHandler/Command.cs b/src/RemoteTech-CommandHandler/Command.cs index a718493..e1c3b12 100644 --- a/src/RemoteTech-CommandHandler/Command.cs +++ b/src/RemoteTech-CommandHandler/Command.cs @@ -8,7 +8,9 @@ namespace RemoteTech.CommandHandler class Command : IConfigNode { private const string commandNodeName = "Command"; - private ICommand extCommand; + + public ICommand extCommand; + private Command[] subCommands; //public Command(){} @@ -20,7 +22,7 @@ public Command(ConfigNode node) public void Save(ConfigNode node) { - node.AddValue(ProviderManager.providerConfigLabelName, extCommand.providerName); + node.AddValue(ProviderManager.providerConfigLabelName, extCommand.ProviderName); var extNode = new ConfigNode(ProviderManager.providerDataNodeName); extCommand.Save(extNode); node.AddNode(extNode); @@ -38,21 +40,25 @@ public void Load(ConfigNode node) ConfigNode extNode = null; if (node.TryGetValue(ProviderManager.providerConfigLabelName, ref providerName) && node.TryGetNode(ProviderManager.providerDataNodeName, ref extNode)) { + var subnodes = node.GetNodes(commandNodeName); + subCommands = new Command[subnodes.Length]; + for (var i = 0; i < subnodes.Length; i++) + { + subCommands[i] = new Command(subnodes[i]); + } var provider = ProviderManager.Instance.FindProvider(providerName); if (provider != null) { extCommand = provider.LoadCommand(extNode); + for (var i=0; i + + - + +