Skip to content

Commit

Permalink
Add more deployers and SetIBoolOnGiveTag. Fix issue with instantied t…
Browse files Browse the repository at this point in the history
…ablet position.
  • Loading branch information
homothetyhk committed Jun 18, 2022
1 parent df0efde commit 7627120
Show file tree
Hide file tree
Showing 6 changed files with 199 additions and 96 deletions.
19 changes: 19 additions & 0 deletions ItemChanger/Deployers/EnemyBlockerDeployer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
namespace ItemChanger.Deployers
{
/// <summary>
/// Deployer which creates a region which enemies cannot enter.
/// </summary>
public record EnemyBlockerDeployer : Deployer
{
public float Width { get; init; }
public float Height { get; init; }

public override GameObject Instantiate()
{
GameObject go = new() { layer = 15 };
BoxCollider2D box = go.AddComponent<BoxCollider2D>();
box.size = new(Width, Height);
return go;
}
}
}
22 changes: 22 additions & 0 deletions ItemChanger/Deployers/HintBoxDeployer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using ItemChanger.Components;

namespace ItemChanger.Deployers
{
/// <summary>
/// Deployer which creates a HintBox, a region which displays a dream dialogue message when the hero enters.
/// </summary>
public record HintBoxDeployer : Deployer
{
public float Width { get; init; } = 5f;
public float Height { get; init; } = 5f;
public IString Text { get; init; }


public override GameObject Instantiate()
{
HintBox box = HintBox.Create(new Vector2(X, Y), new Vector2(Width, Height));
box.GetDisplayText = Text.GetValue;
return box.gameObject;
}
}
}
57 changes: 57 additions & 0 deletions ItemChanger/Tags/SetIBoolOnGiveTag.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
namespace ItemChanger.Tags
{
/// <summary>
/// Tag which sets an IWriteableBool when its parent item is given.
/// <br/>If attached to a location or placement, sets the bool when VisitState.ObtainedAnyItem is first set on the placement.
/// </summary>
public class SetIBoolOnGiveTag : Tag
{
public IWritableBool Bool;
public bool value = true;

public override void Load(object parent)
{
if (parent is AbstractItem item)
{
item.OnGive += OnGive;
}
else
{
AbstractPlacement placement = parent as AbstractPlacement ?? (parent as AbstractLocation)?.Placement;
if (placement is not null)
{
placement.OnVisitStateChanged += OnVisitStateChanged;
}
}
}

public override void Unload(object parent)
{
if (parent is AbstractItem item)
{
item.OnGive -= OnGive;
}
else
{
AbstractPlacement placement = parent as AbstractPlacement ?? (parent as AbstractLocation)?.Placement;
if (placement is not null)
{
placement.OnVisitStateChanged -= OnVisitStateChanged;
}
}
}

private void OnGive(ReadOnlyGiveEventArgs obj)
{
Bool.Value = value;
}

private void OnVisitStateChanged(VisitStateChangedEventArgs obj)
{
if (obj.NewFlags.HasFlag(VisitState.ObtainedAnyItem) && !obj.Orig.HasFlag(VisitState.ObtainedAnyItem))
{
Bool.Value = value;
}
}
}
}
1 change: 1 addition & 0 deletions ItemChanger/Tags/SetPDBoolOnGiveTag.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
/// Tag which adds setting a PlayerData bool as a side effect to an item.
/// <br/>Be warned that this effect is tied to the tag's parent, regardless of how it is modified during Give.
/// </summary>
[Obsolete("Use SetIBoolOnGiveTag instead.")]
public class SetPDBoolOnGiveTag : Tag
{
public string fieldName;
Expand Down
2 changes: 1 addition & 1 deletion ItemChanger/Util/TabletUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public static GameObject InstantiateTablet(string tabletName)
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.localPosition = new Vector3(-0.1f, 0.1f, -3f);
lit.transform.localScale = Vector3.one;
lit.AddComponent<SpriteRenderer>().sprite = lit_tablet.GetComponent<SpriteRenderer>().sprite;
lit.GetComponent<SpriteRenderer>().color = new Color(1, 1, 1, 0.8f);
Expand Down
Loading

0 comments on commit 7627120

Please sign in to comment.