using System; using RynthCore.Plugin.RynthInventory.Data; using RynthCore.Plugin.Shared; using RynthCore.PluginSdk; namespace RynthCore.Plugin.RynthInventory; /// What the window reads and the actions it can take. Plugin pump thread only. internal sealed class InventoryContext { public RynthCoreHost Host; public readonly InventorySettings Settings = new(); public InventoryStore Store = new(); /// The merged view of every file (and this client's live snapshot); null until first built. public InventoryIndex? Index; /// Bumped whenever is replaced. public int IndexRevision; public int BrokenFiles; public bool Loading; public bool InWorld; public uint Player; public string Server = string.Empty; public string Account = string.Empty; public string Character = string.Empty; /// This character's latest snapshot (never changed once published; a change makes a new one). public CharacterSnapshot? Live; public DateTime LastSavedUtc; public string LastSaveError = string.Empty; /// The storage container open right now, if it is being recorded (0 none). public uint OpenStorage; public string OpenStorageLabel = string.Empty; /// The engine draws icons in script windows (op level 2). public bool IconsAvailable; public DateTime UtcNow; public Action RequestRescan = () => { }; public Action RequestReload = () => { }; /// Forgets a character (moves its file aside). Returns a message for the player. public Func Forget = _ => string.Empty; /// /// The plugin's chat lines, queued and written by the tick (Plugins/Shared/CommandReply.cs: the host /// drops a line within 100 ms of another plugin's). Null before Initialize. /// public CommandReply? Reply; public void Print(string text) => Print(text, ok: true); /// A line saying a command didn't work (the failure colour). public void PrintFail(string text) => Print(text, ok: false); private void Print(string text, bool ok) { if (Reply != null) { Reply.Say(ok, text); return; } if (!Host.WriteToChat("[RynthInventory] " + text, ok ? CommandReply.OkChatType : CommandReply.FailChatType)) Host.Log("[RynthInventory] " + text); } }