From a7fb3d5c22f7312fa96c45bfec982e594a306121 Mon Sep 17 00:00:00 2001 From: Raimon Zamora Date: Tue, 24 Feb 2026 22:17:46 +0100 Subject: [PATCH] - [CHG] Intercanviats botons de botar i disparar - [NEW] cheats.showaabb - [CHG] retocs en score - [NEW] Autocompletar en la consola --- data/console.lua | 116 +++++++++++++++++++++++++++++++++++++++++++++++ data/game.lua | 3 ++ data/score.lua | 15 +++++- data/sprites.lua | 12 +++-- 4 files changed, 140 insertions(+), 6 deletions(-) diff --git a/data/console.lua b/data/console.lua index 4ac91a5..7f7e73f 100644 --- a/data/console.lua +++ b/data/console.lua @@ -1,8 +1,78 @@ +local separators = " ()[],-+*/=<>" + +local function split_by_last_separator(s) + for i = #s, 1, -1 do + local c = s:sub(i, i) + if separators:find(c, 1, true) then + if i == #s then + -- Separador al final + return s, "" + end + -- Separador en medio + return s:sub(1, i), s:sub(i + 1) + end + end + -- Sin separadores + return "", s +end + +local function split_by_last_dot(s) + local last = s:match(".*()%.") -- devuelve la posición DESPUÉS del último punto + + if not last then + -- No hay puntos: primera parte = cadena completa, segunda = "" + return "", s + end + + -- Si el punto está al final, la segunda parte es "" + if last > #s then + return s, "" + end + + -- Primera parte incluye el punto + local first = s:sub(1, last - 1) + local second = s:sub(last+1) + + return first, second +end + +function get_by_path(path) + local current = _G + + for segment in path:gmatch("[^%.]+") do + if type(current) ~= "table" then + return nil + end + current = current[segment] + if current == nil then + --print("get_by_path: " ..segment.." es nil") + return nil + end + end + + --print("get_by_path: ok") + return current +end + +function entries_starting_with(s, t) + if not t then return nil end + local result = {} + for k, v in pairs(t) do + if type(k) == "string" and k:sub(1, #s) == s then + result[#result+1] = k + end + end + return result +end + console = { command = "", history = {}, history_pos = 0, cursor = 50, + autocomplete_list = {}, + autocomplete_prefix = "", + autocomplete_index = 1, enable = function() app.push(console.update) @@ -15,6 +85,20 @@ console = { draw.rrect(0, 92, 160, 108, 4, 13) draw.text(">", 2, 96, 13) draw.text(console.command, 6, 96, 13) + + if console.autocomplete_list and #console.autocomplete_list>0 then + --local num = math.min(5, #console.autocomplete_list) + --local base_y = 92-num*7 + --draw.rectf(3+#console.command*4, base_y, 80, num*7, 1) + --draw.rect(3+#console.command*4, base_y, 80, num*7, 13) + --for i=1,num do + -- draw.text(console.autocomplete_list[i], 6+#console.command*4, base_y+i*7, 13) + --end + + local sufix = console.autocomplete_list[console.autocomplete_index]:sub(#console.autocomplete_prefix+1) + draw.text(sufix, 6+#console.command*4, 96, 6) + end + if console.cursor > 24 then draw.text("_", 6+#console.command*4, 96, 13) end @@ -26,18 +110,23 @@ console = { return end + local should_update = false + if #console.history>0 then if key.press(key.UP) and console.history_pos > 1 then console.history_pos = console.history_pos - 1 console.command = console.history[console.history_pos] + should_update = true elseif key.press(key.DOWN) and console.history_pos < #console.history then console.history_pos = console.history_pos + 1 console.command = console.history[console.history_pos] + should_update = true end end local k = key.press() if k ~= key.UNKNOWN then + should_update = true if k >= key.A and k <= key.Z then if key.down(key.LSHIFT) or key.down(key.RSHIFT) then console.command = console.command .. string.char(k+61) @@ -229,6 +318,11 @@ console = { console.command = console.command .. ' ' elseif k == key.BACKSPACE then console.command = console.command:sub(1, #console.command - 1) + + elseif k == key.TAB then + local sufix = console.autocomplete_list[console.autocomplete_index]:sub(#console.autocomplete_prefix+1) + console.command = console.command .. sufix + elseif k == key.RETURN then table.insert(console.history, console.command) console.history_pos = #console.history+1 @@ -242,6 +336,28 @@ console = { end end + + if should_update then + local a, b = split_by_last_separator(console.command) + if b ~= "" then + local ba, bb = split_by_last_dot(b) + console.autocomplete_prefix = bb + if ba ~= "" then + console.autocomplete_list = entries_starting_with(bb, get_by_path(ba)) + --print(bb..":"..ba) + --print(#console.autocomplete_list) + else + console.autocomplete_list = entries_starting_with(bb, _G) + --print(bb..":".."golbal") + --print(#console.autocomplete_list) + end + else + console.autocomplete_prefix = "" + console.autocomplete_list = entries_starting_with("", _G) + --print(""..":".."golbal") + --print(#console.autocomplete_list) + end + end end, } \ No newline at end of file diff --git a/data/game.lua b/data/game.lua index fc3298f..4e2bff8 100644 --- a/data/game.lua +++ b/data/game.lua @@ -7,6 +7,8 @@ function test() tweening.add(0, 1, 1, easing.easeOutCubic, function(value, progress, finished) palfade.fade_reddish(value) end) end +cheats = {} + game = { chg_adv = {x=0, y=0}, chg_step = 0, @@ -29,6 +31,7 @@ game = { app.update = game.update sys.beat(2) palfade.init() + score.init() --palfade.fade_reddish(0.5) --shader.enable(); end, diff --git a/data/score.lua b/data/score.lua index c4bd779..c8be7d8 100644 --- a/data/score.lua +++ b/data/score.lua @@ -1,7 +1,20 @@ score = { points = 0, + color = 28, + zoom = 1, + + init = function() + score.points = 0 + end, + draw = function() draw.rectf(0,0,160,8,1) - draw.text(string.format("%03d", score.points),0,0,28) + draw.text(string.format("%03d", score.points),0,0,score.color) + end, + + inc = function(value) + print("score.inc()") + score.points = score.points + value + tweening.add(8, 0, 0.5, easing.linear, function(val,progress,finished) score.color = (math.floor(val)&1) == 0 and 28 or 14 end) end } diff --git a/data/sprites.lua b/data/sprites.lua index 23694d0..012bf75 100644 --- a/data/sprites.lua +++ b/data/sprites.lua @@ -207,7 +207,7 @@ sprites = { spr.pos.y=spr.pos.y-16 spr.pos.x=spr.pos.x-4 spr.timer = 0 - score.points = score.points + 10 + score.inc(10) return end --end @@ -316,11 +316,11 @@ sprites = { end end -- SI POLSA BOTAR... - if key.down(key.Z) or pad.down(pad.A) then + if key.down(key.X) or pad.down(pad.A) then sprites.hero.jumping = 17 -- SI POLSA DISPAR... - elseif (sprites.hero.cooldown==0) and (key.down(key.X) or pad.down(pad.B)) then + elseif (sprites.hero.cooldown==0) and (key.down(key.Z) or pad.down(pad.B)) then sprites.hero.shooting = true sprites.hero.cooldown = 20 local x = sprites.hero.flipped and sprites.hero.pos.x+8 or sprites.hero.pos.x-8 @@ -391,8 +391,10 @@ sprites = { local reversed = frame.reversed or false surf.source(sprite.surf) draw.surf(frame.frame.x, frame.frame.y, frame.frame.w, frame.frame.h, sprite.pos.x, sprite.pos.y, frame.frame.w, frame.frame.h, (not reversed) ~= (not sprite.flipped)) - --local x,y,w,h = util.aabb(sprite) - --draw.rect(x,y,w,h,8) + if cheats.showaabb then + local x,y,w,h = util.aabb(sprite) + draw.rect(x,y,w,h,8) + end if (app.update ~= editor.update) and (sprite.light) then game.draw_light(sprite.pos.x+sprite.light_ox, sprite.pos.y+sprite.light_oy,sprite.light) end