feat(vagrant): rock template gains player-facing properties
Rock template now declares name="Rock", a description, weight (kg), volume (L), and composition.stone=1.0. The module-side label_resolver override is removed — display lib's default reads name now. Inspect action prints a structured block (name, description, weight, volume, composition.<material>, reg_id) to the console. Future notification system will route this to an in-game text panel; for now the console output makes Inspect useful instead of silent.
This commit is contained in:
49
init.lua
49
init.lua
@@ -1,4 +1,4 @@
|
||||
-- sporel-module-vagrant-skeleton v0.9.0
|
||||
-- sporel-module-vagrant-skeleton v0.9.1
|
||||
-- Sprite-mode test-chamber: 13-bone humanoid puppet + sprite-tilemap +
|
||||
-- hardcoded furniture. Subterrain-style puppet control model:
|
||||
-- multi-look-target (aim/soft), slerp body rotation, hip-static legs,
|
||||
@@ -27,6 +27,13 @@
|
||||
-- showing backpack contents. Right-click on an item row opens a context
|
||||
-- menu with Drop and Inspect actions. Q-drop (LIFO quick-drop) remains
|
||||
-- available in parallel.
|
||||
--
|
||||
-- v0.9.1: Rock template gains player-facing properties (name,
|
||||
-- description, weight, volume, composition.stone). Inspect prints the
|
||||
-- name+description+weight+composition block to the console; future
|
||||
-- notification system will route this to an in-game text panel. Module-
|
||||
-- side label_resolver override removed — default_label_resolver reads
|
||||
-- the `name` property.
|
||||
|
||||
local input = require("lib-core.input")
|
||||
local camera = require("lib-core.camera")
|
||||
@@ -81,6 +88,14 @@ composition.define_template{
|
||||
id = "rock",
|
||||
properties = {
|
||||
stack_mode = "individual", -- required by inventory-list
|
||||
-- Player-facing properties (item-template-convention v0.x):
|
||||
name = "Rock", -- shown by inventory display
|
||||
description = "A heavy stone. Could be useful for crafting.",
|
||||
weight = 2.5, -- kg (real units)
|
||||
volume = 0.001, -- L (real units)
|
||||
-- Material composition (composition-model.md §4 — 0-1 platonic;
|
||||
-- 1.0 = pure stone). Phase E (property-driven recipes) reads this.
|
||||
["composition.stone"] = 1.0,
|
||||
sprite_atlas = "",
|
||||
sprite_uv = {x = 0, y = 0, w = 1, h = 1},
|
||||
position = {x = 0, y = 0},
|
||||
@@ -405,11 +420,8 @@ function M.init(ctx)
|
||||
pause_on_open = false,
|
||||
})
|
||||
|
||||
-- Module-side label-resolver (display lib's default returns "Item").
|
||||
-- Vagrant currently has one item template (rock); hardcoded for v0.9.
|
||||
inv_display.set_label_resolver(backpack_widget, function(item)
|
||||
return "Rock"
|
||||
end)
|
||||
-- Default label_resolver reads `name` property from the item-template
|
||||
-- (set on the rock template above). No override needed in v0.9.1.
|
||||
|
||||
-- Drop action: knows world-reparenting + player position
|
||||
inv_display.register_action(backpack_widget, "Drop", function(item, c)
|
||||
@@ -423,9 +435,30 @@ function M.init(ctx)
|
||||
if CI_FRAME_PERF then engine.print("vagrant: event=drop_via_menu") end
|
||||
end)
|
||||
|
||||
-- Inspect action: dumps reg_id to console
|
||||
-- Inspect action: prints player-facing item info to console. Future
|
||||
-- notification-system (lib-core.toast or similar) will route this to
|
||||
-- an in-game text panel instead of engine.print.
|
||||
inv_display.register_action(backpack_widget, "Inspect", function(item, c)
|
||||
engine.print(string.format("vagrant: inspect: reg_id=%s",
|
||||
local name = item:get_property("name") or "(unnamed)"
|
||||
local description = item:get_property("description") or ""
|
||||
local weight = item:get_property("weight") or 0
|
||||
local volume = item:get_property("volume") or 0
|
||||
engine.print(string.format("=== %s ===", name))
|
||||
if description ~= "" then engine.print(description) end
|
||||
engine.print(string.format("weight=%.2fkg volume=%.3fL", weight, volume))
|
||||
-- Surface material composition by iterating composition.* properties.
|
||||
local props = item:get_properties()
|
||||
local mats = {}
|
||||
for k, v in pairs(props) do
|
||||
local mat = k:match("^composition%.(.+)$")
|
||||
if mat and mat ~= "reg_id" then
|
||||
table.insert(mats, string.format("%s=%.2f", mat, v))
|
||||
end
|
||||
end
|
||||
if #mats > 0 then
|
||||
engine.print("composition: " .. table.concat(mats, " "))
|
||||
end
|
||||
engine.print(string.format("(reg_id=%s)",
|
||||
tostring(item:get_property("composition.reg_id"))))
|
||||
c.close_menu()
|
||||
end)
|
||||
|
||||
Reference in New Issue
Block a user