From d3f3caca937314493fdb0af7b01336de96e6766b Mon Sep 17 00:00:00 2001 From: flibber-hk <76987839+flibber-hk@users.noreply.github.com> Date: Sat, 11 Jun 2022 21:19:12 +0100 Subject: [PATCH] Add TabletDeployer --- ItemChanger/Deployer.cs | 6 +++ ItemChanger/Deployers/TabletDeployer.cs | 26 ++++++++++++ ItemChanger/Modules/ReverseBeastDenPath.cs | 2 +- ItemChanger/SmallPlatform.cs | 11 ----- ItemChanger/Util/SceneUtil.cs | 40 +++++++++--------- ItemChanger/Util/TabletUtility.cs | 49 +++++++++++----------- 6 files changed, 77 insertions(+), 57 deletions(-) create mode 100644 ItemChanger/Deployers/TabletDeployer.cs diff --git a/ItemChanger/Deployer.cs b/ItemChanger/Deployer.cs index c7f394c2..cc58ca61 100644 --- a/ItemChanger/Deployer.cs +++ b/ItemChanger/Deployer.cs @@ -11,8 +11,14 @@ public abstract record Deployer : IDeployer public float Y { get; init; } public abstract GameObject Instantiate(); + /// + /// Optional property. If non-null and evaluates false, the GameObject is not deployed. + /// + public IBool Test { get; init; } = null; + public virtual void OnSceneChange(Scene to) { + if (Test != null && !Test.Value) return; Deploy(); } diff --git a/ItemChanger/Deployers/TabletDeployer.cs b/ItemChanger/Deployers/TabletDeployer.cs new file mode 100644 index 00000000..449a9d4f --- /dev/null +++ b/ItemChanger/Deployers/TabletDeployer.cs @@ -0,0 +1,26 @@ +namespace ItemChanger.Deployers +{ + /// + /// A Deployer which creates a lore tablet at the specified point. + /// The tablet will not be readable unless the y value is at least 0.1 higher than the knight's position at ground level. + /// + public record TabletDeployer : Deployer + { + /// + /// The text to display when the tablet is read by the player. + /// + public IString Text { get; init; } + + public override GameObject Instantiate() + { + return Util.TabletUtility.MakeNewTablet("Deployed Tablet", Text.GetValue); + } + + public override GameObject Deploy() + { + GameObject obj = Instantiate(); + Container.GetContainer(Container.Tablet).ApplyTargetContext(obj, X, Y, 0); + return obj; + } + } +} diff --git a/ItemChanger/Modules/ReverseBeastDenPath.cs b/ItemChanger/Modules/ReverseBeastDenPath.cs index d31e0943..b54ad034 100644 --- a/ItemChanger/Modules/ReverseBeastDenPath.cs +++ b/ItemChanger/Modules/ReverseBeastDenPath.cs @@ -20,7 +20,7 @@ public override void Unload() private void SaveBeastsDenCollapserOpen(Scene scene) { - SceneDataUtil.Save("Deepnest_Spider_Town", "Collapser Small (12)"); + SceneDataUtil.Save(SceneNames.Deepnest_Spider_Town, "Collapser Small (12)"); } } } diff --git a/ItemChanger/SmallPlatform.cs b/ItemChanger/SmallPlatform.cs index ad85600e..aef99a41 100644 --- a/ItemChanger/SmallPlatform.cs +++ b/ItemChanger/SmallPlatform.cs @@ -7,20 +7,9 @@ namespace ItemChanger /// public record SmallPlatform : Deployer { - /// - /// Optional property. If non-null and evaluates false, the platform is not deployed. - /// - public IBool Test { get; init; } = null; - public override GameObject Instantiate() { return ObjectCache.SmallPlatform; } - - public override void OnSceneChange(Scene to) - { - if (Test != null && !Test.Value) return; - else base.OnSceneChange(to); - } } } diff --git a/ItemChanger/Util/SceneUtil.cs b/ItemChanger/Util/SceneUtil.cs index cc60290e..a5d0b991 100644 --- a/ItemChanger/Util/SceneUtil.cs +++ b/ItemChanger/Util/SceneUtil.cs @@ -4,26 +4,26 @@ public static class SceneUtil { static Dictionary subScenes = new Dictionary { - { "Crossroads_10_preload", SceneNames.Crossroads_10 }, - { "Crossroads_10_boss", SceneNames.Crossroads_10 }, - { "Crossroads_10_boss_defeated", SceneNames.Crossroads_10 }, - { "Ruins1_24_boss", SceneNames.Ruins1_24 }, - { "Ruins1_24_boss_defeated", SceneNames.Ruins1_24 }, - { "Ruins2_03_boss", SceneNames.Ruins2_03 }, - { "Ruins2_11_boss", SceneNames.Ruins2_11 }, - { "Fungus1_04_boss", SceneNames.Fungus1_04 }, - { "Fungus2_15_boss", SceneNames.Fungus2_15 }, - { "Fungus2_15_boss_defeated", SceneNames.Fungus2_15 }, - { "Fungus3_23_boss", SceneNames.Fungus3_23 }, - { "Fungus3_40_boss", SceneNames.Fungus3_40 }, - { "Fungus3_archive_02_boss", SceneNames.Fungus3_archive_02 }, - { "Cliffs_02_boss", SceneNames.Cliffs_02 }, - { "RestingGrounds_02_boss", SceneNames.RestingGrounds_02 }, - { "Mines_18_boss", SceneNames.Mines_18 }, - { "Deepnest_East_Hornet_boss", SceneNames.Deepnest_East_Hornet }, - { "Waterways_05_boss", SceneNames.Waterways_05 }, - { "Waterways_12_boss", SceneNames.Waterways_12 }, - { "Grimm_Main_Tent_boss", SceneNames.Grimm_Main_Tent }, + { SceneNames.Crossroads_10_preload, SceneNames.Crossroads_10 }, + { SceneNames.Crossroads_10_boss, SceneNames.Crossroads_10 }, + { SceneNames.Crossroads_10_boss_defeated, SceneNames.Crossroads_10 }, + { SceneNames.Ruins1_24_boss, SceneNames.Ruins1_24 }, + { SceneNames.Ruins1_24_boss_defeated, SceneNames.Ruins1_24 }, + { SceneNames.Ruins2_03_boss, SceneNames.Ruins2_03 }, + { SceneNames.Ruins2_11_boss, SceneNames.Ruins2_11 }, + { SceneNames.Fungus1_04_boss, SceneNames.Fungus1_04 }, + { SceneNames.Fungus2_15_boss, SceneNames.Fungus2_15 }, + { SceneNames.Fungus2_15_boss_defeated, SceneNames.Fungus2_15 }, + { SceneNames.Fungus3_23_boss, SceneNames.Fungus3_23 }, + { SceneNames.Fungus3_40_boss, SceneNames.Fungus3_40 }, + { SceneNames.Fungus3_archive_02_boss, SceneNames.Fungus3_archive_02 }, + { SceneNames.Cliffs_02_boss, SceneNames.Cliffs_02 }, + { SceneNames.RestingGrounds_02_boss, SceneNames.RestingGrounds_02 }, + { SceneNames.Mines_18_boss, SceneNames.Mines_18 }, + { SceneNames.Deepnest_East_Hornet_boss, SceneNames.Deepnest_East_Hornet }, + { SceneNames.Waterways_05_boss, SceneNames.Waterways_05 }, + { SceneNames.Waterways_12_boss, SceneNames.Waterways_12 }, + { SceneNames.Grimm_Main_Tent_boss, SceneNames.Grimm_Main_Tent }, }; public static bool TryGetSuperScene(string subScene, out string superScene) diff --git a/ItemChanger/Util/TabletUtility.cs b/ItemChanger/Util/TabletUtility.cs index 2fe6bd55..2c3251b2 100644 --- a/ItemChanger/Util/TabletUtility.cs +++ b/ItemChanger/Util/TabletUtility.cs @@ -8,7 +8,9 @@ namespace ItemChanger.Util { public static class TabletUtility { - public static GameObject MakeNewTablet(AbstractPlacement placement) + public static GameObject InstantiateTablet(AbstractPlacement placement) => InstantiateTablet(GetTabletName(placement)); + + public static GameObject InstantiateTablet(string tabletName) { GameObject tablet = ObjectCache.LoreTablet; @@ -20,25 +22,33 @@ public static GameObject MakeNewTablet(AbstractPlacement placement) lit.AddComponent().sprite = lit_tablet.GetComponent().sprite; lit.GetComponent().color = new Color(1, 1, 1, 0.8f); - tablet.name = GetTabletName(placement); - tablet.SetActive(true); + tablet.name = tabletName; return tablet; } - public static GameObject MakeNewTablet(AbstractPlacement placement, Func textGenerator) + public static GameObject MakeNewTablet(AbstractPlacement placement) { - GameObject tablet = ObjectCache.LoreTablet; + GameObject tablet = InstantiateTablet(placement); + tablet.SetActive(true); - GameObject lit_tablet = tablet.transform.Find("lit_tablet").gameObject; // doesn't appear after instantiation, for some reason - GameObject lit = new GameObject(); - lit.transform.SetParent(tablet.transform); - lit.transform.localPosition = new Vector3(-0.1f, 0.1f, -3f); - lit.transform.localScale = Vector3.one; - lit.AddComponent().sprite = lit_tablet.GetComponent().sprite; - lit.GetComponent().color = new Color(1, 1, 1, 1f); + return tablet; + } - tablet.name = GetTabletName(placement); + public static GameObject MakeNewTablet(AbstractPlacement placement, Func textGenerator) + { + return MakeNewTablet(GetTabletName(placement), textGenerator); + } + + /// + /// Creates a lore tablet GameObject with the specified name and lore text. + /// + /// The name of the tablet. + /// This method is invoked when the player reads the lore tablet to set the displayed text. + /// The tablet GameObject. + public static GameObject MakeNewTablet(string tabletName, Func textGenerator) + { + GameObject tablet = InstantiateTablet(tabletName); tablet.SetActive(true); PlayMakerFSM inspectFsm = tablet.LocateMyFSM("Inspection"); @@ -65,23 +75,12 @@ public static GameObject MakeNewTablet(AbstractPlacement placement, Func promptUp.AddTransition("CONVO_FINISH", turnBack); foreach (var t in setBool.Transitions) t.SetToState(turnBack); - return tablet; } internal static GameObject MakeNewTablet(AbstractPlacement placement, IEnumerable items, FlingType flingType) { - GameObject tablet = ObjectCache.LoreTablet; - - GameObject lit_tablet = tablet.transform.Find("lit_tablet").gameObject; // doesn't appear after instantiation, for some reason - GameObject lit = new GameObject(); - lit.transform.SetParent(tablet.transform); - lit.transform.localPosition = new Vector3(-0.1f, 0.1f, -1.8f); - lit.transform.localScale = Vector3.one; - lit.AddComponent().sprite = lit_tablet.GetComponent().sprite; - lit.GetComponent().color = new Color(1, 1, 1, 0.8f); - - tablet.name = GetTabletName(placement); + GameObject tablet = InstantiateTablet(placement); var info = tablet.AddComponent(); info.containerType = Container.Tablet; info.giveInfo = new ContainerGiveInfo