From 5798d5cf37a3a8e14c52ce5f64eacd8c82ae6f89 Mon Sep 17 00:00:00 2001 From: ficedula Date: Sat, 5 Aug 2023 13:44:39 +0100 Subject: [PATCH] Add DataOnly plugin to support non-code plugins that just override files --- Braver.Plugins/DataOnlyPlugin.cs | 41 ++++++++++++++++++++++++++++++++ Braver.Plugins/Plugin.cs | 2 +- Braver/FGame.cs | 3 +++ 3 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 Braver.Plugins/DataOnlyPlugin.cs diff --git a/Braver.Plugins/DataOnlyPlugin.cs b/Braver.Plugins/DataOnlyPlugin.cs new file mode 100644 index 0000000..38375db --- /dev/null +++ b/Braver.Plugins/DataOnlyPlugin.cs @@ -0,0 +1,41 @@ +// This program and the accompanying materials are made available under the terms of the +// Eclipse Public License v2.0 which accompanies this distribution, and is available at +// https://www.eclipse.org/legal/epl-v20.html +// +// SPDX-License-Identifier: EPL-2.0 + +using System; +using System.Collections.Generic; +using System.Linq; + +namespace Braver.Plugins { + public class DataOnlyPlugin : Plugin { + + private string _root; + + public override string Name => $"Data Plugin: {_root}"; + public override Version Version => new Version(1, 0, 0); + public override object ConfigObject => null; + + public DataOnlyPlugin(string root) { + _root = root; + } + + public override IEnumerable Get(string context, Type t) { + throw new NotImplementedException(); + } + + public override IEnumerable GetPluginInstances() { + return Enumerable.Empty(); + } + + public override void Init(BGame game) { + string data = Path.Combine(_root, "BraverData"); + if (Directory.Exists(data)) { + foreach(string folder in Directory.GetDirectories(data)) { + game.AddDataSource(Path.GetFileName(folder), new FileDataSource(folder)); + } + } + } + } +} diff --git a/Braver.Plugins/Plugin.cs b/Braver.Plugins/Plugin.cs index 9a4b7ef..531afb4 100644 --- a/Braver.Plugins/Plugin.cs +++ b/Braver.Plugins/Plugin.cs @@ -93,7 +93,7 @@ namespace Braver.Plugins { Plugin = pl, Config = configs.Configs.FirstOrDefault(cfg => cfg.PluginClass == pl.GetType().FullName) ?? new PluginConfig(), }) - .Where(pl => pl.Config.Enabled) + .Where(pl => pl.Config.Enabled || (pl.Plugin is DataOnlyPlugin)) .OrderBy(pl => pl.Config.Priority); foreach(var p in configuredPlugins) { diff --git a/Braver/FGame.cs b/Braver/FGame.cs index 2320fda..3f91b28 100644 --- a/Braver/FGame.cs +++ b/Braver/FGame.cs @@ -144,6 +144,9 @@ namespace Braver { new FileDataSource(folder) }; } + if (Directory.Exists(Path.Combine(folder, "BraverData"))) { + plugins.Add(new DataOnlyPlugin(folder)); + } } if (plugins.Any()) {