Add DataOnly plugin to support non-code plugins that just override files

This commit is contained in:
ficedula 2023-08-05 13:44:39 +01:00
parent a6ecf60fb3
commit 5798d5cf37
3 changed files with 45 additions and 1 deletions

View File

@ -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<IPluginInstance> Get(string context, Type t) {
throw new NotImplementedException();
}
public override IEnumerable<Type> GetPluginInstances() {
return Enumerable.Empty<Type>();
}
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));
}
}
}
}
}

View File

@ -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) {

View File

@ -144,6 +144,9 @@ namespace Braver {
new FileDataSource(folder)
};
}
if (Directory.Exists(Path.Combine(folder, "BraverData"))) {
plugins.Add(new DataOnlyPlugin(folder));
}
}
if (plugins.Any()) {