test some stuff
This commit is contained in:
@@ -3,4 +3,6 @@
|
|||||||
# This software is released under the MIT License.
|
# This software is released under the MIT License.
|
||||||
# https://opensource.org/licenses/MIT
|
# https://opensource.org/licenses/MIT
|
||||||
|
|
||||||
add_asset(TILESET ui.png type=PALETTIZED tileWidth=8 tileHeight=8)
|
add_asset(TILESET ui.png type=PALETTIZED tileWidth=8 tileHeight=8)
|
||||||
|
add_asset(TILESET cell.png type=PALETTIZED tileWidth=8 tileHeight=8)
|
||||||
|
add_asset(TILESET grid.png type=PALETTIZED tileWidth=8 tileHeight=8)
|
||||||
Binary file not shown.
|
Before Width: | Height: | Size: 127 B After Width: | Height: | Size: 168 B |
@@ -9,11 +9,85 @@ module('text')
|
|||||||
module('tileset')
|
module('tileset')
|
||||||
module('texture')
|
module('texture')
|
||||||
|
|
||||||
|
CELL_STATE_DEFAULT = 0
|
||||||
|
CELL_STATE_HOVER = 1
|
||||||
|
CELL_STATE_DOWN = 2
|
||||||
|
CELL_STATE_DISABLED = 3
|
||||||
|
|
||||||
screenSetBackground(colorBlack())
|
screenSetBackground(colorBlack())
|
||||||
camera = cameraCreate(CAMERA_PROJECTION_TYPE_ORTHOGRAPHIC)
|
camera = cameraCreate(CAMERA_PROJECTION_TYPE_ORTHOGRAPHIC)
|
||||||
|
|
||||||
tileset = tilesetGetByName("ui")
|
tilesetUi = tilesetGetByName("ui")
|
||||||
ui = textureLoad(tileset.texture)
|
textureUi = textureLoad(tilesetUi.texture)
|
||||||
|
|
||||||
|
tilesetGrid = tilesetGetByName("grid")
|
||||||
|
textureGrid = textureLoad(tilesetGrid.texture)
|
||||||
|
gridPiece = tilesetPositionGetUV(tilesetGrid, 0, 0)
|
||||||
|
gridSlice = tilesetPositionGetUV(tilesetGrid, 11, 3)
|
||||||
|
|
||||||
|
tilesetCell = tilesetGetByName("cell")
|
||||||
|
textureCell = textureLoad(tilesetCell.texture)
|
||||||
|
cellSliceHover = tilesetPositionGetUV(tilesetCell, 3, 4)
|
||||||
|
cellSliceDefault = tilesetPositionGetUV(tilesetCell, 3, 5)
|
||||||
|
cellSliceDown = tilesetPositionGetUV(tilesetCell, 3, 6)
|
||||||
|
cellSliceDisabled = tilesetPositionGetUV(tilesetCell, 3, 7)
|
||||||
|
|
||||||
|
width = 10
|
||||||
|
height = 14
|
||||||
|
|
||||||
|
i = 0
|
||||||
|
cells = {}
|
||||||
|
for y = 1, height do
|
||||||
|
for x = 1, width do
|
||||||
|
cells[i] = CELL_STATE_DEFAULT
|
||||||
|
i = i + 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function cellDraw(x, y, type)
|
||||||
|
if type == CELL_STATE_HOVER then
|
||||||
|
slice = cellSliceHover
|
||||||
|
elseif type == CELL_STATE_DOWN then
|
||||||
|
slice = cellSliceDown
|
||||||
|
elseif type == CELL_STATE_DISABLED then
|
||||||
|
slice = cellSliceDisabled
|
||||||
|
else
|
||||||
|
slice = cellSliceDefault
|
||||||
|
end
|
||||||
|
|
||||||
|
spriteBatchPush(textureCell,
|
||||||
|
x, y,
|
||||||
|
x + tilesetCell.tileWidth, y + tilesetCell.tileHeight,
|
||||||
|
colorWhite(),
|
||||||
|
slice.u0, slice.v0,
|
||||||
|
slice.u1, slice.v1
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
function backgroundDraw()
|
||||||
|
local t = (TIME.time * 3) % 1
|
||||||
|
local offXStart = gridPiece.u1 * t
|
||||||
|
local offYStart = gridPiece.v1 * t
|
||||||
|
local offXEnd = offXStart + gridPiece.u1
|
||||||
|
local offYEnd = offYStart + gridPiece.v1
|
||||||
|
|
||||||
|
-- Tile background
|
||||||
|
local cols = math.ceil(screenGetWidth() / tilesetGrid.tileWidth)
|
||||||
|
local rows = math.ceil(screenGetHeight() / tilesetGrid.tileHeight)
|
||||||
|
|
||||||
|
for y = 0, rows do
|
||||||
|
for x = 0, cols do
|
||||||
|
spriteBatchPush(
|
||||||
|
textureGrid,
|
||||||
|
x * tilesetGrid.tileWidth, y * tilesetGrid.tileHeight,
|
||||||
|
(x + 1) * tilesetGrid.tileWidth, (y + 1) * tilesetGrid.tileHeight,
|
||||||
|
colorWhite(),
|
||||||
|
gridSlice.u0 + offXStart, gridSlice.v0 + offYStart,
|
||||||
|
gridSlice.u1 + offXEnd, gridSlice.v1 + offYEnd
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
function sceneDispose()
|
function sceneDispose()
|
||||||
end
|
end
|
||||||
@@ -27,17 +101,20 @@ function sceneRender()
|
|||||||
camera.bottom = screenGetHeight()
|
camera.bottom = screenGetHeight()
|
||||||
camera.right = screenGetWidth()
|
camera.right = screenGetWidth()
|
||||||
|
|
||||||
slice = tilesetTileGetUV(tileset, 0)
|
backgroundDraw()
|
||||||
spriteBatchPush(ui,
|
|
||||||
0, 0,
|
|
||||||
ui.width * slice.u1, ui.height * slice.v1,
|
|
||||||
colorRainbow(),
|
|
||||||
slice.u0, slice.v0,
|
|
||||||
slice.u1, slice.v1
|
|
||||||
)
|
|
||||||
spriteBatchFlush()
|
|
||||||
|
|
||||||
-- textDraw(0, 0, "Hello World", colorRainbow())
|
offsetX = 32
|
||||||
|
offsetY = 32
|
||||||
|
for y = 0, height - 1 do
|
||||||
|
for x = 0, width - 1 do
|
||||||
|
cellDraw(
|
||||||
|
x * tilesetCell.tileWidth + offsetX,
|
||||||
|
y * tilesetCell.tileHeight + offsetY,
|
||||||
|
cells[i]
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
spriteBatchFlush()
|
||||||
|
|
||||||
cameraPopMatrix()
|
cameraPopMatrix()
|
||||||
end
|
end
|
||||||
@@ -27,9 +27,8 @@ void moduleColor(scriptcontext_t *context) {
|
|||||||
lua_pushstring(context->luaState, "__tostring");
|
lua_pushstring(context->luaState, "__tostring");
|
||||||
lua_pushcfunction(context->luaState, moduleColorToString);
|
lua_pushcfunction(context->luaState, moduleColorToString);
|
||||||
lua_settable(context->luaState, -3);
|
lua_settable(context->luaState, -3);
|
||||||
|
|
||||||
lua_pop(context->luaState, 1);
|
|
||||||
}
|
}
|
||||||
|
lua_pop(context->luaState, 1);
|
||||||
|
|
||||||
lua_register(context->luaState, "color", moduleColorFuncColor);
|
lua_register(context->luaState, "color", moduleColorFuncColor);
|
||||||
lua_register(context->luaState, "colorRainbow", moduleColorRainbow);
|
lua_register(context->luaState, "colorRainbow", moduleColorRainbow);
|
||||||
|
|||||||
@@ -46,6 +46,21 @@ int moduleTilesetIndex(lua_State *l) {
|
|||||||
} else if(stringCompare(key, "texture") == 0) {
|
} else if(stringCompare(key, "texture") == 0) {
|
||||||
lua_pushstring(l, ts->image);
|
lua_pushstring(l, ts->image);
|
||||||
return 1;
|
return 1;
|
||||||
|
} else if(stringCompare(key, "tileWidth") == 0) {
|
||||||
|
lua_pushnumber(l, ts->tileWidth);
|
||||||
|
return 1;
|
||||||
|
} else if(stringCompare(key, "tileHeight") == 0) {
|
||||||
|
lua_pushnumber(l, ts->tileHeight);
|
||||||
|
return 1;
|
||||||
|
} else if(stringCompare(key, "tileCount") == 0) {
|
||||||
|
lua_pushnumber(l, ts->tileCount);
|
||||||
|
return 1;
|
||||||
|
} else if(stringCompare(key, "columns") == 0) {
|
||||||
|
lua_pushnumber(l, ts->columns);
|
||||||
|
return 1;
|
||||||
|
} else if(stringCompare(key, "rows") == 0) {
|
||||||
|
lua_pushnumber(l, ts->rows);
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
lua_pushnil(l);
|
lua_pushnil(l);
|
||||||
|
|||||||
@@ -13,21 +13,20 @@ void moduleTime(scriptcontext_t *ctx) {
|
|||||||
|
|
||||||
// Script structure
|
// Script structure
|
||||||
if(luaL_newmetatable(ctx->luaState, "time_mt")) {
|
if(luaL_newmetatable(ctx->luaState, "time_mt")) {
|
||||||
// Metatable is new, set __index
|
|
||||||
lua_pushstring(ctx->luaState, "__index");
|
|
||||||
lua_pushcfunction(ctx->luaState, moduleTimeIndex);
|
lua_pushcfunction(ctx->luaState, moduleTimeIndex);
|
||||||
lua_settable(ctx->luaState, -3);
|
lua_setfield(ctx->luaState, -2, "__index");
|
||||||
}
|
}
|
||||||
|
lua_pop(ctx->luaState, 1);
|
||||||
|
|
||||||
// Global time struct
|
dusktime_t **ud = (dusktime_t**)lua_newuserdatauv(
|
||||||
lua_pushlightuserdata(ctx->luaState, &TIME);
|
ctx->luaState, sizeof(dusktime_t*), 0
|
||||||
|
);
|
||||||
|
*ud = &TIME;
|
||||||
luaL_setmetatable(ctx->luaState, "time_mt");
|
luaL_setmetatable(ctx->luaState, "time_mt");
|
||||||
lua_setglobal(ctx->luaState, "TIME");
|
lua_setglobal(ctx->luaState, "TIME");
|
||||||
}
|
}
|
||||||
|
|
||||||
int moduleTimeIndex(lua_State *L) {
|
int moduleTimeIndex(lua_State *L) {
|
||||||
assertNotNull(L, "Lua state cannot be NULL.");
|
|
||||||
|
|
||||||
const char_t *key = lua_tostring(L, 2);
|
const char_t *key = lua_tostring(L, 2);
|
||||||
assertStrLenMin(key, 1, "Key cannot be empty.");
|
assertStrLenMin(key, 1, "Key cannot be empty.");
|
||||||
|
|
||||||
|
|||||||
@@ -45,6 +45,7 @@ def processPalettizedImage(asset):
|
|||||||
elif color[3] == 0 and palColor[3] == 0:
|
elif color[3] == 0 and palColor[3] == 0:
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
|
print('Pallete {} does not contain color #{}'.format(p['paletteName'], '{:02x}{:02x}{:02x}{:02x}'.format(color[0], color[1], color[2], color[3])))
|
||||||
hasAllColors = False
|
hasAllColors = False
|
||||||
break
|
break
|
||||||
if hasAllColors:
|
if hasAllColors:
|
||||||
|
|||||||
Reference in New Issue
Block a user