-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add more deployers and SetIBoolOnGiveTag. Fix issue with instantied t…
…ablet position.
- Loading branch information
1 parent
df0efde
commit 7627120
Showing
6 changed files
with
199 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.