Skip to content

Commit

Permalink
readd ActorProxy
Browse files Browse the repository at this point in the history
lets us do cool stuff, not really that bad of a thing to have tbh
... if theres weird exploits with this ill figure it out sooner or later
  • Loading branch information
poco0317 committed Sep 23, 2020
1 parent 7b9b7af commit 9cf90f3
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 0 deletions.
67 changes: 67 additions & 0 deletions src/Etterna/Actor/Base/ActorProxy.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#include "Etterna/Globals/global.h"
#include "ActorProxy.h"
#include "Etterna/Actor/Base/ActorUtil.h"

REGISTER_ACTOR_CLASS(ActorProxy);

ActorProxy::ActorProxy()
{
m_pActorTarget = nullptr;
}

bool
ActorProxy::EarlyAbortDraw() const
{
return m_pActorTarget == nullptr || Actor::EarlyAbortDraw();
}

void
ActorProxy::DrawPrimitives()
{
if (m_pActorTarget != nullptr) {
bool bVisible = m_pActorTarget->GetVisible();
m_pActorTarget->SetVisible(true);
m_pActorTarget->Draw();
m_pActorTarget->SetVisible(bVisible);
}
}

void
ActorProxy::LoadFromNode(const XNode* pNode)
{
Actor::LoadFromNode(pNode);
}

// lua start
#include "Etterna/Models/Lua/LuaBinding.h"

/** @brief Allow Lua to have access to the ActorProxy. */
class LunaActorProxy : public Luna<ActorProxy>
{
public:
static int SetTarget(T* p, lua_State* L)
{
Actor* pTarget = Luna<Actor>::check(L, 1);
p->SetTarget(pTarget);
COMMON_RETURN_SELF;
}

static int GetTarget(T* p, lua_State* L)
{
Actor* pTarget = p->GetTarget();
if (pTarget != nullptr)
pTarget->PushSelf(L);
else
lua_pushnil(L);
return 1;
}

LunaActorProxy()
{
ADD_METHOD(SetTarget);
ADD_METHOD(GetTarget);
}
};

LUA_REGISTER_DERIVED_CLASS(ActorProxy, Actor)
// lua end
29 changes: 29 additions & 0 deletions src/Etterna/Actor/Base/ActorProxy.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#ifndef ACTOR_PROXY_H
#define ACTOR_PROXY_H

#include "Actor.h"

struct lua_State;
/** @brief Renders another actor. */
class ActorProxy : public Actor
{
public:
ActorProxy();

virtual bool EarlyAbortDraw() const;
virtual void DrawPrimitives();

void LoadFromNode(const XNode* pNode);
virtual ActorProxy* Copy() const;

Actor* GetTarget() { return m_pActorTarget; }
void SetTarget(Actor* pTarget) { m_pActorTarget = pTarget; }

// Lua
virtual void PushSelf(lua_State* L);

private:
Actor* m_pActorTarget;
};

#endif
2 changes: 2 additions & 0 deletions src/Etterna/Actor/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ list(APPEND ACTOR_BASE_SRC
"Base/ActorFrame.cpp"
"Base/ActorFrameTexture.cpp"
"Base/ActorMultiVertex.cpp"
"Base/ActorProxy.cpp"
"Base/ActorScroller.cpp"
"Base/ActorSound.cpp"
"Base/ActorUtil.cpp"
Expand All @@ -20,6 +21,7 @@ list(APPEND ACTOR_BASE_HPP
"Base/ActorFrame.h"
"Base/ActorFrameTexture.h"
"Base/ActorMultiVertex.h"
"Base/ActorProxy.h"
"Base/ActorScroller.h"
"Base/ActorSound.h"
"Base/ActorUtil.h"
Expand Down

0 comments on commit 9cf90f3

Please sign in to comment.