feat(P.3.7): selection-to-command demo — RMB-to-move with 3 speed classes
- lib-core.command 0.1.0 dep added - 6 stones gain speed (100/150/200 px/s pairs) - RMB → move selected stones (target_provider = selection.list) - command.update(dt) after selection.update(dt)
This commit is contained in:
32
init.lua
32
init.lua
@@ -5,6 +5,7 @@ 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 command = require("lib-core.command")
|
||||
|
||||
local demo_map = maps.load("maps/demo.map.json")
|
||||
maps.set_current(demo_map)
|
||||
@@ -41,6 +42,12 @@ selection.bind_action("lmb")
|
||||
selection.bind_modifier_add("mod_add")
|
||||
selection.bind_modifier_toggle("mod_toggle")
|
||||
|
||||
-- P.3.7: Command bindings (RMB → move selected units).
|
||||
input.bind("rmb", { "mouse_right" })
|
||||
|
||||
command.bind_move_action("rmb")
|
||||
command.bind_target_provider(function() return selection.list() end)
|
||||
|
||||
camera.bind_pan_keys("pan_left", "pan_right", "pan_up", "pan_down")
|
||||
camera.bind_pan_drag("pan_drag")
|
||||
camera.enable_pan_edge()
|
||||
@@ -60,15 +67,14 @@ 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.
|
||||
-- P.3.6/P.3.7: 6 stones as selectables + movable units (3 speed classes).
|
||||
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} },
|
||||
{ x = 64, y = 96, w = 20, h = 20, color = {120, 120, 140}, speed = 100 },
|
||||
{ x = 224, y = 96, w = 20, h = 20, color = {120, 120, 140}, speed = 100 },
|
||||
{ x = 96, y = 256, w = 20, h = 20, color = {130, 110, 100}, speed = 150 },
|
||||
{ x = 320, y = 192, w = 20, h = 20, color = {130, 110, 100}, speed = 150 },
|
||||
{ x = 192, y = 320, w = 20, h = 20, color = {140, 130, 110}, speed = 200 },
|
||||
{ x = 384, y = 256, w = 20, h = 20, color = {140, 130, 110}, speed = 200 },
|
||||
}
|
||||
|
||||
-- P.3.5: Free-Cam-Mode state
|
||||
@@ -100,14 +106,21 @@ function init(ctx)
|
||||
end)
|
||||
engine.print(string.format("interaction: %d trigger(s) registered",
|
||||
interaction.trigger_count()))
|
||||
-- P.3.6: Register each stone as selectable.
|
||||
-- P.3.6/P.3.7: Register each stone as selectable AND movable.
|
||||
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)
|
||||
s.cmd_handle = command.register(
|
||||
function() return { x = s.x, y = s.y } end,
|
||||
function(nx, ny) s.x = nx; s.y = ny end,
|
||||
s.speed
|
||||
)
|
||||
end
|
||||
engine.print(string.format("selection: %d selectables registered",
|
||||
selection.count_registered()))
|
||||
engine.print(string.format("command: %d movable units registered",
|
||||
command.count_registered()))
|
||||
end
|
||||
|
||||
function render(ctx)
|
||||
@@ -158,6 +171,7 @@ function update(ctx, dt)
|
||||
-- Pan-Summation jeden Frame (keys nur wenn enabled; drag + edge always-on).
|
||||
camera.update(dt)
|
||||
selection.update(dt)
|
||||
command.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