From 0560bb3368f636e0bf394cf11539704444c88de4 Mon Sep 17 00:00:00 2001 From: samuzad Date: Wed, 15 Apr 2026 09:12:14 +0100 Subject: [PATCH] MVP: tail sync --- BeaverBuddies/Events/EntityUIEvents.cs | 100 ++++++++++++++++++++++++- 1 file changed, 99 insertions(+), 1 deletion(-) diff --git a/BeaverBuddies/Events/EntityUIEvents.cs b/BeaverBuddies/Events/EntityUIEvents.cs index 835d039..812ff67 100644 --- a/BeaverBuddies/Events/EntityUIEvents.cs +++ b/BeaverBuddies/Events/EntityUIEvents.cs @@ -11,6 +11,8 @@ using Timberborn.Characters; using Timberborn.CharactersUI; using Timberborn.CoreUI; +using Timberborn.DecalSystem; +using Timberborn.DecalSystemUI; using Timberborn.Demolishing; using Timberborn.DemolishingUI; using Timberborn.Emptying; @@ -1650,4 +1652,100 @@ public static bool Prefix(WaterSourceRegulator __instance) return WaterSourceRegulatorStateChangedEvent.DoPrefix(__instance, false); } } -} + + [Serializable] + class DecalSupplierActiveDecalChangedEvent : ReplayEvent + { + public string entityID; + public string decalId; + public string category; + + public override void Replay(IReplayContext context) + { + var supplier = GetComponent(context, entityID); + if (!supplier) return; + supplier.SetActiveDecal(new Decal(decalId, category)); + } + + public override string ToActionString() + { + return $"Setting decal for {entityID} to: {decalId}"; + } + } + + [HarmonyPatch(typeof(DecalSupplier), nameof(DecalSupplier.SetActiveDecal))] + class DecalSupplierSetActiveDecalPatcher + { + static bool Prefix(DecalSupplier __instance, Decal decal) + { + if (__instance.ActiveDecal.Equals(decal)) return true; + return ReplayEvent.DoEntityPrefix(__instance, entityID => + { + return new DecalSupplierActiveDecalChangedEvent() + { + entityID = entityID, + decalId = decal.Id, + category = decal.Category, + }; + }); + } + } + + [Serializable] + class FlippableDecalFlipChangedEvent : ReplayEvent + { + public string entityID; + public bool isFlipped; + + public override void Replay(IReplayContext context) + { + var flippable = GetComponent(context, entityID); + if (!flippable) return; + flippable.SetFlip(isFlipped); + } + + public override string ToActionString() + { + return $"Setting decal flip for {entityID} to: {isFlipped}"; + } + } + + [HarmonyPatch(typeof(FlippableDecal), nameof(FlippableDecal.SetFlip))] + class FlippableDecalSetFlipPatcher + { + static bool Prefix(FlippableDecal __instance, bool value) + { + if (__instance.IsFlipped == value) return true; + return ReplayEvent.DoEntityPrefix(__instance, entityID => + { + return new FlippableDecalFlipChangedEvent() + { + entityID = entityID, + isFlipped = value, + }; + }); + } + } + + // Disabling custom patterns for now - if someone is ambitious they can + // figure out a solution for how to sync custom textures across clients. + [HarmonyPatch(typeof(UserDecalService), nameof(UserDecalService.GetCustomDecals))] + class UserDecalServiceGetCustomDecalsPatcher + { + static bool Prefix(ref IEnumerable __result) + { + __result = Enumerable.Empty(); + return false; + } + } + + [HarmonyPatch(typeof(DecalSupplierFragment), nameof(DecalSupplierFragment.ShowFragment))] + class DecalSupplierFragmentShowFragmentPatcher + { + static void Postfix(DecalSupplierFragment __instance, VisualElement ____root) + { + ____root.Q