diff --git a/WickedEngine/MainComponent_BindLua.cpp b/WickedEngine/MainComponent_BindLua.cpp index f0e3664a7..66ea7e6aa 100644 --- a/WickedEngine/MainComponent_BindLua.cpp +++ b/WickedEngine/MainComponent_BindLua.cpp @@ -1,8 +1,10 @@ #include "MainComponent_BindLua.h" +#include "RenderableComponent_BindLua.h" #include "Renderable3DComponent_BindLua.h" #include "Renderable2DComponent_BindLua.h" #include "DeferredRenderableComponent_BindLua.h" #include "ForwardRenderableComponent_BindLua.h" +#include "LoadingScreenComponent_BindLua.h" #include "wiResourceManager_BindLua.h" const char MainComponent_BindLua::className[] = "MainComponent"; @@ -43,6 +45,12 @@ int MainComponent_BindLua::GetContent(lua_State *L) } int MainComponent_BindLua::GetActiveComponent(lua_State *L) { + if (component == nullptr) + { + wiLua::SError(L, "GetActiveComponent() component is empty!"); + return 0; + } + //return deferred 3d component if the active one is of that type DeferredRenderableComponent* compDef3D = dynamic_cast(component->getActiveComponent()); if (compDef3D != nullptr) @@ -67,6 +75,14 @@ int MainComponent_BindLua::GetActiveComponent(lua_State *L) return 1; } + //return loading component if the active one is of that type + LoadingScreenComponent* compLoad = dynamic_cast(component->getActiveComponent()); + if (compLoad != nullptr) + { + Luna::push(L, new LoadingScreenComponent_BindLua(compLoad)); + return 1; + } + //return 2d component if the active one is of that type Renderable2DComponent* comp2D = dynamic_cast(component->getActiveComponent()); if (comp2D != nullptr) @@ -75,25 +91,85 @@ int MainComponent_BindLua::GetActiveComponent(lua_State *L) return 1; } + //return component if the active one is of that type + RenderableComponent* comp = dynamic_cast(component->getActiveComponent()); + if (comp != nullptr) + { + Luna::push(L, new RenderableComponent_BindLua(comp)); + return 1; + } + wiLua::SError(L, "GetActiveComponent() Warning: type of active component not registered!"); return 0; } int MainComponent_BindLua::SetActiveComponent(lua_State *L) { + if (component == nullptr) + { + wiLua::SError(L, "SetActiveComponent(RenderableComponent component) component is empty!"); + return 0; + } + int argc = wiLua::SGetArgCount(L); if (argc > 1) { - //TODO + ForwardRenderableComponent_BindLua* compFwd3D = Luna::lightcheck(L, 2); + if (compFwd3D != nullptr) + { + component->activateComponent(compFwd3D->component); + return 0; + } + + DeferredRenderableComponent_BindLua* compDef3D = Luna::lightcheck(L, 2); + if (compDef3D != nullptr) + { + component->activateComponent(compDef3D->component); + return 0; + } + + Renderable3DComponent_BindLua* comp3D = Luna::lightcheck(L, 2); + if (comp3D != nullptr) + { + component->activateComponent(comp3D->component); + return 0; + } + + LoadingScreenComponent_BindLua* compLoad = Luna::lightcheck(L, 2); + if (compLoad != nullptr) + { + component->activateComponent(compLoad->component); + return 0; + } + + Renderable2DComponent_BindLua* comp2D = Luna::lightcheck(L, 2); + if (comp2D != nullptr) + { + component->activateComponent(comp2D->component); + return 0; + } + + RenderableComponent_BindLua* comp = Luna::lightcheck(L, 2); + if (comp != nullptr) + { + component->activateComponent(comp->component); + return 0; + } } else { - wiLua::SError(L, "SetActiveComponent(Renderable3DComponent component) not enought arguments!"); + wiLua::SError(L, "SetActiveComponent(RenderableComponent component) not enought arguments!"); return 0; } return 0; } int MainComponent_BindLua::SetFrameSkip(lua_State *L) { + if (component == nullptr) + { + wiLua::SError(L, "SetFrameSkip(bool enabled) component is empty!"); + return 0; + } + int argc = wiLua::SGetArgCount(L); if (argc > 1) { diff --git a/WickedEngine/Renderable2DComponent_BindLua.h b/WickedEngine/Renderable2DComponent_BindLua.h index 4a13092a8..0cad01eba 100644 --- a/WickedEngine/Renderable2DComponent_BindLua.h +++ b/WickedEngine/Renderable2DComponent_BindLua.h @@ -2,12 +2,13 @@ #include "wiLua.h" #include "wiLuna.h" #include "Renderable2DComponent.h" +#include "RenderableComponent_BindLua.h" -class Renderable2DComponent_BindLua +class Renderable2DComponent_BindLua : public RenderableComponent_BindLua { -protected: - Renderable2DComponent* component; public: + Renderable2DComponent* component; + static const char className[]; static Luna::FunctionType methods[]; static Luna::PropertyType properties[]; diff --git a/WickedEngine/Renderable3DComponent_BindLua.h b/WickedEngine/Renderable3DComponent_BindLua.h index 3361be785..3773ddc29 100644 --- a/WickedEngine/Renderable3DComponent_BindLua.h +++ b/WickedEngine/Renderable3DComponent_BindLua.h @@ -2,12 +2,13 @@ #include "wiLua.h" #include "wiLuna.h" #include "Renderable3DComponent.h" +#include "RenderableComponent_BindLua.h" -class Renderable3DComponent_BindLua +class Renderable3DComponent_BindLua : public RenderableComponent_BindLua { -protected: - Renderable3DComponent* component; public: + Renderable3DComponent* component; + static const char className[]; static Luna::FunctionType methods[]; static Luna::PropertyType properties[]; diff --git a/WickedEngine/RenderableComponent_BindLua.cpp b/WickedEngine/RenderableComponent_BindLua.cpp new file mode 100644 index 000000000..be4697fbe --- /dev/null +++ b/WickedEngine/RenderableComponent_BindLua.cpp @@ -0,0 +1,36 @@ +#include "RenderableComponent_BindLua.h" + +const char RenderableComponent_BindLua::className[] = "RenderableComponent"; + +Luna::FunctionType RenderableComponent_BindLua::methods[] = { + { NULL, NULL } +}; +Luna::PropertyType RenderableComponent_BindLua::properties[] = { + { NULL, NULL } +}; + +RenderableComponent_BindLua::RenderableComponent_BindLua(RenderableComponent* component) :component(component) +{ +} + +RenderableComponent_BindLua::RenderableComponent_BindLua(lua_State *L) +{ + component = nullptr; +} + + +RenderableComponent_BindLua::~RenderableComponent_BindLua() +{ +} + +void RenderableComponent_BindLua::Bind() +{ + + static bool initialized = false; + if (!initialized) + { + initialized = true; + Luna::Register(wiLua::GetGlobal()->GetLuaState()); + } +} + diff --git a/WickedEngine/RenderableComponent_BindLua.h b/WickedEngine/RenderableComponent_BindLua.h new file mode 100644 index 000000000..1a0bd5d28 --- /dev/null +++ b/WickedEngine/RenderableComponent_BindLua.h @@ -0,0 +1,20 @@ +#pragma once +#include "wiLua.h" +#include "wiLuna.h" +#include "RenderableComponent.h" + +class RenderableComponent_BindLua +{ +public: + RenderableComponent* component; + static const char className[]; + static Luna::FunctionType methods[]; + static Luna::PropertyType properties[]; + + RenderableComponent_BindLua(RenderableComponent* component = nullptr); + RenderableComponent_BindLua(lua_State *L); + ~RenderableComponent_BindLua(); + + static void Bind(); +}; + diff --git a/WickedEngine/SpriteAnim_BindLua.cpp b/WickedEngine/SpriteAnim_BindLua.cpp new file mode 100644 index 000000000..7eb2d0def --- /dev/null +++ b/WickedEngine/SpriteAnim_BindLua.cpp @@ -0,0 +1,49 @@ +#include "SpriteAnim_BindLua.h" + +const char SpriteAnim_BindLua::className[] = "SpriteAnim"; + +Luna::FunctionType SpriteAnim_BindLua::methods[] = { + lunamethod(SpriteAnim_BindLua, SetRot), + { NULL, NULL } +}; +Luna::PropertyType SpriteAnim_BindLua::properties[] = { + { NULL, NULL } +}; + +SpriteAnim_BindLua::SpriteAnim_BindLua(const wiSprite::Anim& anim) :anim(anim) +{ +} + +SpriteAnim_BindLua::SpriteAnim_BindLua(lua_State *L) +{ + anim = wiSprite::Anim(); +} + +SpriteAnim_BindLua::~SpriteAnim_BindLua() +{ +} + + +int SpriteAnim_BindLua::SetRot(lua_State *L) +{ + int argc = wiLua::SGetArgCount(L); + if (argc > 1) + { + anim.rot = wiLua::SGetFloat(L, 2); + } + else + { + wiLua::SError(L, "SetRot(float rot) not enough arguments!"); + } + return 0; +} + +void SpriteAnim_BindLua::Bind() +{ + static bool initialized = false; + if (!initialized) + { + initialized = true; + Luna::Register(wiLua::GetGlobal()->GetLuaState()); + } +} diff --git a/WickedEngine/SpriteAnim_BindLua.h b/WickedEngine/SpriteAnim_BindLua.h new file mode 100644 index 000000000..0bb683ad1 --- /dev/null +++ b/WickedEngine/SpriteAnim_BindLua.h @@ -0,0 +1,23 @@ +#pragma once +#include "wiLua.h" +#include "wiLuna.h" +#include "wiSprite.h" + +class SpriteAnim_BindLua +{ +public: + wiSprite::Anim anim; + + static const char className[]; + static Luna::FunctionType methods[]; + static Luna::PropertyType properties[]; + + SpriteAnim_BindLua(const wiSprite::Anim& anim); + SpriteAnim_BindLua(lua_State *L); + ~SpriteAnim_BindLua(); + + int SetRot(lua_State *L); + + static void Bind(); +}; + diff --git a/WickedEngine/WickedEngine.vcxproj b/WickedEngine/WickedEngine.vcxproj index 7e45cb52f..ca91dc3cd 100644 --- a/WickedEngine/WickedEngine.vcxproj +++ b/WickedEngine/WickedEngine.vcxproj @@ -217,6 +217,8 @@ + + @@ -423,6 +425,8 @@ + + diff --git a/WickedEngine/WickedEngine.vcxproj.filters b/WickedEngine/WickedEngine.vcxproj.filters index 273c6d618..482cd0e15 100644 --- a/WickedEngine/WickedEngine.vcxproj.filters +++ b/WickedEngine/WickedEngine.vcxproj.filters @@ -54,12 +54,12 @@ {4d8f8d1d-ba7b-4418-9933-725e9d27c0f6} - - {719a8bbd-d0a7-4a16-a409-8c3094008dfd} - {5faa1a83-4a1b-4e70-a9b0-4b935d033095} + + {719a8bbd-d0a7-4a16-a409-8c3094008dfd} + @@ -738,40 +738,46 @@ LUA - ScriptBinders + Lua Bindings - ScriptBinders + Lua Bindings - ScriptBinders + Lua Bindings - ScriptBinders + Lua Bindings - ScriptBinders + Lua Bindings - ScriptBinders + Lua Bindings - ScriptBinders + Lua Bindings - ScriptBinders + Lua Bindings - ScriptBinders + Lua Bindings - ScriptBinders + Lua Bindings - ScriptBinders + Lua Bindings - ScriptBinders + Lua Bindings + + + Lua Bindings + + + Lua Bindings @@ -1679,43 +1685,49 @@ Header Files - ScriptBinders + Lua Bindings - ScriptBinders + Lua Bindings Header Files - ScriptBinders + Lua Bindings - ScriptBinders + Lua Bindings - ScriptBinders + Lua Bindings - ScriptBinders + Lua Bindings - ScriptBinders + Lua Bindings - ScriptBinders + Lua Bindings - ScriptBinders + Lua Bindings - ScriptBinders + Lua Bindings - ScriptBinders + Lua Bindings - ScriptBinders + Lua Bindings + + + Lua Bindings + + + Lua Bindings diff --git a/WickedEngine/wiLua.cpp b/WickedEngine/wiLua.cpp index 42c38db62..4c10263e4 100644 --- a/WickedEngine/wiLua.cpp +++ b/WickedEngine/wiLua.cpp @@ -1,6 +1,7 @@ #include "wiLua.h" #include "wiBackLog.h" #include "MainComponent_BindLua.h" +#include "RenderableComponent_BindLua.h" #include "Renderable2DComponent_BindLua.h" #include "LoadingScreenComponent_BindLua.h" #include "Renderable3DComponent_BindLua.h" @@ -11,6 +12,8 @@ #include "wiSound_BindLua.h" #include "wiSprite_BindLua.h" #include "wiImageEffects_BindLua.h" +#include "SpriteAnim_BindLua.h" +#include "wiResourceManager_BindLua.h" wiLua *wiLua::globalLua = nullptr; @@ -36,6 +39,7 @@ wiLua* wiLua::GetGlobal() globalLua = new wiLua(); MainComponent_BindLua::Bind(); + RenderableComponent_BindLua::Bind(); Renderable2DComponent_BindLua::Bind(); LoadingScreenComponent_BindLua::Bind(); Renderable3DComponent_BindLua::Bind(); @@ -44,8 +48,12 @@ wiLua* wiLua::GetGlobal() Texture_BindLua::Bind(); wiRenderer_BindLua::Bind(); wiSound_BindLua::Bind(); + wiSoundEffect_BindLua::Bind(); + wiMusic_BindLua::Bind(); wiSprite_BindLua::Bind(); wiImageEffects_BindLua::Bind(); + SpriteAnim_BindLua::Bind(); + wiResourceManager_BindLua::Bind(); } return globalLua; } diff --git a/WickedEngine/wiSound_BindLua.cpp b/WickedEngine/wiSound_BindLua.cpp index 567c236ff..0f5c6ef77 100644 --- a/WickedEngine/wiSound_BindLua.cpp +++ b/WickedEngine/wiSound_BindLua.cpp @@ -87,3 +87,68 @@ int wiSound_BindLua::MusicVolume(lua_State *L) return 1; } + + +const char wiSoundEffect_BindLua::className[] = "SoundEffect"; + +Luna::FunctionType wiSoundEffect_BindLua::methods[] = { + lunamethod(wiSoundEffect_BindLua, Play), + lunamethod(wiSoundEffect_BindLua, Stop), + { NULL, NULL } +}; +Luna::PropertyType wiSoundEffect_BindLua::properties[] = { + { NULL, NULL } +}; + +wiSoundEffect_BindLua::wiSoundEffect_BindLua(lua_State *L) +{ + wiSoundEffect_BindLua::wiSound_BindLua(); + int argc = wiLua::SGetArgCount(L); + if (argc > 0) + { + sound = new wiSoundEffect(wiLua::SGetString(L, 1)); + } +} + +void wiSoundEffect_BindLua::Bind() +{ + static bool initialized = false; + if (!initialized) + { + initialized = true; + Luna::Register(wiLua::GetGlobal()->GetLuaState()); + } +} + + +const char wiMusic_BindLua::className[] = "Music"; + +Luna::FunctionType wiMusic_BindLua::methods[] = { + lunamethod(wiMusic_BindLua, Play), + lunamethod(wiMusic_BindLua, Stop), + { NULL, NULL } +}; +Luna::PropertyType wiMusic_BindLua::properties[] = { + { NULL, NULL } +}; + +wiMusic_BindLua::wiMusic_BindLua(lua_State *L) +{ + wiSoundEffect_BindLua::wiSound_BindLua(); + int argc = wiLua::SGetArgCount(L); + if (argc > 0) + { + sound = new wiMusic(wiLua::SGetString(L, 1)); + } +} + +void wiMusic_BindLua::Bind() +{ + static bool initialized = false; + if (!initialized) + { + initialized = true; + Luna::Register(wiLua::GetGlobal()->GetLuaState()); + } +} + diff --git a/WickedEngine/wiSound_BindLua.h b/WickedEngine/wiSound_BindLua.h index e17d971c7..b7a4aa36b 100644 --- a/WickedEngine/wiSound_BindLua.h +++ b/WickedEngine/wiSound_BindLua.h @@ -5,9 +5,8 @@ class wiSound_BindLua { -private: - wiSound* sound; public: + wiSound* sound; static const char className[]; static Luna::FunctionType methods[]; static Luna::PropertyType properties[]; @@ -25,3 +24,25 @@ public: static int MusicVolume(lua_State *L); }; +class wiSoundEffect_BindLua : public wiSound_BindLua +{ +public: + static const char className[]; + static Luna::FunctionType methods[]; + static Luna::PropertyType properties[]; + wiSoundEffect_BindLua(lua_State *L); + + static void Bind(); +}; + +class wiMusic_BindLua : public wiSound_BindLua +{ +public: + static const char className[]; + static Luna::FunctionType methods[]; + static Luna::PropertyType properties[]; + wiMusic_BindLua(lua_State *L); + + static void Bind(); +}; + diff --git a/WickedEngine/wiSprite_BindLua.cpp b/WickedEngine/wiSprite_BindLua.cpp index 60a576d65..0dcff6423 100644 --- a/WickedEngine/wiSprite_BindLua.cpp +++ b/WickedEngine/wiSprite_BindLua.cpp @@ -1,11 +1,14 @@ #include "wiSprite_BindLua.h" #include "wiImageEffects_BindLua.h" +#include "SpriteAnim_BindLua.h" const char wiSprite_BindLua::className[] = "Sprite"; Luna::FunctionType wiSprite_BindLua::methods[] = { lunamethod(wiSprite_BindLua, SetEffects), lunamethod(wiSprite_BindLua, GetEffects), + lunamethod(wiSprite_BindLua, SetAnim), + lunamethod(wiSprite_BindLua, GetAnim), { NULL, NULL } }; Luna::PropertyType wiSprite_BindLua::properties[] = { @@ -72,6 +75,38 @@ int wiSprite_BindLua::GetEffects(lua_State *L) Luna::push(L, new wiImageEffects_BindLua(sprite->effects)); return 1; } +int wiSprite_BindLua::SetAnim(lua_State *L) +{ + if (sprite == nullptr) + { + wiLua::SError(L, "SetAnim() sprite is null!"); + return 0; + } + int argc = wiLua::SGetArgCount(L); + if (argc > 1) + { + SpriteAnim_BindLua* anim = Luna::check(L, 2); + if (anim != nullptr) + { + sprite->anim = anim->anim; + } + } + else + { + wiLua::SError(L, "SetAnim(SpriteAnim anim) not enough arguments!"); + } + return 0; +} +int wiSprite_BindLua::GetAnim(lua_State *L) +{ + if (sprite == nullptr) + { + wiLua::SError(L, "GetAnim() sprite is null!"); + return 0; + } + Luna::push(L, new SpriteAnim_BindLua(sprite->anim)); + return 1; +} void wiSprite_BindLua::Bind() { diff --git a/WickedEngine/wiSprite_BindLua.h b/WickedEngine/wiSprite_BindLua.h index 91c2a17fa..e2ccd77a0 100644 --- a/WickedEngine/wiSprite_BindLua.h +++ b/WickedEngine/wiSprite_BindLua.h @@ -18,6 +18,8 @@ public: int SetEffects(lua_State *L); int GetEffects(lua_State *L); + int SetAnim(lua_State *L); + int GetAnim(lua_State *L); static void Bind(); };