- [CHG] Intercanviats botons de botar i disparar
- [NEW] cheats.showaabb - [CHG] retocs en score - [NEW] Autocompletar en la consola
This commit is contained in:
116
data/console.lua
116
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 = {
|
console = {
|
||||||
command = "",
|
command = "",
|
||||||
history = {},
|
history = {},
|
||||||
history_pos = 0,
|
history_pos = 0,
|
||||||
cursor = 50,
|
cursor = 50,
|
||||||
|
autocomplete_list = {},
|
||||||
|
autocomplete_prefix = "",
|
||||||
|
autocomplete_index = 1,
|
||||||
|
|
||||||
enable = function()
|
enable = function()
|
||||||
app.push(console.update)
|
app.push(console.update)
|
||||||
@@ -15,6 +85,20 @@ console = {
|
|||||||
draw.rrect(0, 92, 160, 108, 4, 13)
|
draw.rrect(0, 92, 160, 108, 4, 13)
|
||||||
draw.text(">", 2, 96, 13)
|
draw.text(">", 2, 96, 13)
|
||||||
draw.text(console.command, 6, 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
|
if console.cursor > 24 then
|
||||||
draw.text("_", 6+#console.command*4, 96, 13)
|
draw.text("_", 6+#console.command*4, 96, 13)
|
||||||
end
|
end
|
||||||
@@ -26,18 +110,23 @@ console = {
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local should_update = false
|
||||||
|
|
||||||
if #console.history>0 then
|
if #console.history>0 then
|
||||||
if key.press(key.UP) and console.history_pos > 1 then
|
if key.press(key.UP) and console.history_pos > 1 then
|
||||||
console.history_pos = console.history_pos - 1
|
console.history_pos = console.history_pos - 1
|
||||||
console.command = console.history[console.history_pos]
|
console.command = console.history[console.history_pos]
|
||||||
|
should_update = true
|
||||||
elseif key.press(key.DOWN) and console.history_pos < #console.history then
|
elseif key.press(key.DOWN) and console.history_pos < #console.history then
|
||||||
console.history_pos = console.history_pos + 1
|
console.history_pos = console.history_pos + 1
|
||||||
console.command = console.history[console.history_pos]
|
console.command = console.history[console.history_pos]
|
||||||
|
should_update = true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local k = key.press()
|
local k = key.press()
|
||||||
if k ~= key.UNKNOWN then
|
if k ~= key.UNKNOWN then
|
||||||
|
should_update = true
|
||||||
if k >= key.A and k <= key.Z then
|
if k >= key.A and k <= key.Z then
|
||||||
if key.down(key.LSHIFT) or key.down(key.RSHIFT) then
|
if key.down(key.LSHIFT) or key.down(key.RSHIFT) then
|
||||||
console.command = console.command .. string.char(k+61)
|
console.command = console.command .. string.char(k+61)
|
||||||
@@ -229,6 +318,11 @@ console = {
|
|||||||
console.command = console.command .. ' '
|
console.command = console.command .. ' '
|
||||||
elseif k == key.BACKSPACE then
|
elseif k == key.BACKSPACE then
|
||||||
console.command = console.command:sub(1, #console.command - 1)
|
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
|
elseif k == key.RETURN then
|
||||||
table.insert(console.history, console.command)
|
table.insert(console.history, console.command)
|
||||||
console.history_pos = #console.history+1
|
console.history_pos = #console.history+1
|
||||||
@@ -242,6 +336,28 @@ console = {
|
|||||||
end
|
end
|
||||||
|
|
||||||
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("<buit>"..":".."golbal")
|
||||||
|
--print(#console.autocomplete_list)
|
||||||
|
end
|
||||||
|
end
|
||||||
end,
|
end,
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -7,6 +7,8 @@ function test()
|
|||||||
tweening.add(0, 1, 1, easing.easeOutCubic, function(value, progress, finished) palfade.fade_reddish(value) end)
|
tweening.add(0, 1, 1, easing.easeOutCubic, function(value, progress, finished) palfade.fade_reddish(value) end)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
cheats = {}
|
||||||
|
|
||||||
game = {
|
game = {
|
||||||
chg_adv = {x=0, y=0},
|
chg_adv = {x=0, y=0},
|
||||||
chg_step = 0,
|
chg_step = 0,
|
||||||
@@ -29,6 +31,7 @@ game = {
|
|||||||
app.update = game.update
|
app.update = game.update
|
||||||
sys.beat(2)
|
sys.beat(2)
|
||||||
palfade.init()
|
palfade.init()
|
||||||
|
score.init()
|
||||||
--palfade.fade_reddish(0.5)
|
--palfade.fade_reddish(0.5)
|
||||||
--shader.enable();
|
--shader.enable();
|
||||||
end,
|
end,
|
||||||
|
|||||||
@@ -1,7 +1,20 @@
|
|||||||
score = {
|
score = {
|
||||||
points = 0,
|
points = 0,
|
||||||
|
color = 28,
|
||||||
|
zoom = 1,
|
||||||
|
|
||||||
|
init = function()
|
||||||
|
score.points = 0
|
||||||
|
end,
|
||||||
|
|
||||||
draw = function()
|
draw = function()
|
||||||
draw.rectf(0,0,160,8,1)
|
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
|
end
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -207,7 +207,7 @@ sprites = {
|
|||||||
spr.pos.y=spr.pos.y-16
|
spr.pos.y=spr.pos.y-16
|
||||||
spr.pos.x=spr.pos.x-4
|
spr.pos.x=spr.pos.x-4
|
||||||
spr.timer = 0
|
spr.timer = 0
|
||||||
score.points = score.points + 10
|
score.inc(10)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
--end
|
--end
|
||||||
@@ -316,11 +316,11 @@ sprites = {
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
-- SI POLSA BOTAR...
|
-- 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
|
sprites.hero.jumping = 17
|
||||||
|
|
||||||
-- SI POLSA DISPAR...
|
-- 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.shooting = true
|
||||||
sprites.hero.cooldown = 20
|
sprites.hero.cooldown = 20
|
||||||
local x = sprites.hero.flipped and sprites.hero.pos.x+8 or sprites.hero.pos.x-8
|
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
|
local reversed = frame.reversed or false
|
||||||
surf.source(sprite.surf)
|
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))
|
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)
|
if cheats.showaabb then
|
||||||
--draw.rect(x,y,w,h,8)
|
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
|
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)
|
game.draw_light(sprite.pos.x+sprite.light_ox, sprite.pos.y+sprite.light_oy,sprite.light)
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user