Skip to content

Commit

Permalink
hardcoded lua event tables
Browse files Browse the repository at this point in the history
  • Loading branch information
audinowho committed May 10, 2024
1 parent 8b54f78 commit 40b5248
Show file tree
Hide file tree
Showing 11 changed files with 35 additions and 13 deletions.
4 changes: 2 additions & 2 deletions RogueEssence/Dungeon/GameEffects/BattleEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public override IEnumerator<YieldInstruction> Apply(GameEventOwner owner, Charac
{
LuaTable args = LuaEngine.Instance.RunString("return " + ArgTable).First() as LuaTable;
object[] parameters = new object[] { owner, ownerChar, context, args };
string name = "BATTLE_SCRIPT." + Script;
string name = LuaEngine.EVENT_BATTLE_NAME + "." + Script;
LuaFunction func_iter = LuaEngine.Instance.CreateCoroutineIterator(name, parameters);

yield return CoroutineManager.Instance.StartCoroutine(ScriptEvent.ApplyFunc(name, func_iter));
Expand All @@ -53,7 +53,7 @@ public override IEnumerator<YieldInstruction> Apply(GameEventOwner owner, Charac
ScriptCallState call = ((StatusEffect)owner).StatusStates.Get<ScriptCallState>();
LuaTable args = LuaEngine.Instance.RunString("return " + call.ArgTable).First() as LuaTable;
object[] parameters = new object[] { owner, ownerChar, context, args };
string name = "BATTLE_SCRIPT." + call.Script;
string name = LuaEngine.EVENT_BATTLE_NAME + "." + call.Script;
LuaFunction func_iter = LuaEngine.Instance.CreateCoroutineIterator(name, parameters);

yield return CoroutineManager.Instance.StartCoroutine(ScriptEvent.ApplyFunc(name, func_iter));
Expand Down
2 changes: 1 addition & 1 deletion RogueEssence/Dungeon/GameEffects/ItemGivenEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public override IEnumerator<YieldInstruction> Apply(GameEventOwner owner, Charac
{
LuaTable args = LuaEngine.Instance.RunString("return " + ArgTable).First() as LuaTable;
object[] parameters = new object[] { owner, ownerChar, context, args };
string name = "ITEM_SCRIPT." + Script;
string name = LuaEngine.EVENT_ITEM_NAME + "." + Script;
LuaFunction func_iter = LuaEngine.Instance.CreateCoroutineIterator(name, parameters);

yield return CoroutineManager.Instance.StartCoroutine(ScriptEvent.ApplyFunc(name, func_iter));
Expand Down
2 changes: 1 addition & 1 deletion RogueEssence/Dungeon/GameEffects/MapStatusGivenEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public override IEnumerator<YieldInstruction> Apply(GameEventOwner owner, Charac
{
LuaTable args = LuaEngine.Instance.RunString("return " + ArgTable).First() as LuaTable;
object[] parameters = new object[] { owner, ownerChar, character, status, msg, args };
string name = "MAP_STATUS_SCRIPT." + Script;
string name = LuaEngine.EVENT_MAPSTATUS_NAME + "." + Script;
LuaFunction func_iter = LuaEngine.Instance.CreateCoroutineIterator(name, parameters);

yield return CoroutineManager.Instance.StartCoroutine(ScriptEvent.ApplyFunc(name, func_iter));
Expand Down
2 changes: 1 addition & 1 deletion RogueEssence/Dungeon/GameEffects/RefreshEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ protected RefreshScriptEvent(RefreshScriptEvent other)

public override void Apply(GameEventOwner owner, Character ownerChar, Character character)
{
LuaFunction luafun = LuaEngine.Instance.LuaState.GetFunction("REFRESH_SCRIPT." + Script);
LuaFunction luafun = LuaEngine.Instance.LuaState.GetFunction(LuaEngine.EVENT_REFRESH_NAME + "." + Script);

if (luafun != null)
{
Expand Down
2 changes: 1 addition & 1 deletion RogueEssence/Dungeon/GameEffects/SingleCharEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public override IEnumerator<YieldInstruction> Apply(GameEventOwner owner, Charac
{
LuaTable args = LuaEngine.Instance.RunString("return " + ArgTable).First() as LuaTable;
object[] parameters = new object[] { owner, ownerChar, context, args };
string name = "SINGLE_CHAR_SCRIPT." + Script;
string name = LuaEngine.EVENT_SINGLE_NAME + "." + Script;
LuaFunction func_iter = LuaEngine.Instance.CreateCoroutineIterator(name, parameters);

yield return CoroutineManager.Instance.StartCoroutine(ScriptEvent.ApplyFunc(name, func_iter));
Expand Down
2 changes: 1 addition & 1 deletion RogueEssence/Dungeon/GameEffects/SkillChangeEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ protected SkillChangeScriptEvent(SkillChangeScriptEvent other)

public override void Apply(GameEventOwner owner, Character character, int[] skillIndices)
{
LuaFunction luafun = LuaEngine.Instance.LuaState.GetFunction("SKILL_CHANGE_SCRIPT." + Script);
LuaFunction luafun = LuaEngine.Instance.LuaState.GetFunction(LuaEngine.EVENT_SKILLCHANGE_NAME + "." + Script);

if (luafun != null)
{
Expand Down
2 changes: 1 addition & 1 deletion RogueEssence/Dungeon/GameEffects/StatusGivenEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public override IEnumerator<YieldInstruction> Apply(GameEventOwner owner, Charac
{
LuaTable args = LuaEngine.Instance.RunString("return " + ArgTable).First() as LuaTable;
object[] parameters = new object[] { owner, ownerChar, context, args };
string name = "STATUS_SCRIPT." + Script;
string name = LuaEngine.EVENT_STATUS_NAME + "." + Script;
LuaFunction func_iter = LuaEngine.Instance.CreateCoroutineIterator(name, parameters);

yield return CoroutineManager.Instance.StartCoroutine(ScriptEvent.ApplyFunc(name, func_iter));
Expand Down
2 changes: 1 addition & 1 deletion RogueEssence/Ground/GroundItemEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public override IEnumerator<YieldInstruction> Apply(GroundContext context)
{
LuaTable args = LuaEngine.Instance.RunString("return " + ArgTable).First() as LuaTable;
object[] parameters = new object[] { context, args };
string name = "GROUND_ITEM_EVENT_SCRIPT." + Script;
string name = LuaEngine.EVENT_GROUNDITEM_NAME + "." + Script;
LuaFunction func_iter = LuaEngine.Instance.CreateCoroutineIterator(name, parameters);

yield return CoroutineManager.Instance.StartCoroutine(ScriptEvent.ApplyFunc(name, func_iter));
Expand Down
2 changes: 1 addition & 1 deletion RogueEssence/LevelGen/Floors/GenSteps/ScriptGenStep.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class ScriptGenStep<T> : GenStep<T> where T : BaseMapGenContext

public override void Apply(T map)
{
LuaFunction luafun = LuaEngine.Instance.LuaState.GetFunction("FLOOR_GEN_SCRIPT." + Script);
LuaFunction luafun = LuaEngine.Instance.LuaState.GetFunction(LuaEngine.EVENT_FLOORGEN_NAME + "." + Script);

if (luafun != null)
{
Expand Down
2 changes: 1 addition & 1 deletion RogueEssence/LevelGen/Zones/ZoneSteps/ScriptZoneStep.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ protected ScriptZoneStep(ScriptZoneStep other, ulong seed)

public override void Apply(ZoneGenContext zoneContext, IGenContext context, StablePriorityQueue<Priority, IGenStep> queue)
{
LuaFunction luafun = LuaEngine.Instance.LuaState.GetFunction("ZONE_GEN_SCRIPT." + Script);
LuaFunction luafun = LuaEngine.Instance.LuaState.GetFunction(LuaEngine.EVENT_ZONEGEN_NAME + "." + Script);

if (luafun != null)
{
Expand Down
26 changes: 24 additions & 2 deletions RogueEssence/Lua/LuaEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ public static IEnumerable<EZoneCallbacks> EnumerateZoneCallbackTypes()
/// Create the name of a map's expected callback function in its script.
/// Each specifc callbacks has its own name and format.
/// </summary>
/// <param name="callbackformat"></param>
/// <param name="mapname"></param>
/// <param name="zonename"></param>
/// <param name="callback"></param>
/// <returns></returns>
public static string MakeZoneScriptCallbackName(string zonename, EZoneCallbacks callback)
{
Expand Down Expand Up @@ -359,6 +359,16 @@ private string PathToScript(string script)

//Global lua symbol names
public const string SCRIPT_VARS_NAME = "SV"; //Name of the table of script variables that gets loaded and saved with the game
public const string EVENT_SINGLE_NAME = "SINGLE_CHAR_SCRIPT";
public const string EVENT_BATTLE_NAME = "BATTLE_SCRIPT";
public const string EVENT_STATUS_NAME = "STATUS_SCRIPT";
public const string EVENT_MAPSTATUS_NAME = "MAP_STATUS_SCRIPT";
public const string EVENT_ITEM_NAME = "ITEM_SCRIPT";
public const string EVENT_GROUNDITEM_NAME = "GROUND_ITEM_EVENT_SCRIPT";
public const string EVENT_REFRESH_NAME = "REFRESH_SCRIPT";
public const string EVENT_SKILLCHANGE_NAME = "SKILL_CHANGE_SCRIPT";
public const string EVENT_FLOORGEN_NAME = "FLOOR_GEN_SCRIPT";
public const string EVENT_ZONEGEN_NAME = "ZONE_GEN_SCRIPT";

//Lua State
public const string SCRIPT_PATH = DataManager.DATA_PATH + "Script/"; //Base script engine scripts path
Expand Down Expand Up @@ -631,6 +641,18 @@ private void SetupGlobals()
RunString(MapCurrentScriptSym + " = nil");
RunString(DungeonMapCurrentScriptSym + " = nil");

//Make the callbacks table
LuaState.NewTable(EVENT_SINGLE_NAME);
LuaState.NewTable(EVENT_BATTLE_NAME);
LuaState.NewTable(EVENT_STATUS_NAME);
LuaState.NewTable(EVENT_MAPSTATUS_NAME);
LuaState.NewTable(EVENT_ITEM_NAME);
LuaState.NewTable(EVENT_GROUNDITEM_NAME);
LuaState.NewTable(EVENT_REFRESH_NAME);
LuaState.NewTable(EVENT_SKILLCHANGE_NAME);
LuaState.NewTable(EVENT_FLOORGEN_NAME);
LuaState.NewTable(EVENT_ZONEGEN_NAME);

//Make empty script variable table
LuaState.NewTable(SCRIPT_VARS_NAME);
LuaState[SCRIPT_VARS_NAME + ".__ALL_SET"] = "OK"; //This is just a debug variable, to make sure the table isn't overwritten at runtime by something else, and help track down issues linked to that.
Expand Down

0 comments on commit 40b5248

Please sign in to comment.