aboutsummaryrefslogtreecommitdiff
path: root/src/lua/modules/graphics/je_lua_spritesheet.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/lua/modules/graphics/je_lua_spritesheet.cpp')
-rw-r--r--src/lua/modules/graphics/je_lua_spritesheet.cpp63
1 files changed, 56 insertions, 7 deletions
diff --git a/src/lua/modules/graphics/je_lua_spritesheet.cpp b/src/lua/modules/graphics/je_lua_spritesheet.cpp
index 8454321..504e022 100644
--- a/src/lua/modules/graphics/je_lua_spritesheet.cpp
+++ b/src/lua/modules/graphics/je_lua_spritesheet.cpp
@@ -1,10 +1,12 @@
-#include "lua/modules/luax.h"
+#include <vector>
+#include "lua/modules/luax.h"
#include "lua/common/je_lua_common.h"
#include "libjin/jin.h"
#include "je_lua_sprite.h"
#include "je_lua_spritesheet.h"
+using namespace std;
using namespace JinEngine::Math;
using namespace JinEngine::Graphics;
@@ -42,8 +44,8 @@ namespace JinEngine
else if (luax_gettop(L) == 3)
{
int o = luax_checkinteger(L, 3);
- Sprite::Origin origin;
- origin = static_cast<Sprite::Origin>(o);
+ Origin origin;
+ origin = static_cast<Origin>(o);
spr = sheet->createSprite(quad, origin);
}
Proxy* pxySprite = luax_newinstance(L, Jin_Lua_Sprite);
@@ -56,15 +58,62 @@ namespace JinEngine
// {} = newSprites
LUA_IMPLEMENT int l_newSprites(lua_State* L)
{
-
+ Proxy* pxySS = (Proxy*)luax_checktype(L, 1, Jin_Lua_SpriteSheet);
+ Shared<SpriteSheet>& shrSS = pxySS->getShared<SpriteSheet>();
+ SpriteSheet* ss = pxySS->getObject<SpriteSheet>();
+ int count = luax_checkinteger(L, 2);
+ int r = luax_checkinteger(L, 3);
+ int c = luax_checkinteger(L, 4);
+ int w = luax_checkinteger(L, 5);
+ int h = luax_checkinteger(L, 6);
+ vector<Sprite*> sprs;
+ int args = luax_gettop(L);
+ if (args == 6)
+ {
+ sprs = ss->createSprites(count, r, c, w, h, Origin::TopLeft);
+ }
+ else if (args >= 8)
+ {
+ int ox = luax_checkinteger(L, 7);
+ int oy = luax_checkinteger(L, 8);
+ int offx = luax_optinteger(L, 9, 0);
+ int offy = luax_optinteger(L, 10, 0);
+ sprs = ss->createSprites(count, r, c, w, h, ox, oy, offx, offy);
+ }
+ else if (args >= 7)
+ {
+ int o = luax_checkinteger(L, 7);
+ Origin origin = static_cast<Origin>(o);
+ int offx = luax_optinteger(L, 8, 0);
+ int offy = luax_optinteger(L, 9, 0);
+ sprs = ss->createSprites(count, r, c, w, h, origin, offx, offy);
+ }
+ else
+ {
+ luax_error(L, "No matched override function.");
+ return 1;
+ }
+ luax_newtable(L);
+ SharedBase* shrGraphic = shrSS.getDependency((int)SpriteSheetDependency::DEP_GRAPHIC);
+ for (int i = 0; i < sprs.size(); ++i)
+ {
+ Sprite* spr = sprs[i];
+ Proxy* pxys = (Proxy*)luax_newinstance(L, Jin_Lua_Sprite);
+ Shared<Sprite>* shrSpr = new Shared<Sprite>(spr, Jin_Lua_Sprite);
+ shrSpr->setDependency((int)SpriteDependency::DEP_GRAPHIC, shrGraphic);
+ pxys->bind(shrSpr);
+ luax_rawseti(L, -2, i + 1);
+ }
+ return 1;
}
LUA_EXPORT void luaopen_SpriteSheet(lua_State* L)
{
luaL_Reg methods[] = {
- { "__gc", l_gc },
- { "newSprite", l_newSprite },
- { 0, 0 }
+ { "__gc", l_gc },
+ { "newSprite", l_newSprite },
+ { "newSprites", l_newSprites },
+ { 0, 0 }
};
luax_newtype(L, Jin_Lua_SpriteSheet, methods);
}