Start of projection totems

This commit is contained in:
Joshua Thome 2024-10-13 22:18:24 -05:00
parent a1d165e2b9
commit 9a2843c8dc
2 changed files with 159 additions and 0 deletions

View File

@ -0,0 +1,115 @@
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 ProjectionTotemBuilder
{
private static GameObject _prefab;
internal static void InitPrefab()
{
if (_prefab == null)
{
_prefab = SearchUtilities.Find("DreamWorld_Body/Sector_DreamWorld/Sector_DreamZone_3/Interactibles_DreamZone_3/Prefab_IP_DreamObjectProjector_Bridge").InstantiateInactive().Rename("Prefab_ProjectionTotem").DontDestroyOnLoad();
if (_prefab == null)
{
NHLogger.LogWarning($"Tried to make a grapple totem but couldn't. Do you have the DLC installed?");
return;
}
else
{
_prefab.AddComponent<DestroyOnDLC>()._destroyOnDLCNotOwned = true;
var projector = _prefab.GetComponent<DreamObjectProjector>();
projector._projections = new DreamObjectProjection[0];
}
}
}
public static GameObject Make(GameObject planetGO, Sector sector, ProjectionTotemInfo info, IModBehaviour mod)
{
InitPrefab();
if (_prefab == null || sector == null) return null;
var totemObj = DetailBuilder.Make(planetGO, sector, mod, _prefab, new DetailInfo(info));
var projector = totemObj.GetComponent<DreamObjectProjector>();
if (!string.IsNullOrEmpty(info.pathToAlarmTotem))
{
var alarmTotemObj = planetGO.transform.Find(info.pathToAlarmTotem);
if (alarmTotemObj != null)
{
var alarmTotem = alarmTotemObj.GetComponentInChildren<AlarmTotem>();
if (alarmTotem != null)
{
projector._alarmTotem = alarmTotem;
}
}
}
if (info.pathsToDreamCandles != null)
{
var dreamCandles = new List<DreamCandle>();
foreach (var pathToDreamCandles in info.pathsToDreamCandles)
{
if (string.IsNullOrEmpty(pathToDreamCandles)) continue;
var dreamCandleObj = planetGO.transform.Find(pathToDreamCandles);
if (dreamCandleObj != null)
{
dreamCandles.AddRange(dreamCandleObj.GetComponentsInChildren<DreamCandle>());
}
}
projector._dreamCandles = dreamCandles.ToArray();
}
if (info.pathsToProjectionTotems != null)
{
var projectionTotems = new List<DreamObjectProjector>();
foreach (var pathToProjectionTotems in info.pathsToProjectionTotems)
{
if (string.IsNullOrEmpty(pathToProjectionTotems)) continue;
var projectionTotemObj = planetGO.transform.Find(pathToProjectionTotems);
if (projectionTotemObj != null)
{
projectionTotems.AddRange(projectionTotemObj.GetComponentsInChildren<DreamObjectProjector>());
}
}
projector._extinguishedProjectors = projectionTotems.ToArray();
}
if (info.pathsToProjectedObjects != null)
{
var projections = new List<DreamObjectProjection>();
foreach (var pathToProjectedObject in info.pathsToProjectedObjects)
{
if (string.IsNullOrEmpty(pathToProjectedObject)) continue;
var projectionObj = planetGO.transform.Find(pathToProjectedObject);
if (projectionObj != null)
{
projectionObj.gameObject.AddComponent<DitheringAnimator>();
var projection = projectionObj.gameObject.AddComponent<DreamObjectProjection>();
projection._setActive = true;
projection.Awake();
}
}
projector._projections = projections.ToArray();
}
projector.SetLit(info.startLit);
return totemObj;
}
}
}

View File

@ -0,0 +1,44 @@
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 ProjectionTotemInfo : GeneralPropInfo
{
/// <summary>
/// Whether the totem should start lit or extinguished.
/// </summary>
public bool startLit;
/// <summary>
/// Whether the projection totem should be able to extinguished but not be able to be lit again with the artifact. Mainly useful if `startLit` is set to true.
/// </summary>
public bool extinguishOnly;
/// <summary>
/// A relative path from this planet to an alarm totem that will be activated or deactivated based on whether this totem is lit.
/// </summary>
public string pathToAlarmTotem;
/// <summary>
/// Relative paths from this planet to objects containing dream candles that will be activated or deactivated based on whether this totem is lit. All dream candles in the selected objects will be connected to this totem, so they do not need to be specified individually if a parent object is specified.
/// </summary>
public string[] pathsToDreamCandles;
/// <summary>
/// Relative paths from this planet to projection totems that will be deactivated if this totem is extinguished. All projection totems in the selected objects will be connected to this totem, so they do not need to be specified individually if a parent object is specified.
/// </summary>
public string[] pathsToProjectionTotems;
/// <summary>
/// Relative paths from this planet to objects that will appear or disappear when this totem is lit or extinguished. Some types of objects and effects are not supported and will remain visible and active.
/// </summary>
public string[] pathsToProjectedObjects;
}
}