- VERSIÓ 1.1

- [NEW] map.surf() per a obtindre i fixar la surface que usa el tilemap
- [NEW] Llevats map.new, map.load i map.save. Es fa des de les surfaces.
This commit is contained in:
2025-06-17 13:53:45 +02:00
parent 2a4195c839
commit 16be589a72
4 changed files with 20 additions and 22 deletions

18
lua.cpp
View File

@@ -125,6 +125,7 @@ extern "C" {
// map // map
// =============================================== // ===============================================
/*
static int cpp_map_new(lua_State *L) { static int cpp_map_new(lua_State *L) {
int w = luaL_checknumber(L, 1); int w = luaL_checknumber(L, 1);
int h = luaL_checknumber(L, 2); int h = luaL_checknumber(L, 2);
@@ -148,10 +149,17 @@ extern "C" {
savesurf(surface, str, nullptr); savesurf(surface, str, nullptr);
return 0; return 0;
} }
*/
static int cpp_map_set(lua_State *L) { static int cpp_map_surf(lua_State *L) {
if (lua_gettop(L)==1) {
uint8_t surface = luaL_checkinteger(L, 1); uint8_t surface = luaL_checkinteger(L, 1);
setmap(surface); setmap(surface);
} else {
lua_pushinteger(L, getmap());
return 1;
}
return 0; return 0;
} }
@@ -826,10 +834,10 @@ void push_lua_funcs() {
lua_setglobal(L, "surf"); lua_setglobal(L, "surf");
lua_newtable(L); lua_newtable(L);
lua_pushcfunction(L,cpp_map_new); lua_setfield(L, -2, "new"); //lua_pushcfunction(L,cpp_map_new); lua_setfield(L, -2, "new");
lua_pushcfunction(L,cpp_map_load); lua_setfield(L, -2, "load"); //lua_pushcfunction(L,cpp_map_load); lua_setfield(L, -2, "load");
lua_pushcfunction(L,cpp_map_save); lua_setfield(L, -2, "save"); //lua_pushcfunction(L,cpp_map_save); lua_setfield(L, -2, "save");
lua_pushcfunction(L,cpp_map_set); lua_setfield(L, -2, "set"); lua_pushcfunction(L,cpp_map_surf); lua_setfield(L, -2, "surf");
lua_pushcfunction(L,cpp_map_draw); lua_setfield(L, -2, "draw"); lua_pushcfunction(L,cpp_map_draw); lua_setfield(L, -2, "draw");
lua_pushcfunction(L,cpp_map_tile); lua_setfield(L, -2, "tile"); lua_pushcfunction(L,cpp_map_tile); lua_setfield(L, -2, "tile");
lua_setglobal(L, "map"); lua_setglobal(L, "map");

View File

@@ -4,7 +4,6 @@
#include "lua.h" #include "lua.h"
#include "gif.h" #include "gif.h"
#include "gifenc.h" #include "gifenc.h"
//#include "SDL2/SDL_mixer.h"
#include "jail_audio.h" #include "jail_audio.h"
#define MAX_TEXTURES 100 #define MAX_TEXTURES 100

View File

@@ -1,3 +1,3 @@
#pragma once #pragma once
#define MINI_VERSION "1.0.1" #define MINI_VERSION "1.1"

View File

@@ -62,22 +62,13 @@ function surf.pixel(x, y, color) end
---@class map ---@class map
map = {} map = {}
---@param w number ---@return number surface
---@param h number ---Get tilemaps current surface
---Create new map specifying width and height function map.surf() end
function map.new(w, h) end
---@param filename string
---Load a tilemap from a file and set it as current tilemap
function map.load(filename) end
---@param filename string
---Save the current tilemap in a file
function map.save(filename) end
---@param surface number ---@param surface number
---Set surface as the current tilemap ---Set surface as the current tilemap
function map.set(surface) end function map.surf(surface) end
---Draw the tilemap, using the source surface as tile graphics source ---Draw the tilemap, using the source surface as tile graphics source
function map.draw() end function map.draw() end