This commit is contained in:
SoulliesOfficial
2025-10-23 00:49:44 -04:00
parent 9b1b5ca93f
commit 61a397dd4c
9846 changed files with 2618439 additions and 793547 deletions

View File

@@ -1,17 +1,56 @@
using UnityEngine;
using System.Collections.Generic;
using UnityEngine;
namespace SoulliesFramework.General
namespace SLSFramework.General
{
/// <summary>
/// 指令上下文 (Command Context)
/// 指令内容 (Command Context)
/// 包含了指令执行时可能需要的所有游戏状态信息。
/// 这个对象在指令组开始执行时创建,并被传递给每一个子指令。
/// 指令组开始执行时创建的CommandContext被传递给每一个子指令。
/// 在ICommand内置的CommandContext中则包含了该指令执行时特有的信息。
/// </summary>
public class CommandContext
{
public Dictionary<string, object> sharedInfo = new Dictionary<string, object>();
public readonly Dictionary<string, object> context;
public CommandContext()
{
context = new Dictionary<string, object>();
}
public CommandContext(string key, object value)
{
context = new Dictionary<string, object>
{
{ key, value }
};
}
public CommandContext(List<KeyValuePair<string, object>> initialInfo)
{
context = new Dictionary<string, object>();
foreach (var pair in initialInfo)
{
context[pair.Key] = pair.Value;
}
}
public CommandContext Clone()
{
var newContext = new CommandContext();
foreach (var pair in context)
{
newContext.context[pair.Key] = pair.Value;
}
return newContext;
}
public T GetInfo<T>(string key)
{
if (context.TryGetValue(key, out object value) && value is T typedValue)
{
return typedValue;
}
return default;
}
}
}