Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions docs/guides/lua.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/program/Context.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "Config.h"
#include "ConcurrentQueue.h"
#include "KeyMapping.h"
#include "movie/MovieFile.h"

#ifdef __unix__
#include <xcb/xcb.h>
Expand Down
3 changes: 3 additions & 0 deletions src/program/GameLoop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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()
Expand Down
46 changes: 46 additions & 0 deletions src/program/lua/Movie.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,16 @@

#include "Context.h"

#include "../movie/MovieActionInsertFrames.h"

#include <iostream>
extern "C" {
#include <lua.h>
#include <lauxlib.h>
}

static Context* context;
static MovieFile* movie;

/* List of functions to register */
static const luaL_Reg movie_functions[] =
Expand All @@ -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 }
};

Expand All @@ -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<lua_Integer>(context->framecount));
Expand Down Expand Up @@ -90,3 +102,37 @@ int Lua::Movie::isDraw(lua_State *L)
lua_pushinteger(L, static_cast<lua_Integer>(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<unsigned int>(lua_tointeger(L, 1));
MovieActionInsertFrames action(context->framecount, n, movie->inputs);
action.redo();
return 0;
}
18 changes: 18 additions & 0 deletions src/program/lua/Movie.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,22 @@ extern "C" {
#include <lua.h>
}

#include <string>

struct Context;

class MovieFile;

namespace Lua {

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);

Expand All @@ -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);
}
}

Expand Down