Dream candle and projection totem conditions

This commit is contained in:
Joshua Thome 2025-07-01 17:08:13 -05:00
parent b84d94a404
commit d072a74b5d
6 changed files with 142 additions and 0 deletions

View File

@ -1,3 +1,4 @@
using NewHorizons.Components.EOTE;
using NewHorizons.External.Modules.Props;
using NewHorizons.External.Modules.Props.EchoesOfTheEye;
using NewHorizons.Handlers;
@ -9,6 +10,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TerrainBaker;
using UnityEngine;
namespace NewHorizons.Builder.Props.EchoesOfTheEye
@ -70,6 +72,12 @@ namespace NewHorizons.Builder.Props.EchoesOfTheEye
dreamCandle._startLit = info.startLit;
dreamCandle.SetLit(info.startLit, false, true);
if (info.condition != null)
{
var conditionController = dreamCandle.gameObject.AddComponent<DreamLightConditionController>();
conditionController.SetFromInfo(info.condition);
}
return candleObj;
}
}

View File

@ -1,3 +1,4 @@
using NewHorizons.Components.EOTE;
using NewHorizons.External.Modules.Props;
using NewHorizons.External.Modules.Props.EchoesOfTheEye;
using NewHorizons.Handlers;
@ -116,6 +117,13 @@ namespace NewHorizons.Builder.Props.EchoesOfTheEye
projector._lit = info.startLit;
projector._startLit = info.startLit;
projector._extinguishOnly = info.extinguishOnly;
if (info.condition != null)
{
var conditionController = projector.gameObject.AddComponent<DreamLightConditionController>();
conditionController.SetFromInfo(info.condition);
}
/*
Delay.FireOnNextUpdate(() =>
{

View File

@ -0,0 +1,85 @@
using NewHorizons.External.Modules.Props.EchoesOfTheEye;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
namespace NewHorizons.Components.EOTE
{
public class DreamLightConditionController : MonoBehaviour
{
public string Condition { get; set; }
public bool Persistent { get; set; }
public bool Reversible { get; set; }
public bool OnExtinguish { get; set; }
DreamObjectProjector _projector;
DreamCandle _dreamCandle;
public void SetFromInfo(DreamLightConditionInfo info)
{
Condition = info.condition;
Persistent = info.persistent;
Reversible = info.reversible;
OnExtinguish = info.onExtinguish;
}
protected void Awake()
{
_projector = GetComponent<DreamObjectProjector>();
_projector.OnProjectorLit.AddListener(OnProjectorLit);
_projector.OnProjectorExtinguished.AddListener(OnProjectorExtinguished);
_dreamCandle = GetComponent<DreamCandle>();
if (_dreamCandle != null)
{
_dreamCandle.OnLitStateChanged.AddListener(OnCandleLitStateChanged);
}
}
protected void OnDestroy()
{
if (_projector != null)
{
_projector.OnProjectorLit.RemoveListener(OnProjectorLit);
_projector.OnProjectorExtinguished.RemoveListener(OnProjectorExtinguished);
}
if (_dreamCandle != null)
{
_dreamCandle.OnLitStateChanged.RemoveListener(OnCandleLitStateChanged);
}
}
private void OnProjectorLit()
{
HandleCondition(!OnExtinguish);
}
private void OnProjectorExtinguished()
{
HandleCondition(OnExtinguish);
}
private void OnCandleLitStateChanged()
{
HandleCondition(OnExtinguish ? !_dreamCandle._lit : _dreamCandle._lit);
}
private void HandleCondition(bool shouldSet)
{
if (shouldSet || Reversible)
{
if (Persistent)
{
PlayerData.SetPersistentCondition(Condition, shouldSet);
}
else
{
DialogueConditionManager.SharedInstance.SetConditionState(Condition, shouldSet);
}
}
}
}
}

View File

@ -20,5 +20,10 @@ namespace NewHorizons.External.Modules.Props.EchoesOfTheEye
/// Whether the candle should start lit or extinguished.
/// </summary>
public bool startLit;
/// <summary>
/// A condition to set when the candle is lit.
/// </summary>
public DreamLightConditionInfo condition;
}
}

View File

@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace NewHorizons.External.Modules.Props.EchoesOfTheEye
{
public class DreamLightConditionInfo
{
/// <summary>
/// The name of the dialogue condition or persistent condition to set when the light is lit.
/// </summary>
public string condition;
/// <summary>
/// If true, the condition will persist across all future loops until unset.
/// </summary>
public bool persistent;
/// <summary>
/// Whether to unset the condition when the light is extinguished again.
/// </summary>
public bool reversible;
/// <summary>
/// Whether to set the condition when the light is extinguished instead. If `reversible` is true, the condition will be unset when the light is lit again.
/// </summary>
public bool onExtinguish;
}
}

View File

@ -45,5 +45,10 @@ namespace NewHorizons.External.Modules.Props.EchoesOfTheEye
/// If set, projected objects will be set to fully active or fully disabled instantly instead of smoothly fading lights/renderers/colliders. Use this if the normal behavior is insufficient for the objects you're using.
/// </summary>
public bool toggleProjectedObjectsActive;
/// <summary>
/// A condition to set when the totem is lit.
/// </summary>
public DreamLightConditionInfo condition;
}
}