Skip to content

Commit

Permalink
add lua binding to allow adding noteskin actor children at runtime
Browse files Browse the repository at this point in the history
this was made for an optimization to the noteskin preview but you can use it however you want
  • Loading branch information
poco0317 committed Jan 9, 2023
1 parent a178233 commit 8b43403
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/Etterna/Singletons/NoteSkinManager.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "Etterna/Globals/global.h"
#include "Etterna/Actor/Base/ActorUtil.h"
#include "Etterna/Actor/Base/ActorFrame.h"
#include "Etterna/Models/Misc/Foreach.h"
#include "Etterna/Models/Misc/Game.h"
#include "Etterna/Models/Misc/GameInput.h"
Expand Down Expand Up @@ -703,6 +704,33 @@ class LunaNoteSkinManager : public Luna<NoteSkinManager>
FOR_NOTESKIN(GetMetricA, 2);
FOR_NOTESKIN(LoadActor, 2);
#undef FOR_NOTESKIN
static int AddChildActorForNoteSkin(T* p, lua_State* L) {
const std::string sOldNoteSkin = p->GetCurrentNoteSkin();
std::string nsname = SArg(3);
if (!p->DoesNoteSkinExist(nsname)) {
luaL_error(L, "Noteskin \"%s\" does not exist.", nsname.c_str());
}

auto actor = Luna<ActorFrame>::check(L, 4);

p->SetCurrentNoteSkin(nsname);
LoadActor(p, L);
p->SetCurrentNoteSkin(sOldNoteSkin);

auto xnode = XmlFileUtil::XNodeFromTable(L);
if (xnode == nullptr) {
// XNode will warn about the error
lua_pushnil(L);
return 1;
}

auto* result = ActorUtil::LoadFromNode(xnode, actor);
if (result != nullptr) {
actor->AddChild(result);
}
return 1;
}

static int GetNoteSkinNames(T* p, lua_State* L)
{
std::vector<std::string> vNoteskins;
Expand Down Expand Up @@ -742,6 +770,7 @@ class LunaNoteSkinManager : public Luna<NoteSkinManager>
ADD_METHOD(GetMetricBForNoteSkin);
ADD_METHOD(GetMetricAForNoteSkin);
ADD_METHOD(LoadActorForNoteSkin);
ADD_METHOD(AddChildActorForNoteSkin);
ADD_METHOD(GetNoteSkinNames);
ADD_METHOD(DoesNoteSkinExist); // for the current game
}
Expand Down

0 comments on commit 8b43403

Please sign in to comment.