feat(P.3.6): selection demo — 6 stones + click/box-select wiring
- camera dep 0.2.0 → 0.3.0 (screen_to_world consumer) - selection dep 0.1.0 added - 6 stones registered as selectables - selection.update + render_highlights + render_drag_box wired - input: lmb + mod_add (shift) + mod_toggle (ctrl)
This commit is contained in:
56
init.lua
56
init.lua
@@ -4,6 +4,7 @@ local camera = require("lib-core.camera")
|
||||
local input = require("lib-core.input")
|
||||
local player = require("lib-core.player_control")
|
||||
local interaction = require("lib-core.interaction")
|
||||
local selection = require("lib-core.selection")
|
||||
|
||||
local demo_map = maps.load("maps/demo.map.json")
|
||||
maps.set_current(demo_map)
|
||||
@@ -31,6 +32,14 @@ input.bind("pan_left", { "a", "left" })
|
||||
input.bind("pan_right", { "d", "right" })
|
||||
input.bind("pan_up", { "w", "up" })
|
||||
input.bind("pan_down", { "s", "down" })
|
||||
-- P.3.6: Selection bindings
|
||||
input.bind("lmb", { "mouse_left" })
|
||||
input.bind("mod_add", { "shift" })
|
||||
input.bind("mod_toggle", { "ctrl" })
|
||||
|
||||
selection.bind_action("lmb")
|
||||
selection.bind_modifier_add("mod_add")
|
||||
selection.bind_modifier_toggle("mod_toggle")
|
||||
|
||||
camera.bind_pan_keys("pan_left", "pan_right", "pan_up", "pan_down")
|
||||
camera.bind_pan_drag("pan_drag")
|
||||
@@ -51,6 +60,17 @@ local PLAYER_R, PLAYER_G, PLAYER_B = 200, 60, 80
|
||||
local sign = { x = 144, y = 144, text = "Hier steht: Willkommen im Spine." }
|
||||
local SIGN_R, SIGN_G, SIGN_B = 220, 200, 60
|
||||
|
||||
-- P.3.6: 6 stones as selectables (demo for click/box-select + modifiers).
|
||||
-- Positions distributed across walkable map area; sizes uniform 20×20.
|
||||
local stones = {
|
||||
{ x = 64, y = 96, w = 20, h = 20, color = {120, 120, 140} },
|
||||
{ x = 224, y = 96, w = 20, h = 20, color = {120, 120, 140} },
|
||||
{ x = 96, y = 256, w = 20, h = 20, color = {130, 110, 100} },
|
||||
{ x = 320, y = 192, w = 20, h = 20, color = {130, 110, 100} },
|
||||
{ x = 192, y = 320, w = 20, h = 20, color = {140, 130, 110} },
|
||||
{ x = 384, y = 256, w = 20, h = 20, color = {140, 130, 110} },
|
||||
}
|
||||
|
||||
-- P.3.5: Free-Cam-Mode state
|
||||
local free_cam_mode = false
|
||||
|
||||
@@ -80,21 +100,38 @@ function init(ctx)
|
||||
end)
|
||||
engine.print(string.format("interaction: %d trigger(s) registered",
|
||||
interaction.trigger_count()))
|
||||
-- P.3.6: Register each stone as selectable.
|
||||
for _, s in ipairs(stones) do
|
||||
s.sel_handle = selection.register(function()
|
||||
return { x = s.x, y = s.y, w = s.w, h = s.h }
|
||||
end)
|
||||
end
|
||||
engine.print(string.format("selection: %d selectables registered",
|
||||
selection.count_registered()))
|
||||
end
|
||||
|
||||
function render(ctx)
|
||||
engine.render.clear_color(engine.render.rgb(20, 20, 30))
|
||||
camera.begin()
|
||||
r_lib.draw_map()
|
||||
-- draw sign on top of map
|
||||
engine.render.draw_rect(sign.x - 6, sign.y - 6, 12, 12,
|
||||
engine.render.rgb(SIGN_R, SIGN_G, SIGN_B))
|
||||
-- draw player on top of sign
|
||||
local p = player.position()
|
||||
local s = player.size()
|
||||
engine.render.draw_rect(p.x, p.y, s.w, s.h,
|
||||
engine.render.rgb(PLAYER_R, PLAYER_G, PLAYER_B))
|
||||
r_lib.draw_map()
|
||||
-- draw sign on top of map
|
||||
engine.render.draw_rect(sign.x - 6, sign.y - 6, 12, 12,
|
||||
engine.render.rgb(SIGN_R, SIGN_G, SIGN_B))
|
||||
-- P.3.6: draw stones
|
||||
for _, s in ipairs(stones) do
|
||||
engine.render.draw_rect(s.x, s.y, s.w, s.h,
|
||||
engine.render.rgb(s.color[1], s.color[2], s.color[3]))
|
||||
end
|
||||
-- draw player on top of map/stones
|
||||
local p = player.position()
|
||||
local sz = player.size()
|
||||
engine.render.draw_rect(p.x, p.y, sz.w, sz.h,
|
||||
engine.render.rgb(PLAYER_R, PLAYER_G, PLAYER_B))
|
||||
-- P.3.6: highlights over selected entities (world-space)
|
||||
selection.render_highlights()
|
||||
camera.finish()
|
||||
-- P.3.6: drag-box overlay (screen-space, after camera.finish)
|
||||
selection.render_drag_box()
|
||||
end
|
||||
|
||||
function update(ctx, dt)
|
||||
@@ -120,6 +157,7 @@ function update(ctx, dt)
|
||||
|
||||
-- Pan-Summation jeden Frame (keys nur wenn enabled; drag + edge always-on).
|
||||
camera.update(dt)
|
||||
selection.update(dt)
|
||||
|
||||
if not free_cam_mode then
|
||||
-- Follow-cam: set_target jeden Frame -> drag/edge "drift" wird unsichtbar.
|
||||
|
||||
Reference in New Issue
Block a user