From 0752b11b65d5c77e7eae81e36d481ea880aef813 Mon Sep 17 00:00:00 2001 From: Joshua Thome Date: Mon, 14 Oct 2024 01:45:44 -0500 Subject: [PATCH] Dream candles --- NewHorizons/Builder/Props/DetailBuilder.cs | 10 +++ .../EchoesOfTheEye/DreamCandleBuilder.cs | 76 +++++++++++++++++++ NewHorizons/Builder/Props/PropBuildManager.cs | 14 ++-- NewHorizons/External/Modules/PropModule.cs | 21 +++-- .../Props/EchoesOfTheEye/DreamCandleInfo.cs | 24 ++++++ .../Props/EchoesOfTheEye/DreamCandleType.cs | 33 ++++++++ 6 files changed, 165 insertions(+), 13 deletions(-) create mode 100644 NewHorizons/Builder/Props/EchoesOfTheEye/DreamCandleBuilder.cs create mode 100644 NewHorizons/External/Modules/Props/EchoesOfTheEye/DreamCandleInfo.cs create mode 100644 NewHorizons/External/Modules/Props/EchoesOfTheEye/DreamCandleType.cs diff --git a/NewHorizons/Builder/Props/DetailBuilder.cs b/NewHorizons/Builder/Props/DetailBuilder.cs index e49feeee..4b499946 100644 --- a/NewHorizons/Builder/Props/DetailBuilder.cs +++ b/NewHorizons/Builder/Props/DetailBuilder.cs @@ -331,6 +331,16 @@ namespace NewHorizons.Builder.Props { remoteCameraPlatform._visualSector = sector; } + + else if(component is SingleLightSensor singleLightSensor && !existingSectors.Contains(singleLightSensor._sector)) + { + if (singleLightSensor._sector != null) + { + singleLightSensor._sector.OnSectorOccupantsUpdated -= singleLightSensor.OnSectorOccupantsUpdated; + } + singleLightSensor._sector = sector; + singleLightSensor._sector.OnSectorOccupantsUpdated += singleLightSensor.OnSectorOccupantsUpdated; + } } /// diff --git a/NewHorizons/Builder/Props/EchoesOfTheEye/DreamCandleBuilder.cs b/NewHorizons/Builder/Props/EchoesOfTheEye/DreamCandleBuilder.cs new file mode 100644 index 00000000..38387bf8 --- /dev/null +++ b/NewHorizons/Builder/Props/EchoesOfTheEye/DreamCandleBuilder.cs @@ -0,0 +1,76 @@ +using NewHorizons.External.Modules.Props; +using NewHorizons.External.Modules.Props.EchoesOfTheEye; +using NewHorizons.Handlers; +using NewHorizons.Utility; +using NewHorizons.Utility.OWML; +using OWML.Common; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using UnityEngine; + +namespace NewHorizons.Builder.Props.EchoesOfTheEye +{ + public static class DreamCandleBuilder + { + private static Dictionary _prefabs = new(); + + internal static void InitPrefabs() + { + InitPrefab(DreamCandleType.Ground, "DreamWorld_Body/Sector_DreamWorld/Sector_DreamZone_1/Interactibles_DreamZone_1/DreamHouseIsland/Prefab_IP_DreamCandle"); + InitPrefab(DreamCandleType.GroundSmall, "DreamWorld_Body/Sector_DreamWorld/Sector_DreamZone_2/Structure_DreamZone_2/City/StartingAreaLanterns/Prefab_IP_DreamCandle_Ground_Small"); + InitPrefab(DreamCandleType.GroundLarge, "DreamWorld_Body/Sector_DreamWorld/Sector_DreamZone_1/Interactibles_DreamZone_1/DreamHouseIsland/Prefab_IP_DreamCandle_Ground_Large"); + InitPrefab(DreamCandleType.GroundSingle, "DreamWorld_Body/Sector_DreamWorld/Sector_DreamZone_1/Sector_PartyHouse/Interactables_PartyHouse/Prefab_IP_DreamCandle_Ground_Single"); + InitPrefab(DreamCandleType.Wall, "DreamWorld_Body/Sector_DreamWorld/Sector_DreamZone_2/Structure_DreamZone_2/City/ParkLanterns/Prefab_IP_DreamCandle_Wall"); + InitPrefab(DreamCandleType.WallLargeFlame, "DreamWorld_Body/Sector_DreamWorld/Sector_DreamZone_2/Structure_DreamZone_2/City/FalseKnightHouse/CandleDoor/FirstDoorLanterns/Prefab_IP_DreamCandle_LargeFlame_Wall"); + InitPrefab(DreamCandleType.WallBigWick, "DreamWorld_Body/Sector_DreamWorld/Sector_DreamZone_2/Structure_DreamZone_2/DreamFireHouse_2/Interactibles_DreamFireHouse_2/Pivot_SlideReelRoom/CandleController/CandlePivot_0/Prefab_IP_DreamCandle_BigWick_Wall"); + InitPrefab(DreamCandleType.Standing, "DreamWorld_Body/Sector_DreamWorld/Sector_DreamZone_2/Structure_DreamZone_2/City/ElevatorHouse/CandleDoor/DoorTutorial/Prefab_IP_DreamCandle_LargeFlame_Standing"); + InitPrefab(DreamCandleType.Pile, "DreamWorld_Body/Sector_DreamWorld/Sector_DreamZone_3/Sector_Hotel/Gallery/Interactibles_Gallery/DreamCandles/Prefab_IP_DreamCandle_Pile"); + } + + private static void InitPrefab(DreamCandleType type, string path) + { + var prefab = _prefabs.ContainsKey(type) ? _prefabs[type] : null; + if (prefab == null) + { + prefab = SearchUtilities.Find(path).InstantiateInactive().Rename($"Prefab_DreamCandle_{type}").DontDestroyOnLoad(); + if (prefab == null) + { + NHLogger.LogWarning($"Tried to make a dream candle but couldn't. Do you have the DLC installed?"); + return; + } + else + { + prefab.AddComponent()._destroyOnDLCNotOwned = true; + var sensor = prefab.GetComponentInChildren(); + sensor._sector = null; + } + _prefabs.Add(type, prefab); + } + } + + public static GameObject Make(GameObject planetGO, Sector sector, DreamCandleInfo info, IModBehaviour mod) + { + InitPrefabs(); + + var prefab = _prefabs.ContainsKey(info.type) ? _prefabs[info.type] : null; + + if (prefab == null || sector == null) return null; + + var candleObj = DetailBuilder.Make(planetGO, sector, mod, prefab, new DetailInfo(info)); + + var dreamCandle = candleObj.GetComponent(); + + var sensor = candleObj.GetComponentInChildren(); + sensor._detectFlashlight = true; + sensor._lightSourceMask |= LightSourceType.FLASHLIGHT; + + dreamCandle._startLit = info.startLit; + dreamCandle.SetLit(info.startLit, false, true); + + return candleObj; + } + } +} diff --git a/NewHorizons/Builder/Props/PropBuildManager.cs b/NewHorizons/Builder/Props/PropBuildManager.cs index d171ae88..64c4221f 100644 --- a/NewHorizons/Builder/Props/PropBuildManager.cs +++ b/NewHorizons/Builder/Props/PropBuildManager.cs @@ -102,11 +102,15 @@ namespace NewHorizons.Builder.Props // If a prop has set its parentPath and the parent cannot be found, add it to the next pass and try again later nextPass = new List(); - if (Main.HasDLC) MakeGeneralProps(go, config.Props.portholes, (porthole) => PortholeBuilder.Make(go, sector, porthole, mod)); - if (Main.HasDLC) MakeGeneralProps(go, config.Props.alarmTotems, (totem) => AlarmTotemBuilder.Make(go, sector, totem, mod)); - if (Main.HasDLC) MakeGeneralProps(go, config.Props.grappleTotems, (totem) => GrappleTotemBuilder.Make(go, sector, totem, mod)); - if (Main.HasDLC) MakeGeneralProps(go, config.Props.dreamCampfires, (campfire) => DreamCampfireBuilder.Make(go, sector, campfire, mod), (campfire) => campfire.id); - if (Main.HasDLC) MakeGeneralProps(go, config.Props.dreamArrivalPoints, (point) => DreamArrivalPointBuilder.Make(go, sector, point, mod), (point) => point.id); + if (Main.HasDLC) + { + MakeGeneralProps(go, config.Props.dreamCandles, (candle) => DreamCandleBuilder.Make(go, sector, candle, mod)); + MakeGeneralProps(go, config.Props.portholes, (porthole) => PortholeBuilder.Make(go, sector, porthole, mod)); + MakeGeneralProps(go, config.Props.alarmTotems, (totem) => AlarmTotemBuilder.Make(go, sector, totem, mod)); + MakeGeneralProps(go, config.Props.grappleTotems, (totem) => GrappleTotemBuilder.Make(go, sector, totem, mod)); + MakeGeneralProps(go, config.Props.dreamCampfires, (campfire) => DreamCampfireBuilder.Make(go, sector, campfire, mod), (campfire) => campfire.id); + MakeGeneralProps(go, config.Props.dreamArrivalPoints, (point) => DreamArrivalPointBuilder.Make(go, sector, point, mod), (point) => point.id); + } MakeGeneralProps(go, config.Props.gravityCannons, (cannon) => GravityCannonBuilder.Make(go, sector, cannon, mod), (cannon) => cannon.shuttleID); MakeGeneralProps(go, config.Props.shuttles, (shuttle) => ShuttleBuilder.Make(go, sector, mod, shuttle), (shuttle) => shuttle.id); MakeGeneralProps(go, config.Props.details, (detail) => DetailBuilder.Make(go, sector, mod, detail), (detail) => detail.path); diff --git a/NewHorizons/External/Modules/PropModule.cs b/NewHorizons/External/Modules/PropModule.cs index 046976d0..3ae2e82f 100644 --- a/NewHorizons/External/Modules/PropModule.cs +++ b/NewHorizons/External/Modules/PropModule.cs @@ -54,7 +54,7 @@ namespace NewHorizons.External.Modules public DetailInfo[] proxyDetails; /// - /// Add rafts to this planet + /// Add rafts to this planet (requires Echoes of the Eye DLC) /// public RaftInfo[] rafts; @@ -64,7 +64,7 @@ namespace NewHorizons.External.Modules public ScatterInfo[] scatter; /// - /// Add slideshows (from the DLC) to the planet + /// Add slideshows to the planet (requires Echoes of the Eye DLC) /// public ProjectionInfo[] slideShows; @@ -124,30 +124,35 @@ namespace NewHorizons.External.Modules public ShuttleInfo[] shuttles; /// - /// Add campfires that allow you to enter the dream world/simulation. Must be paired with a dream arrival point, which can be placed on this planet or elsewhere. + /// Add campfires that allow you to enter the dream world/simulation (requires Echoes of the Eye DLC). Must be paired with a dream arrival point, which can be placed on this planet or elsewhere. /// public DreamCampfireInfo[] dreamCampfires; - + /// - /// Add the points you will arrive at when entering the dream world/simulation from a paired dream campfire, which can be placed on this planet or elsewhere. The planet with the arrival point should be statically positioned to avoid issues with the simulation view materials. + /// Add the points you will arrive at when entering the dream world/simulation from a paired dream campfire (requires Echoes of the Eye DLC). The planet with the arrival point should be statically positioned to avoid issues with the simulation view materials. /// public DreamArrivalPointInfo[] dreamArrivalPoints; /// - /// Adds dream world grapple totems to this planet. + /// Adds dream world grapple totems to this planet (requires Echoes of the Eye DLC). /// public GrappleTotemInfo[] grappleTotems; /// - /// Adds dream world alarm totems to this planet. + /// Adds dream world alarm totems to this planet (requires Echoes of the Eye DLC). /// public AlarmTotemInfo[] alarmTotems; /// - /// Adds portholes (the windows you can peek through in the DLC) to this planet. + /// Adds portholes (the windows you can peek through in the Stranger) to this planet (requires Echoes of the Eye DLC). /// public PortholeInfo[] portholes; + /// + /// Adds dream world candles to this planet (requires Echoes of the Eye DLC). + /// + public DreamCandleInfo[] dreamCandles; + [Obsolete("reveal is deprecated. Use Volumes->revealVolumes instead.")] public RevealVolumeInfo[] reveal; [Obsolete("audioVolumes is deprecated. Use Volumes->audioVolumes instead.")] public AudioVolumeInfo[] audioVolumes; diff --git a/NewHorizons/External/Modules/Props/EchoesOfTheEye/DreamCandleInfo.cs b/NewHorizons/External/Modules/Props/EchoesOfTheEye/DreamCandleInfo.cs new file mode 100644 index 00000000..10106fb8 --- /dev/null +++ b/NewHorizons/External/Modules/Props/EchoesOfTheEye/DreamCandleInfo.cs @@ -0,0 +1,24 @@ +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace NewHorizons.External.Modules.Props.EchoesOfTheEye +{ + [JsonObject] + public class DreamCandleInfo : GeneralPropInfo + { + /// + /// The type of dream candle this is. + /// + [DefaultValue(DreamCandleType.Ground)] public DreamCandleType type = DreamCandleType.Ground; + + /// + /// Whether the candle should start lit or extinguished. + /// + public bool startLit; + } +} diff --git a/NewHorizons/External/Modules/Props/EchoesOfTheEye/DreamCandleType.cs b/NewHorizons/External/Modules/Props/EchoesOfTheEye/DreamCandleType.cs new file mode 100644 index 00000000..07d1f764 --- /dev/null +++ b/NewHorizons/External/Modules/Props/EchoesOfTheEye/DreamCandleType.cs @@ -0,0 +1,33 @@ +using Newtonsoft.Json.Converters; +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.Serialization; +using System.Text; +using System.Threading.Tasks; + +namespace NewHorizons.External.Modules.Props.EchoesOfTheEye +{ + [JsonConverter(typeof(StringEnumConverter))] + public enum DreamCandleType + { + [EnumMember(Value = @"ground")] Ground, + + [EnumMember(Value = @"groundSmall")] GroundSmall, + + [EnumMember(Value = @"groundLarge")] GroundLarge, + + [EnumMember(Value = @"groundSingle")] GroundSingle, + + [EnumMember(Value = @"wall")] Wall, + + [EnumMember(Value = @"wallLargeFlame")] WallLargeFlame, + + [EnumMember(Value = @"wallBigWick")] WallBigWick, + + [EnumMember(Value = @"standing")] Standing, + + [EnumMember(Value = @"pile")] Pile, + } +}