2024-12-23 21:36:26 -05:00
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
|
|
|
|
|
|
|
|
|
namespace Arrowgene.Ddon.GameServer.Scripting
|
|
|
|
|
{
|
2025-02-03 00:56:57 -05:00
|
|
|
public class MixinModule : GameServerScriptModule
|
2024-12-23 21:36:26 -05:00
|
|
|
{
|
|
|
|
|
public override string ModuleRoot => "mixins";
|
|
|
|
|
public override string Filter => "*.csx";
|
|
|
|
|
public override bool ScanSubdirectories => true;
|
|
|
|
|
public override bool EnableHotLoad => true;
|
|
|
|
|
|
|
|
|
|
private Dictionary<string, object> Mixins { get; set; }
|
|
|
|
|
|
|
|
|
|
public MixinModule()
|
|
|
|
|
{
|
|
|
|
|
Mixins = new Dictionary<string, object>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public T Get<T>(string scriptName)
|
|
|
|
|
{
|
|
|
|
|
if (!Mixins.ContainsKey(scriptName))
|
|
|
|
|
{
|
|
|
|
|
throw new Exception($"A mixin with the name '{scriptName}' doesn't exist");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (T) Mixins[scriptName];
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-30 16:37:22 -04:00
|
|
|
public bool TryGet<T>(string scriptName, out T mixin)
|
|
|
|
|
{
|
|
|
|
|
if (Mixins.TryGetValue(scriptName, out var raw) && raw is T typed)
|
|
|
|
|
{
|
|
|
|
|
mixin = typed;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
mixin = default;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-29 02:07:13 -07:00
|
|
|
public override bool EvaluateResult(string path, object result, IDictionary<string, object> variables)
|
2024-12-23 21:36:26 -05:00
|
|
|
{
|
|
|
|
|
if (result == null)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Mixins are c# Func<> with arbitary return and params based on the functionality
|
|
|
|
|
string mixinName = Path.GetFileNameWithoutExtension(path);
|
2025-06-29 02:07:13 -07:00
|
|
|
Mixins[mixinName] = result;
|
2024-12-23 21:36:26 -05:00
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|