Skip to content

Commit

Permalink
Merge pull request #11 from flibber-hk/tablet
Browse files Browse the repository at this point in the history
Add TabletDeployer
  • Loading branch information
homothetyhk authored Jun 11, 2022
2 parents 5f1d0bb + d3f3cac commit df0efde
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 57 deletions.
6 changes: 6 additions & 0 deletions ItemChanger/Deployer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,14 @@ public abstract record Deployer : IDeployer
public float Y { get; init; }
public abstract GameObject Instantiate();

/// <summary>
/// Optional property. If non-null and evaluates false, the GameObject is not deployed.
/// </summary>
public IBool Test { get; init; } = null;

public virtual void OnSceneChange(Scene to)
{
if (Test != null && !Test.Value) return;
Deploy();
}

Expand Down
26 changes: 26 additions & 0 deletions ItemChanger/Deployers/TabletDeployer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
namespace ItemChanger.Deployers
{
/// <summary>
/// A Deployer which creates a lore tablet at the specified point.
/// The tablet will not be readable unless the y value is at least 0.1 higher than the knight's position at ground level.
/// </summary>
public record TabletDeployer : Deployer
{
/// <summary>
/// The text to display when the tablet is read by the player.
/// </summary>
public IString Text { get; init; }

public override GameObject Instantiate()
{
return Util.TabletUtility.MakeNewTablet("Deployed Tablet", Text.GetValue);
}

public override GameObject Deploy()
{
GameObject obj = Instantiate();
Container.GetContainer(Container.Tablet).ApplyTargetContext(obj, X, Y, 0);
return obj;
}
}
}
2 changes: 1 addition & 1 deletion ItemChanger/Modules/ReverseBeastDenPath.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public override void Unload()

private void SaveBeastsDenCollapserOpen(Scene scene)
{
SceneDataUtil.Save("Deepnest_Spider_Town", "Collapser Small (12)");
SceneDataUtil.Save(SceneNames.Deepnest_Spider_Town, "Collapser Small (12)");
}
}
}
11 changes: 0 additions & 11 deletions ItemChanger/SmallPlatform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,9 @@ namespace ItemChanger
/// </summary>
public record SmallPlatform : Deployer
{
/// <summary>
/// Optional property. If non-null and evaluates false, the platform is not deployed.
/// </summary>
public IBool Test { get; init; } = null;

public override GameObject Instantiate()
{
return ObjectCache.SmallPlatform;
}

public override void OnSceneChange(Scene to)
{
if (Test != null && !Test.Value) return;
else base.OnSceneChange(to);
}
}
}
40 changes: 20 additions & 20 deletions ItemChanger/Util/SceneUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,26 @@ public static class SceneUtil
{
static Dictionary<string, string> subScenes = new Dictionary<string, string>
{
{ "Crossroads_10_preload", SceneNames.Crossroads_10 },
{ "Crossroads_10_boss", SceneNames.Crossroads_10 },
{ "Crossroads_10_boss_defeated", SceneNames.Crossroads_10 },
{ "Ruins1_24_boss", SceneNames.Ruins1_24 },
{ "Ruins1_24_boss_defeated", SceneNames.Ruins1_24 },
{ "Ruins2_03_boss", SceneNames.Ruins2_03 },
{ "Ruins2_11_boss", SceneNames.Ruins2_11 },
{ "Fungus1_04_boss", SceneNames.Fungus1_04 },
{ "Fungus2_15_boss", SceneNames.Fungus2_15 },
{ "Fungus2_15_boss_defeated", SceneNames.Fungus2_15 },
{ "Fungus3_23_boss", SceneNames.Fungus3_23 },
{ "Fungus3_40_boss", SceneNames.Fungus3_40 },
{ "Fungus3_archive_02_boss", SceneNames.Fungus3_archive_02 },
{ "Cliffs_02_boss", SceneNames.Cliffs_02 },
{ "RestingGrounds_02_boss", SceneNames.RestingGrounds_02 },
{ "Mines_18_boss", SceneNames.Mines_18 },
{ "Deepnest_East_Hornet_boss", SceneNames.Deepnest_East_Hornet },
{ "Waterways_05_boss", SceneNames.Waterways_05 },
{ "Waterways_12_boss", SceneNames.Waterways_12 },
{ "Grimm_Main_Tent_boss", SceneNames.Grimm_Main_Tent },
{ SceneNames.Crossroads_10_preload, SceneNames.Crossroads_10 },
{ SceneNames.Crossroads_10_boss, SceneNames.Crossroads_10 },
{ SceneNames.Crossroads_10_boss_defeated, SceneNames.Crossroads_10 },
{ SceneNames.Ruins1_24_boss, SceneNames.Ruins1_24 },
{ SceneNames.Ruins1_24_boss_defeated, SceneNames.Ruins1_24 },
{ SceneNames.Ruins2_03_boss, SceneNames.Ruins2_03 },
{ SceneNames.Ruins2_11_boss, SceneNames.Ruins2_11 },
{ SceneNames.Fungus1_04_boss, SceneNames.Fungus1_04 },
{ SceneNames.Fungus2_15_boss, SceneNames.Fungus2_15 },
{ SceneNames.Fungus2_15_boss_defeated, SceneNames.Fungus2_15 },
{ SceneNames.Fungus3_23_boss, SceneNames.Fungus3_23 },
{ SceneNames.Fungus3_40_boss, SceneNames.Fungus3_40 },
{ SceneNames.Fungus3_archive_02_boss, SceneNames.Fungus3_archive_02 },
{ SceneNames.Cliffs_02_boss, SceneNames.Cliffs_02 },
{ SceneNames.RestingGrounds_02_boss, SceneNames.RestingGrounds_02 },
{ SceneNames.Mines_18_boss, SceneNames.Mines_18 },
{ SceneNames.Deepnest_East_Hornet_boss, SceneNames.Deepnest_East_Hornet },
{ SceneNames.Waterways_05_boss, SceneNames.Waterways_05 },
{ SceneNames.Waterways_12_boss, SceneNames.Waterways_12 },
{ SceneNames.Grimm_Main_Tent_boss, SceneNames.Grimm_Main_Tent },
};

public static bool TryGetSuperScene(string subScene, out string superScene)
Expand Down
49 changes: 24 additions & 25 deletions ItemChanger/Util/TabletUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ namespace ItemChanger.Util
{
public static class TabletUtility
{
public static GameObject MakeNewTablet(AbstractPlacement placement)
public static GameObject InstantiateTablet(AbstractPlacement placement) => InstantiateTablet(GetTabletName(placement));

public static GameObject InstantiateTablet(string tabletName)
{
GameObject tablet = ObjectCache.LoreTablet;

Expand All @@ -20,25 +22,33 @@ public static GameObject MakeNewTablet(AbstractPlacement placement)
lit.AddComponent<SpriteRenderer>().sprite = lit_tablet.GetComponent<SpriteRenderer>().sprite;
lit.GetComponent<SpriteRenderer>().color = new Color(1, 1, 1, 0.8f);

tablet.name = GetTabletName(placement);
tablet.SetActive(true);
tablet.name = tabletName;

return tablet;
}

public static GameObject MakeNewTablet(AbstractPlacement placement, Func<string> textGenerator)
public static GameObject MakeNewTablet(AbstractPlacement placement)
{
GameObject tablet = ObjectCache.LoreTablet;
GameObject tablet = InstantiateTablet(placement);
tablet.SetActive(true);

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, -3f);
lit.transform.localScale = Vector3.one;
lit.AddComponent<SpriteRenderer>().sprite = lit_tablet.GetComponent<SpriteRenderer>().sprite;
lit.GetComponent<SpriteRenderer>().color = new Color(1, 1, 1, 1f);
return tablet;
}

tablet.name = GetTabletName(placement);
public static GameObject MakeNewTablet(AbstractPlacement placement, Func<string> textGenerator)
{
return MakeNewTablet(GetTabletName(placement), textGenerator);
}

/// <summary>
/// Creates a lore tablet GameObject with the specified name and lore text.
/// </summary>
/// <param name="tabletName">The name of the tablet.</param>
/// <param name="textGenerator">This method is invoked when the player reads the lore tablet to set the displayed text.</param>
/// <returns>The tablet GameObject.</returns>
public static GameObject MakeNewTablet(string tabletName, Func<string> textGenerator)
{
GameObject tablet = InstantiateTablet(tabletName);
tablet.SetActive(true);

PlayMakerFSM inspectFsm = tablet.LocateMyFSM("Inspection");
Expand All @@ -65,23 +75,12 @@ public static GameObject MakeNewTablet(AbstractPlacement placement, Func<string>
promptUp.AddTransition("CONVO_FINISH", turnBack);
foreach (var t in setBool.Transitions) t.SetToState(turnBack);


return tablet;
}

internal static GameObject MakeNewTablet(AbstractPlacement placement, IEnumerable<AbstractItem> items, FlingType flingType)
{
GameObject tablet = ObjectCache.LoreTablet;

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.localScale = Vector3.one;
lit.AddComponent<SpriteRenderer>().sprite = lit_tablet.GetComponent<SpriteRenderer>().sprite;
lit.GetComponent<SpriteRenderer>().color = new Color(1, 1, 1, 0.8f);

tablet.name = GetTabletName(placement);
GameObject tablet = InstantiateTablet(placement);
var info = tablet.AddComponent<ContainerInfo>();
info.containerType = Container.Tablet;
info.giveInfo = new ContainerGiveInfo
Expand Down

0 comments on commit df0efde

Please sign in to comment.