From e644f5c0d769989bd3b0665312c6949d76f5e388 Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Fri, 26 Feb 2021 19:12:45 -0500 Subject: Exposed loadMapScripts to scripting engine This allows common functions to be stored in not per-map script files. Which is useful for code that we're going to want in a lot of places -- i.e. how every underwater map is going to have a copy of the same exit area function. --- res/scripts/underwater.lua | 6 ++++++ res/scripts/underwater_start.lua | 5 ++--- src/script_system.cpp | 6 ++++++ 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/res/scripts/underwater.lua b/res/scripts/underwater.lua index 8e1ae1a..0b62ff5 100644 --- a/res/scripts/underwater.lua +++ b/res/scripts/underwater.lua @@ -1,5 +1,11 @@ underwater = {} +function underwater.make_lucas_underwater() + PreventCrouching() + StartBobbing("lucas") + SetAnimationSlowdown("lucas", 2) +end + function underwater.leave() AllowCrouching() StopBobbing("lucas") diff --git a/res/scripts/underwater_start.lua b/res/scripts/underwater_start.lua index 0852885..56b0b5e 100644 --- a/res/scripts/underwater_start.lua +++ b/res/scripts/underwater_start.lua @@ -1,9 +1,8 @@ underwater_start = {} function underwater_start.init() - PreventCrouching() - StartBobbing("lucas") - SetAnimationSlowdown("lucas", 2) + loadMapScripts("underwater") + underwater.make_lucas_underwater() end function underwater_start.talk_to_fish1() diff --git a/src/script_system.cpp b/src/script_system.cpp index 18a4e39..1846de2 100644 --- a/src/script_system.cpp +++ b/src/script_system.cpp @@ -201,6 +201,12 @@ ScriptSystem::ScriptSystem(Game& game) : game_(game) { return std::bernoulli_distribution(p)(game_.getRng()); }); + engine_.set_function( + "loadMapScripts", + [&] (std::string filename) { + loadMapScripts(filename); + }); + engine_.script_file("../res/scripts/common.lua"); } -- cgit 1.4.1