Skip to content

Commit

Permalink
just make charts available to lua rather than only the playlist
Browse files Browse the repository at this point in the history
  • Loading branch information
MinaciousGrace committed May 13, 2017
1 parent 610c38c commit f5021b3
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
44 changes: 43 additions & 1 deletion src/SongManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ void Chart::FromKey(const string& ck) {
songptr = song;
stepsptr = steps;
LOG->Trace(songptr->GetDisplayMainTitle());
return;
}
loaded = false;
}
Expand Down Expand Up @@ -1478,7 +1479,6 @@ class LunaSongManager: public Luna<SongManager>
LUA_REGISTER_CLASS( SongManager )


/** @brief Allow Lua to have access to the SongManager. */
class LunaPlaylist : public Luna<Playlist>
{
public:
Expand All @@ -1488,6 +1488,17 @@ class LunaPlaylist : public Luna<Playlist>
LuaHelpers::CreateTableFromArray(keys, L);
return 1;
}

static int GetChartlistActual(T* p, lua_State *L)
{
lua_newtable(L);
for (size_t i = 0; i < p->chartlist.size(); ++i)
{
p->chartlist[i].PushSelf(L);
lua_rawseti(L, -2, i + 1);
}
return 1;
}

static int GetRatelist(T* p, lua_State *L)
{
Expand Down Expand Up @@ -1539,6 +1550,7 @@ class LunaPlaylist : public Luna<Playlist>
{
ADD_METHOD(AddChart);
ADD_METHOD(GetChartlist);
ADD_METHOD(GetChartlistActual);
ADD_METHOD(GetNumCharts);
ADD_METHOD(GetRatelist);
ADD_METHOD(GetName);
Expand All @@ -1549,6 +1561,36 @@ class LunaPlaylist : public Luna<Playlist>
};

LUA_REGISTER_CLASS(Playlist)


class LunaChart : public Luna<Chart>
{
public:
DEFINE_METHOD(GetRate, rate);
DEFINE_METHOD(IsLoaded, IsLoaded());
DEFINE_METHOD(GetDifficulty, lastdiff);
DEFINE_METHOD(GetSongTitle, lastsong);
DEFINE_METHOD(GetPackName, lastpack);

static int ChangeRate(T* p, lua_State *L)
{
p->rate += FArg(1);
CLAMP(p->rate, 0.7f, 3.f);
return 1;
}

LunaChart()
{
ADD_METHOD(GetRate);
ADD_METHOD(ChangeRate);
ADD_METHOD(GetDifficulty);
ADD_METHOD(GetSongTitle);
ADD_METHOD(GetPackName);
ADD_METHOD(IsLoaded);
}
};

LUA_REGISTER_CLASS(Chart)
// lua end

/*
Expand Down
3 changes: 3 additions & 0 deletions src/SongManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,13 @@ struct Chart {
Song* songptr;
Steps* stepsptr;

bool IsLoaded() { return loaded; }

bool loaded = false;
void FromKey(const string& ck);
XNode * CreateNode() const;
void LoadFromNode(const XNode * node);
void PushSelf(lua_State *L);
};

struct Playlist {
Expand Down

0 comments on commit f5021b3

Please sign in to comment.