diff --git a/docs/guides/lua.md b/docs/guides/lua.md index 1bebe5af..f8556713 100644 --- a/docs/guides/lua.md +++ b/docs/guides/lua.md @@ -299,6 +299,30 @@ Returns the current rerecord count of the movie, or -1 if no movie is loaded Returns 1 of the current frame is a draw frame, or 0 if not. +#### movie.getMarker + + String movie.getMarker() + +Returns the marker at current frame if there is one, none instead. + +#### movie.setMarker + + none movie.setMarker(String text) + +Edit marker at current frame with the text given as parameter. + +#### movie.insertFrame + + none movie.insertFrame() + +Insert frame at current position + +#### movie.insertFrames + + none movie.insertFrames(Number nb_frames) + +Insert `nb_frame` frames at current position + ### Runtime functions Runtime functions must be performed in callback `onFrame()` to be effective on diff --git a/src/program/Context.h b/src/program/Context.h index e07f7804..dab97d98 100644 --- a/src/program/Context.h +++ b/src/program/Context.h @@ -23,6 +23,7 @@ #include "Config.h" #include "ConcurrentQueue.h" #include "KeyMapping.h" +#include "movie/MovieFile.h" #ifdef __unix__ #include diff --git a/src/program/GameLoop.cpp b/src/program/GameLoop.cpp index 0d0da792..40f8cb0f 100644 --- a/src/program/GameLoop.cpp +++ b/src/program/GameLoop.cpp @@ -37,6 +37,7 @@ #include "SaveStateList.h" #include "lua/Input.h" #include "lua/Callbacks.h" +#include "lua/Movie.h" #include "lua/NamedLuaFunction.h" #include "ramsearch/MemAccess.h" #include "ramsearch/BaseAddresses.h" @@ -67,6 +68,8 @@ GameLoop::GameLoop(Context* c) : movie(MovieFile(c)), context(c) #elif defined(__APPLE__) && defined(__MACH__) gameEvents = new GameEventsQuartz(c, &movie); #endif + /* Register Movie so that lua scripts can modify it */ + Lua::Movie::registerMovie(&movie); } void GameLoop::start() diff --git a/src/program/lua/Movie.cpp b/src/program/lua/Movie.cpp index b2d9c772..780ab5ae 100644 --- a/src/program/lua/Movie.cpp +++ b/src/program/lua/Movie.cpp @@ -21,6 +21,8 @@ #include "Context.h" +#include "../movie/MovieActionInsertFrames.h" + #include extern "C" { #include @@ -28,6 +30,7 @@ extern "C" { } static Context* context; +static MovieFile* movie; /* List of functions to register */ static const luaL_Reg movie_functions[] = @@ -38,6 +41,10 @@ static const luaL_Reg movie_functions[] = { "time", Lua::Movie::time}, { "rerecords", Lua::Movie::rerecords}, { "isDraw", Lua::Movie::isDraw}, + { "getMarker", Lua::Movie::getMarker}, + { "setMarker", Lua::Movie::setMarker}, + { "insertFrame", Lua::Movie::insertFrame}, + { "insertFrames", Lua::Movie::insertFrames}, { NULL, NULL } }; @@ -48,6 +55,11 @@ void Lua::Movie::registerFunctions(lua_State *L, Context* c) lua_setglobal(L, "movie"); } +void Lua::Movie::registerMovie(MovieFile* frame_movie) +{ + movie = frame_movie; +} + int Lua::Movie::currentFrame(lua_State *L) { lua_pushinteger(L, static_cast(context->framecount)); @@ -90,3 +102,37 @@ int Lua::Movie::isDraw(lua_State *L) lua_pushinteger(L, static_cast(context->draw_frame)); return 1; } + +int Lua::Movie::getMarker(lua_State *L) +{ + std::string marker; + try { + marker = movie->editor->markers.at(context->framecount); + } catch (const std::out_of_range&) { + return 0; + } + lua_pushstring(L, marker.c_str()); + return 1; +} + +int Lua::Movie::setMarker(lua_State *L) +{ + const char* marker = lua_tostring(L, 1); + movie->editor->markers[context->framecount] = marker; + return 0; +} + +int Lua::Movie::insertFrame(lua_State *L) +{ + MovieActionInsertFrames action(context->framecount, 1, movie->inputs); + action.redo(); + return 0; +} + +int Lua::Movie::insertFrames(lua_State *L) +{ + unsigned int n = static_cast(lua_tointeger(L, 1)); + MovieActionInsertFrames action(context->framecount, n, movie->inputs); + action.redo(); + return 0; +} diff --git a/src/program/lua/Movie.h b/src/program/lua/Movie.h index 15ec310e..5e256e3d 100644 --- a/src/program/lua/Movie.h +++ b/src/program/lua/Movie.h @@ -24,8 +24,12 @@ extern "C" { #include } +#include + struct Context; +class MovieFile; + namespace Lua { namespace Movie { @@ -33,6 +37,9 @@ namespace Movie { /* Register all functions */ void registerFunctions(lua_State *L, Context* c); + /* Pass the current MovieFile object to be used by lua functions */ + void registerMovie(MovieFile* frame_movie); + /* Get the current framecount */ int currentFrame(lua_State *L); @@ -51,6 +58,17 @@ namespace Movie { /* Returns if the current frame is a draw frame */ int isDraw(lua_State *L); + /* Get marker at current frame if there is one */ + int getMarker(lua_State *L); + + /* Set marker at current frame */ + int setMarker(lua_State *L); + + /* Insert frame at current position */ + int insertFrame(lua_State *L); + + /* Insert n frames at current position */ + int insertFrames(lua_State *L); } }