aboutsummaryrefslogtreecommitdiff
path: root/src/lua
diff options
context:
space:
mode:
Diffstat (limited to 'src/lua')
-rw-r--r--src/lua/common/je_lua_shared.hpp7
-rw-r--r--src/lua/modules/graphics/je_lua_graphics.cpp23
-rw-r--r--src/lua/modules/graphics/je_lua_sprite.cpp4
-rw-r--r--src/lua/modules/graphics/je_lua_spritesheet.h17
-rw-r--r--src/lua/modules/graphics/je_lua_texture_font.cpp2
-rw-r--r--src/lua/modules/graphics/je_lua_ttf.cpp2
-rw-r--r--src/lua/modules/types.h1
7 files changed, 52 insertions, 4 deletions
diff --git a/src/lua/common/je_lua_shared.hpp b/src/lua/common/je_lua_shared.hpp
index d6ea357..2c3e309 100644
--- a/src/lua/common/je_lua_shared.hpp
+++ b/src/lua/common/je_lua_shared.hpp
@@ -78,6 +78,13 @@ namespace JinEngine
mDependencies.clear();
}
+ SharedBase* getDependency(int key)
+ {
+ if (!isDependOn(key))
+ return nullptr;
+ return mDependencies.find(key)->second;
+ }
+
protected:
using DepMap = std::map<int, SharedBase*>;
diff --git a/src/lua/modules/graphics/je_lua_graphics.cpp b/src/lua/modules/graphics/je_lua_graphics.cpp
index 5255de7..d129e6a 100644
--- a/src/lua/modules/graphics/je_lua_graphics.cpp
+++ b/src/lua/modules/graphics/je_lua_graphics.cpp
@@ -5,6 +5,7 @@
#include "lua/modules/luax.h"
#include "lua/modules/types.h"
#include "lua/common/je_lua_common.h"
+#include "je_lua_spritesheet.h"
using namespace std;
using namespace JinEngine;
@@ -666,6 +667,27 @@ namespace JinEngine
return 1;
}
+ LUA_IMPLEMENT int l_newSpriteSheet(lua_State* L)
+ {
+ Proxy* pxyGraphic = nullptr;
+ if (luax_istype(L, 1, JIN_GRAPHICS_TEXTURE))
+ pxyGraphic = (Proxy*)luax_checktype(L, 1, JIN_GRAPHICS_TEXTURE);
+ else if(luax_istype(L, 1, JIN_GRAPHICS_CANVAS))
+ pxyGraphic = (Proxy*)luax_checktype(L, 1, JIN_GRAPHICS_CANVAS);
+ if (pxyGraphic != nullptr)
+ {
+ Proxy* pxySSheet = luax_newinstance(L, JIN_GRAPHICS_SPRITESHEET);
+ Graphic* graphic = pxyGraphic->getObject<Graphic>();
+ Shared<SpriteSheet>& shrSSheet = pxySSheet->getShared<SpriteSheet>();
+ Shared<Graphic>& shrGraphic = pxyGraphic->getShared<Graphic>();
+ shrSSheet.setDependency(SpriteSheetDependency::DEP_GRAPHIC, &shrGraphic);
+ pxySSheet->bind(new Shared<SpriteSheet>(new SpriteSheet(graphic), JIN_GRAPHICS_SPRITESHEET));
+ return 1;
+ }
+ else
+ return 0;
+ }
+
/* newTextureFont(bitmap, text, color | cellw, cellh) */
LUA_IMPLEMENT int l_newTextureFont(lua_State* L)
{
@@ -775,6 +797,7 @@ namespace JinEngine
{ "newText", l_newText },
{ "newTextureFont", l_newTextureFont },
{ "newSprite", l_newSprite },
+ { "newSpriteSheet", l_newSpriteSheet },
/* render */
{ "setClearColor", l_setClearColor },
{ "clear", l_clear },
diff --git a/src/lua/modules/graphics/je_lua_sprite.cpp b/src/lua/modules/graphics/je_lua_sprite.cpp
index b81b66b..af1ac60 100644
--- a/src/lua/modules/graphics/je_lua_sprite.cpp
+++ b/src/lua/modules/graphics/je_lua_sprite.cpp
@@ -98,7 +98,7 @@ namespace JinEngine
Proxy* proxy = (Proxy*)luax_checktype(L, 2, JIN_GRAPHICS_SHADER);
Shader* shader = proxy->getObject<Shader>();
sprite->setShader(shader);
- sprite.setDependency(DEP_SHADER, &proxy->getShared<Shader>());
+ sprite.setDependency(SpriteDependency::DEP_SHADER, &proxy->getShared<Shader>());
return 0;
}
@@ -114,7 +114,7 @@ namespace JinEngine
if (p != nullptr)
{
sprite->setGraphic(p->getObject<Graphic>());
- sprite.setDependency(DEP_GRAPHIC, &p->getShared<Graphic>());
+ sprite.setDependency(SpriteDependency::DEP_GRAPHIC, &p->getShared<Graphic>());
}
return 0;
}
diff --git a/src/lua/modules/graphics/je_lua_spritesheet.h b/src/lua/modules/graphics/je_lua_spritesheet.h
new file mode 100644
index 0000000..b4e965d
--- /dev/null
+++ b/src/lua/modules/graphics/je_lua_spritesheet.h
@@ -0,0 +1,17 @@
+#ifndef __JE_LUA_SPRITE_SHEET_H__
+#define __JE_LUA_SPRITE_SHEET_H__
+
+namespace JinEngine
+{
+ namespace Lua
+ {
+
+ enum SpriteSheetDependency
+ {
+ DEP_GRAPHIC = 1
+ };
+
+ }
+}
+
+#endif \ No newline at end of file
diff --git a/src/lua/modules/graphics/je_lua_texture_font.cpp b/src/lua/modules/graphics/je_lua_texture_font.cpp
index dc48ce4..0bd36e6 100644
--- a/src/lua/modules/graphics/je_lua_texture_font.cpp
+++ b/src/lua/modules/graphics/je_lua_texture_font.cpp
@@ -43,7 +43,7 @@ namespace JinEngine
}
Proxy* pxyPage = luax_newinstance(L, JIN_GRAPHICS_PAGE);
Shared<Page>* shrPage = new Shared<Page>(page, JIN_GRAPHICS_PAGE);
- shrPage->setDependency(DEP_TEXTURE_FONT, &shrTexFont);
+ shrPage->setDependency(PageDependency::DEP_TEXTURE_FONT, &shrTexFont);
pxyPage->bind(shrPage);
return 1;
}
diff --git a/src/lua/modules/graphics/je_lua_ttf.cpp b/src/lua/modules/graphics/je_lua_ttf.cpp
index 6cade75..319fdd6 100644
--- a/src/lua/modules/graphics/je_lua_ttf.cpp
+++ b/src/lua/modules/graphics/je_lua_ttf.cpp
@@ -43,7 +43,7 @@ namespace JinEngine
}
Proxy* pxyPage = luax_newinstance(L, JIN_GRAPHICS_PAGE);
Shared<Page>* refPage = new Shared<Page>(page, JIN_GRAPHICS_PAGE);
- refPage->setDependency(DEP_TTF, &shrTTF);
+ refPage->setDependency(PageDependency::DEP_TTF, &shrTTF);
pxyPage->bind(refPage);
return 1;
}
diff --git a/src/lua/modules/types.h b/src/lua/modules/types.h
index 326b5f2..4bd0943 100644
--- a/src/lua/modules/types.h
+++ b/src/lua/modules/types.h
@@ -12,6 +12,7 @@
#define JIN_GRAPHICS_PAGE "Page"
#define JIN_GRAPHICS_BITMAP "Bitmap"
#define JIN_GRAPHICS_SPRITE "Sprite"
+#define JIN_GRAPHICS_SPRITESHEET "SpriteSheet"
// audio module
#define JIN_AUDIO_SOURCE "Source"