mirror of
https://github.com/ficed/Braver.git
synced 2024-11-23 05:10:08 +00:00
Add DataOnly plugin to support non-code plugins that just override files
This commit is contained in:
parent
a6ecf60fb3
commit
5798d5cf37
41
Braver.Plugins/DataOnlyPlugin.cs
Normal file
41
Braver.Plugins/DataOnlyPlugin.cs
Normal 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));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -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) {
|
||||
|
@ -144,6 +144,9 @@ namespace Braver {
|
||||
new FileDataSource(folder)
|
||||
};
|
||||
}
|
||||
if (Directory.Exists(Path.Combine(folder, "BraverData"))) {
|
||||
plugins.Add(new DataOnlyPlugin(folder));
|
||||
}
|
||||
}
|
||||
|
||||
if (plugins.Any()) {
|
||||
|
Loading…
Reference in New Issue
Block a user