1
0
mirror of https://github.com/pandorabox-io/banners.git synced 2025-01-06 16:10:32 +01:00

whitespace and minetest. -> core.

- use same whitespace style throughout and fix some indents.
- change from minetest. to core. namespace.
This commit is contained in:
Luke aka SwissalpS 2024-11-27 22:32:24 +01:00
parent 283b5bec25
commit c8012c7266
6 changed files with 534 additions and 528 deletions

View File

@ -1,78 +1,73 @@
-- craft recipes -- craft recipes
minetest.register_craft( -- wooden flag pole
{
output = "banners:wooden_pole 1",
recipe = {
{"", "", "default:stick"},
{"", "default:stick", ""},
{"default:stick", "", ""}
}
}
)
minetest.register_craft( -- steel flag pole -- wooden flag pole
{ core.register_craft({
output = "banners:steel_pole 1", output = "banners:wooden_pole 1",
recipe = { recipe = {
{"", "", "default:steel_ingot"}, { "", "", "default:stick" },
{"default:stick", "default:steel_ingot", "default:stick"}, { "", "default:stick", "" },
{"default:steel_ingot", "", ""} { "default:stick", "", "" }
}
} }
) })
minetest.register_craft( -- wooden flag support base -- steel flag pole
{ core.register_craft({
output = "banners:wooden_base 1", output = "banners:steel_pole 1",
recipe = { recipe = {
{"", "default:stick", ""}, { "", "", "default:steel_ingot" },
{"default:stick", "", "default:stick"}, { "default:stick", "default:steel_ingot", "default:stick" },
{"group:wood", "group:wood", "group:wood"} { "default:steel_ingot", "", "" }
}
} }
) })
minetest.register_craft( -- steel support -- wooden flag support base
{ core.register_craft({
output = "banners:steel_base", output = "banners:wooden_base 1",
recipe = { recipe = {
{"", "default:steel_ingot", ""}, { "", "default:stick", "" },
{"default:steel_ingot", "", "default:steel_ingot"}, { "default:stick", "", "default:stick" },
{"", "default:steelblock", ""} { "group:wood", "group:wood", "group:wood" }
}
} }
) })
minetest.register_craft( -- banner sheet -- steel support
{ core.register_craft({
output = "banners:banner_sheet 1", output = "banners:steel_base",
recipe = { recipe = {
{"", "", ""}, { "", "default:steel_ingot", "" },
{"farming:cotton", "farming:cotton", "farming:cotton"}, { "default:steel_ingot", "", "default:steel_ingot" },
{"farming:cotton", "farming:cotton", "farming:cotton"} { "", "default:steelblock", "" }
}
} }
) })
minetest.register_craft( -- wooden support -- banner sheet
{ core.register_craft({
output = "banners:wooden_banner 1", output = "banners:banner_sheet 1",
recipe = { recipe = {
{"", "banners:banner_sheet", ""}, { "", "", "" },
{"", "banners:wooden_pole", ""}, { "farming:cotton", "farming:cotton", "farming:cotton" },
{"", "banners:wooden_base", ""} { "farming:cotton", "farming:cotton", "farming:cotton" }
}
} }
) })
minetest.register_craft( -- steel support -- wooden support
{ core.register_craft({
output = "banners:steel_banner 1", output = "banners:wooden_banner 1",
recipe = { recipe = {
{"", "banners:banner_sheet", ""}, { "", "banners:banner_sheet", "" },
{"", "banners:steel_pole", ""}, { "", "banners:wooden_pole", "" },
{"", "banners:steel_base", ""} { "", "banners:wooden_base", "" }
}
} }
) })
-- steel support
core.register_craft({
output = "banners:steel_banner 1",
recipe = {
{ "", "banners:banner_sheet", "" },
{ "", "banners:steel_pole", "" },
{ "", "banners:steel_base", "" }
}
})

View File

@ -1,43 +1,43 @@
banners.power_per_banner = 10. banners.power_per_banner = 10.
-- items -- items
minetest.register_craftitem("banners:golden_finial", { core.register_craftitem("banners:golden_finial", {
groups = {}, groups = {},
description = "Golden finial", description = "Golden finial",
inventory_image = "gold_finial.png", inventory_image = "gold_finial.png",
}) })
minetest.register_craftitem("banners:silver_pole", { core.register_craftitem("banners:silver_pole", {
groups = {}, groups = {},
description = "Silver pole", description = "Silver pole",
inventory_image = "silver_pole.png" inventory_image = "silver_pole.png"
}) })
minetest.register_craftitem("banners:power_pole", { core.register_craftitem("banners:power_pole", {
groups = {}, groups = {},
description = "Power pole", description = "Power pole",
inventory_image = "power_pole.png" inventory_image = "power_pole.png"
}) })
minetest.register_craftitem("banners:golden_sheet", { core.register_craftitem("banners:golden_sheet", {
groups = {}, groups = {},
description = "Golden sheet", description = "Golden sheet",
inventory_image = "golden_sheet.png" inventory_image = "golden_sheet.png"
}) })
minetest.register_craftitem("banners:death_pole", { core.register_craftitem("banners:death_pole", {
groups = {}, groups = {},
description = "Death pole", description = "Death pole",
inventory_image = "death_pole.png" inventory_image = "death_pole.png"
}) })
minetest.register_craftitem("banners:death_sheet", { core.register_craftitem("banners:death_sheet", {
groups = {}, groups = {},
description = "Death sheet", description = "Death sheet",
inventory_image = "death_sheet.png" inventory_image = "death_sheet.png"
}) })
minetest.register_craftitem("banners:death_base", { core.register_craftitem("banners:death_base", {
groups = {}, groups = {},
description = "Death base", description = "Death base",
inventory_image = "death_base.png" inventory_image = "death_base.png"
@ -46,107 +46,98 @@ minetest.register_craftitem("banners:death_base", {
-- crafts -- crafts
minetest.register_craft( -- silver flag pole -- silver flag pole
{ core.register_craft({
output = "banners:silver_pole 1", output = "banners:silver_pole 1",
recipe = { recipe = {
{"", "", "moreores:silver_ingot"}, { "", "", "moreores:silver_ingot" },
{"", "moreores:silver_ingot", ""}, { "", "moreores:silver_ingot", "" },
{"moreores:silver_ingot", "", ""} { "moreores:silver_ingot", "", "" }
}
} }
) })
minetest.register_craft( -- death flag pole -- death flag pole
{ core.register_craft({
output = "banners:death_pole 1", output = "banners:death_pole 1",
recipe = { recipe = {
{"", "", "default:diamond"}, { "", "", "default:diamond" },
{"", "default:obsidian", ""}, { "", "default:obsidian", "" },
{"default:obsidian", "", ""} { "default:obsidian", "", "" }
}
} }
) })
minetest.register_craft( -- golden finial -- golden finial
{ core.register_craft({
output = "banners:golden_finial", output = "banners:golden_finial",
recipe = { recipe = {
{"", "default:gold_ingot", "default:gold_ingot"}, { "", "default:gold_ingot", "default:gold_ingot" },
{"", "default:gold_ingot", "default:gold_ingot"}, { "", "default:gold_ingot", "default:gold_ingot" },
{"default:gold_ingot", "", ""} { "default:gold_ingot", "", "" }
}
} }
) })
minetest.register_craft( -- power flag pole -- power flag pole
{ core.register_craft({
output = "banners:power_pole 1", output = "banners:power_pole 1",
recipe = { recipe = {
{"", "", ""}, { "", "", "" },
{"", "banners:golden_finial", ""}, { "", "banners:golden_finial", "" },
{"banners:silver_pole", "", ""} { "banners:silver_pole", "", "" }
}
} }
) })
minetest.register_craft( -- golden sheet -- golden sheet
{ core.register_craft({
output = "banners:golden_sheet 1", output = "banners:golden_sheet 1",
type = "shapeless", type = "shapeless",
recipe = { "default:gold_ingot", "banners:banner_sheet"} recipe = { "default:gold_ingot", "banners:banner_sheet" }
} })
)
minetest.register_craft( -- death sheet -- death sheet
{ core.register_craft({
output = "banners:death_sheet 1", output = "banners:death_sheet 1",
type = "shapeless", type = "shapeless",
recipe = { "default:obsidian", "banners:banner_sheet"} recipe = { "default:obsidian", "banners:banner_sheet" }
} })
)
minetest.register_craft( -- death sheet -- death sheet
{ core.register_craft({
output = "banners:death_base 1", output = "banners:death_base 1",
recipe = { recipe = {
{"", "", ""}, { "", "", "" },
{"", "banners:steel_base", ""}, { "", "banners:steel_base", "" },
{"default:obsidian", "default:obsidian", "default:obsidian"} { "default:obsidian", "default:obsidian", "default:obsidian" }
}
} }
) })
minetest.register_craft( -- power banner -- power banner
{ core.register_craft({
output = "banners:power_banner", output = "banners:power_banner",
recipe = { recipe = {
{"", "banners:golden_sheet", ""}, { "", "banners:golden_sheet", "" },
{"", "banners:power_pole", ""}, { "", "banners:power_pole", "" },
{"", "banners:steel_base", ""} { "", "banners:steel_base", "" }
}
} }
) })
minetest.register_craft( -- death banner -- death banner
{ core.register_craft({
output = "banners:death_banner", output = "banners:death_banner",
recipe = { recipe = {
{"", "banners:death_sheet", ""}, { "", "banners:death_sheet", "" },
{"", "banners:death_pole", ""}, { "", "banners:death_pole", "" },
{"", "banners:death_base", ""} { "", "banners:death_base", "" }
}
} }
) })
-- nodes -- nodes
minetest.register_node("banners:power_banner", { core.register_node("banners:power_banner", {
drawtype = "mesh", drawtype = "mesh",
mesh = "banner_support.x", mesh = "banner_support.x",
tiles = {"gold_support.png"}, tiles = { "gold_support.png" },
description = "Power Banner", description = "Power Banner",
groups = {cracky=3}, groups = { cracky = 3 },
is_ground_content = false, is_ground_content = false,
diggable = true, diggable = true,
stack_max = 1, stack_max = 1,
@ -154,15 +145,15 @@ minetest.register_node("banners:power_banner", {
paramtype2 = "facedir", paramtype2 = "facedir",
after_place_node = function (pos, player, itemstack, pointed_thing) after_place_node = function (pos, player, itemstack, pointed_thing)
banners.after_powerbanner_placed(pos, player, itemstack, pointed_thing) banners.after_powerbanner_placed(pos, player, itemstack, pointed_thing)
end, end,
on_destruct = function(pos) on_destruct = function(pos)
banners.banner_on_destruct(pos) banners.banner_on_destruct(pos)
end, end,
on_dig = function(pos, n, p) on_dig = function(pos, n, p)
if minetest.is_protected(pos, p:get_player_name()) then if core.is_protected(pos, p:get_player_name()) then
return return
end end
local meta = minetest.get_meta(pos) local meta = core.get_meta(pos)
local facname = meta:get_string("faction") local facname = meta:get_string("faction")
if facname then if facname then
local faction = factions.factions[facname] local faction = factions.factions[facname]
@ -174,12 +165,12 @@ minetest.register_node("banners:power_banner", {
end, end,
}) })
minetest.register_node("banners:death_banner", { core.register_node("banners:death_banner", {
drawtype = "mesh", drawtype = "mesh",
mesh = "banner_support.x", mesh = "banner_support.x",
tiles = {"death_uv.png"}, tiles = { "death_uv.png" },
description = "Death Banner", description = "Death Banner",
groups = {cracky=3}, groups = { cracky = 3 },
is_ground_content = false, is_ground_content = false,
diggable = true, diggable = true,
stack_max = 1, stack_max = 1,
@ -187,15 +178,15 @@ minetest.register_node("banners:death_banner", {
paramtype2 = "facedir", paramtype2 = "facedir",
after_place_node = function (pos, player, itemstack, pointed_thing) after_place_node = function (pos, player, itemstack, pointed_thing)
banners.after_deathbanner_placed(pos, player, itemstack, pointed_thing) banners.after_deathbanner_placed(pos, player, itemstack, pointed_thing)
end, end,
on_destruct = function(pos) on_destruct = function(pos)
banners.banner_on_destruct(pos) banners.banner_on_destruct(pos)
end, end,
on_dig = function(pos, n, p) on_dig = function(pos, n, p)
if minetest.is_protected(pos, p:get_player_name()) then if core.is_protected(pos, p:get_player_name()) then
return return
end end
local meta = minetest.get_meta(pos) local meta = core.get_meta(pos)
local defending_facname = meta:get_string("faction") local defending_facname = meta:get_string("faction")
local parcelpos = factions.get_parcel_pos(pos) local parcelpos = factions.get_parcel_pos(pos)
if defending_facname then if defending_facname then
@ -204,34 +195,34 @@ minetest.register_node("banners:death_banner", {
faction:stop_attack(parcelpos) faction:stop_attack(parcelpos)
end end
end end
minetest.remove_node(pos) core.remove_node(pos)
end, end,
}) })
banners.after_powerbanner_placed = function(pos, player, itemstack, pointed_thing) banners.after_powerbanner_placed = function(pos, player, itemstack, pointed_thing)
minetest.get_node(pos).param2 = banners.determine_flag_direction(pos, pointed_thing) core.get_node(pos).param2 = banners.determine_flag_direction(pos, pointed_thing)
local faction = factions.players[player:get_player_name()] local faction = factions.players[player:get_player_name()]
if not faction then if not faction then
minetest.get_meta(pos):set_string("banner", "bg_white.png") core.get_meta(pos):set_string("banner", "bg_white.png")
else else
local banner_string = factions.factions[faction].banner local banner_string = factions.factions[faction].banner
minetest.get_meta(pos):set_string("banner", banner_string) core.get_meta(pos):set_string("banner", banner_string)
minetest.get_meta(pos):set_string("faction", faction) core.get_meta(pos):set_string("faction", faction)
factions.factions[faction]:increase_maxpower(banners.power_per_banner) factions.factions[faction]:increase_maxpower(banners.power_per_banner)
end end
minetest.add_entity(pos, "banners:banner_ent") core.add_entity(pos, "banners:banner_ent")
end end
banners.after_deathbanner_placed = function(pos, player, itemstack, pointed_thing) banners.after_deathbanner_placed = function(pos, player, itemstack, pointed_thing)
minetest.get_node(pos).param2 = banners.determine_flag_direction(pos, pointed_thing) core.get_node(pos).param2 = banners.determine_flag_direction(pos, pointed_thing)
local attacking_faction = factions.players[player:get_player_name()] local attacking_faction = factions.players[player:get_player_name()]
if attacking_faction then if attacking_faction then
local parcelpos = factions.get_parcel_pos(pos) local parcelpos = factions.get_parcel_pos(pos)
attacking_faction = factions.factions[attacking_faction] attacking_faction = factions.factions[attacking_faction]
attacking_faction:attack_parcel(parcelpos) attacking_faction:attack_parcel(parcelpos)
minetest.get_meta(pos):set_string("faction", attacking_faction.name) core.get_meta(pos):set_string("faction", attacking_faction.name)
end end
minetest.get_meta(pos):set_string("banner", "death_uv.png") core.get_meta(pos):set_string("banner", "death_uv.png")
minetest.add_entity(pos, "banners:banner_ent") core.add_entity(pos, "banners:banner_ent")
end end

View File

@ -35,13 +35,15 @@ banners.colors = {
"brown", "darkbrown" "brown", "darkbrown"
} }
banners.base_transform = ({texture = "bg_white.png", banners.base_transform = {
mask="mask_background.png"}) texture = "bg_white.png",
mask = "mask_background.png"
}
banners.creation_form_func = function(state) banners.creation_form_func = function(state)
-- helper functions -- helper functions
state.update_player_inv = function(self) state.update_player_inv = function(self)
local player = minetest.get_player_by_name(self.player) local player = core.get_player_by_name(self.player)
local newbanner = player:get_wielded_item() local newbanner = player:get_wielded_item()
newbanner:get_meta():set_string("", state.banner:get_transform_string()) newbanner:get_meta():set_string("", state.banner:get_transform_string())
player:set_wielded_item(newbanner) player:set_wielded_item(newbanner)
@ -58,7 +60,7 @@ banners.creation_form_func = function(state)
state.banner = banners.Banner:new(nil) state.banner = banners.Banner:new(nil)
state.banner:push_transform(banners.base_transform) state.banner:push_transform(banners.base_transform)
state.current_color = "bg_white.png" state.current_color = "bg_white.png"
state:size(20,10) state:size(20, 10)
state:image(3, 0.4, 4, 2, "banner_preview", nil) state:image(3, 0.4, 4, 2, "banner_preview", nil)
state:image(2.4, 0.8, 0.7, 0.7, "color_indicator", state.current_color) state:image(2.4, 0.8, 0.7, 0.7, "color_indicator", state.current_color)
state:update_all() state:update_all()
@ -68,25 +70,24 @@ banners.creation_form_func = function(state)
if #state.banner.transforms > 1 then if #state.banner.transforms > 1 then
state.banner:pop_transform() state.banner:pop_transform()
state:update_all() state:update_all()
end end
end) end)
-- delete button -- delete button
state:button(0.5, 1.3, 2, 1, "delete", "Delete"):click(function(self, state) state:button(0.5, 1.3, 2, 1, "delete", "Delete"):click(function(self, state)
state.banner.transforms = {banners.base_transform} state.banner.transforms = {banners.base_transform}
state:update_all() state:update_all()
end) end)
-- add banners colors -- add banners colors
local x = 7 local x = 7
local y = .3 local y = .3
for i in ipairs(banners.colors) do for i in ipairs(banners.colors) do
local b = state:button(x, y, 1, 1, banners.colors[i], "") local b = state:button(x, y, 1, 1, banners.colors[i], "")
b:setImage("bg_"..banners.colors[i]..".png")
b:click(function(self, state) b:click(function(self, state)
state.current_color = "bg_"..self.name..".png" state.current_color = "bg_"..self.name..".png"
state:update_preview() state:update_preview()
-- todo: update masks or something b:setImage("bg_" .. banners.colors[i] .. ".png")
end -- todo: update masks or something
) end)
x = x + 1 x = x + 1
if x > 19 then if x > 19 then
y = y + 1 y = y + 1
@ -98,12 +99,13 @@ banners.creation_form_func = function(state)
local y = 3 local y = 3
for i in ipairs(banners.masks) do for i in ipairs(banners.masks) do
local b = state:button(x, y, 2, 1, banners.masks[i], "") local b = state:button(x, y, 2, 1, banners.masks[i], "")
b:setImage(banners.masks[i]..".png")
b:click(function(self, state) b:click(function(self, state)
state.banner:push_transform({texture=state.current_color, mask=self.name..".png"}) state.banner:push_transform({texture=state.current_color, mask=self.name..".png"})
state:update_all() state:update_all()
end end
) )
b:setImage(banners.masks[i] .. ".png")
end)
x = x + 2 x = x + 2
if x > 17.5 then if x > 17.5 then
y = y + 1 y = y + 1
@ -114,7 +116,7 @@ banners.creation_form_func = function(state)
end end
banners.creation_form = smartfs.create("banners:banner_creation", banners.creation_form = smartfs.create("banners:banner_creation",
banners.creation_form_func); banners.creation_form_func)
-- banner definition -- banner definition
@ -136,7 +138,8 @@ end
function banners.Banner.get_transform_string(self) function banners.Banner.get_transform_string(self)
local final = {} local final = {}
for i in ipairs(self.transforms) do for i in ipairs(self.transforms) do
table.insert(final, "("..self.transforms[i].texture.."^[mask:"..self.transforms[i].mask.."^[makealpha:0,0,0)") table.insert(final, "(" .. self.transforms[i].texture
.. "^[mask:" .. self.transforms[i].mask .. "^[makealpha:0,0,0)")
end end
local ret = table.concat(final, "^") local ret = table.concat(final, "^")
return ret return ret
@ -146,10 +149,12 @@ end
banners.determine_flag_direction = function(pos, pointed_thing) banners.determine_flag_direction = function(pos, pointed_thing)
local above = pointed_thing.above local above = pointed_thing.above
local under = pointed_thing.under local under = pointed_thing.under
local dir = {x = under.x - above.x, local dir = {
y = under.y - above.y, x = under.x - above.x,
z = under.z - above.z} y = under.y - above.y,
return minetest.dir_to_wallmounted(dir) z = under.z - above.z
}
return core.dir_to_wallmounted(dir)
end end
banners.banner_on_use = function(itemstack, player, pointed_thing) banners.banner_on_use = function(itemstack, player, pointed_thing)
@ -159,18 +164,23 @@ banners.banner_on_use = function(itemstack, player, pointed_thing)
end end
banners.banner_on_dig = function(pos, node, player) banners.banner_on_dig = function(pos, node, player)
if not player or minetest.is_protected(pos, player:get_player_name()) then if not player or core.is_protected(pos, player:get_player_name()) then
return return
end end
local meta = minetest.get_meta(pos) local meta = core.get_meta(pos)
local inventory = player:get_inventory() local inventory = player:get_inventory()
inventory:add_item("main", {name=node.name, count=1, wear=0, metadata=meta:get_string("banner")}) inventory:add_item("main", {
minetest.remove_node(pos) name = node.name,
count = 1,
wear = 0,
metadata = meta:get_string("banner")
})
core.remove_node(pos)
end end
banners.banner_on_destruct = function(pos, node, player) banners.banner_on_destruct = function(pos, node, player)
local objects = minetest.get_objects_inside_radius(pos, 0.5) local objects = core.get_objects_inside_radius(pos, 0.5)
for _,v in ipairs(objects) do for _, v in ipairs(objects) do
local e = v:get_luaentity() local e = v:get_luaentity()
if e and e.name == "banners:banner_ent" then if e and e.name == "banners:banner_ent" then
v:remove() v:remove()
@ -179,22 +189,22 @@ banners.banner_on_destruct = function(pos, node, player)
end end
banners.banner_after_place = function (pos, player, itemstack, pointed_thing) banners.banner_after_place = function (pos, player, itemstack, pointed_thing)
minetest.get_node(pos).param2 = banners.determine_flag_direction(pos, pointed_thing) core.get_node(pos).param2 = banners.determine_flag_direction(pos, pointed_thing)
minetest.get_meta(pos):set_string("banner", itemstack:get_meta():get_string("")) core.get_meta(pos):set_string("banner", itemstack:get_meta():get_string(""))
minetest.add_entity(pos, "banners:banner_ent") core.add_entity(pos, "banners:banner_ent")
end end
-- banner entity -- banner entity
local set_banner_texture local set_banner_texture
set_banner_texture = function (obj, texture) set_banner_texture = function(obj, texture)
obj:set_properties({textures={"banner_uv_text.png^"..texture}}) obj:set_properties({ textures = { "banner_uv_text.png^" .. texture } })
end end
banners.banner_on_activate = function(self) banners.banner_on_activate = function(self)
local pos = self.object:get_pos() local pos = self.object:get_pos()
local banner = minetest.get_meta(pos):get_string("banner") local banner = core.get_meta(pos):get_string("banner")
local banner_face = minetest.get_node(pos).param2 local banner_face = core.get_node(pos).param2
local yaw = 0. local yaw = 0.
if banner_face == 2 then if banner_face == 2 then
yaw = 0. yaw = 0.
@ -211,18 +221,18 @@ banners.banner_on_activate = function(self)
end end
end end
minetest.register_entity("banners:banner_ent", { core.register_entity("banners:banner_ent", {
initial_properties = { initial_properties = {
collisionbox = {0,0,0,0,0,0}, collisionbox = { 0, 0, 0, 0, 0, 0 },
visual = "mesh", visual = "mesh",
textures = {"banner_uv_text"}, textures = { "banner_uv_text" },
mesh = "banner_pole.x", mesh = "banner_pole.x",
}, },
on_activate = banners.banner_on_activate, on_activate = banners.banner_on_activate,
}) })
if minetest.get_modpath("factions") then
dofile(minetest.get_modpath("banners").."/factions.lua") dofile(minetest.get_modpath("banners").."/factions.lua")
if core.get_modpath("factions") then
end end
dofile(minetest.get_modpath("banners").."/items.lua") dofile(minetest.get_modpath("banners").."/items.lua")

View File

@ -2,44 +2,35 @@
-- items -- items
minetest.register_craftitem("banners:banner_sheet", core.register_craftitem("banners:banner_sheet", {
{ groups = {},
groups = {}, description = "Banner sheet",
description = "Banner sheet", inventory_image = "banner_sheet.png",
inventory_image = "banner_sheet.png", stack_max = 1,
stack_max = 1, metadata = "",
metadata = "", })
}
)
minetest.register_craftitem("banners:wooden_pole", core.register_craftitem("banners:wooden_pole", {
{ groups = {},
groups = {}, description = "Wooden pole",
description = "Wooden pole", inventory_image = "wooden_pole.png"
inventory_image = "wooden_pole.png" })
}
)
minetest.register_craftitem("banners:wooden_base", core.register_craftitem("banners:wooden_base", {
{ groups = {},
groups = {}, description = "Wooden base",
description = "Wooden base", inventory_image = "wooden_base.png"
inventory_image = "wooden_base.png" })
}
)
minetest.register_craftitem("banners:steel_pole", core.register_craftitem("banners:steel_pole", {
{ groups = {},
groups = {}, description = "Steel pole",
description = "Steel pole", inventory_image = "steel_pole.png"
inventory_image = "steel_pole.png" })
}
) core.register_craftitem("banners:steel_base", {
groups = {},
description = "Steel base",
inventory_image = "steel_base.png"
})
minetest.register_craftitem("banners:steel_base",
{
groups = {},
description = "Steel base",
inventory_image = "steel_base.png"
}
)

100
nodes.lua
View File

@ -1,57 +1,53 @@
-- da wooden banner -- da wooden banner
minetest.register_node("banners:wooden_banner", core.register_node("banners:wooden_banner", {
{ drawtype = "mesh",
drawtype = "mesh", mesh = "banner_support.x",
mesh = "banner_support.x", tiles = { "banner_support.png" },
tiles = {"banner_support.png"}, description = "Wooden banner",
description = "Wooden banner", groups = { choppy = 2, dig_immediate = 2 },
groups = {choppy=2, dig_immediate=2}, is_ground_content = false,
is_ground_content = false, diggable = true,
diggable = true, stack_max = 1,
stack_max = 1, paramtype = "light",
paramtype="light", paramtype2 = "facedir",
paramtype2="facedir", after_place_node = function (pos, player, itemstack, pointed_thing)
after_place_node = function (pos, player, itemstack, pointed_thing) banners.banner_after_place(pos, player, itemstack, pointed_thing)
banners.banner_after_place(pos, player, itemstack, pointed_thing) end,
end, on_destruct = function(pos)
on_destruct = function(pos) banners.banner_on_destruct(pos)
banners.banner_on_destruct(pos) end,
end, on_use = function(i, p, pt)
on_use = function(i, p, pt) banners.banner_on_use(i, p, pt)
banners.banner_on_use(i, p, pt) end,
end, on_dig = function(pos, n, p)
on_dig = function(pos, n, p) banners.banner_on_dig(pos, n, p)
banners.banner_on_dig(pos, n, p) end
end })
}
)
-- steel banner -- steel banner
minetest.register_node("banners:steel_banner", core.register_node("banners:steel_banner", {
{ drawtype = "mesh",
drawtype = "mesh", mesh = "banner_support.x",
mesh = "banner_support.x", tiles = { "steel_support.png" },
tiles = {"steel_support.png"}, description = "Steel banner",
description = "Steel banner", groups = { cracky = 2 },
groups = {cracky=2}, is_ground_content = false,
is_ground_content = false, diggable = true,
diggable = true, stack_max = 1,
stack_max = 1, paramtype = "light",
paramtype = "light", paramtype2 = "facedir",
paramtype2 = "facedir", after_place_node = function (pos, player, itemstack, pointed_thing)
after_place_node = function (pos, player, itemstack, pointed_thing) banners.banner_after_place(pos, player, itemstack, pointed_thing)
banners.banner_after_place(pos, player, itemstack, pointed_thing) end,
end, on_destruct = function(pos)
on_destruct = function(pos) banners.banner_on_destruct(pos)
banners.banner_on_destruct(pos) end,
end, on_use = function(i, p, pt)
on_use = function(i, p, pt) banners.banner_on_use(i, p, pt)
banners.banner_on_use(i, p, pt) end,
end, on_dig = function(pos, n, p)
on_dig = function(pos, n, p) banners.banner_on_dig(pos, n, p)
banners.banner_on_dig(pos, n, p) end
end
} })
)

View File

@ -17,9 +17,9 @@ function smartfs.__call(self, name)
end end
-- Register forms and elements -- Register forms and elements
function smartfs.create(name,onload) function smartfs.create(name, onload)
if smartfs._fdef[name] then if smartfs._fdef[name] then
error("SmartFS - (Error) Form "..name.." already exists!") error("SmartFS - (Error) Form " .. name .. " already exists!")
end end
if smartfs.loaded and not smartfs._loaded_override then if smartfs.loaded and not smartfs._loaded_override then
error("SmartFS - (Error) Forms should be declared while the game loads.") error("SmartFS - (Error) Forms should be declared while the game loads.")
@ -37,7 +37,7 @@ function smartfs.override_load_checks()
smartfs._loaded_override = true smartfs._loaded_override = true
end end
minetest.after(0, function() core.after(0, function()
smartfs.loaded = true smartfs.loaded = true
end) end)
function smartfs.dynamic(name,player) function smartfs.dynamic(name,player)
@ -45,14 +45,14 @@ function smartfs.dynamic(name,player)
smartfs._dynamic_warned = true smartfs._dynamic_warned = true
print("SmartFS - (Warning) On the fly forms are being used. May cause bad things to happen") print("SmartFS - (Warning) On the fly forms are being used. May cause bad things to happen")
end end
local state = smartfs._makeState_({name=name},player,nil,false) local state = smartfs._makeState_({ name = name }, player, nil, false)
state.show = state._show_ state.show = state._show_
smartfs.opened[player] = state smartfs.opened[player] = state
return state return state
end end
function smartfs.element(name,data) function smartfs.element(name,data)
if smartfs._edef[name] then if smartfs._edef[name] then
error("SmartFS - (Error) Element type "..name.." already exists!") error("SmartFS - (Error) Element type " .. name .. " already exists!")
end end
smartfs._edef[name] = data smartfs._edef[name] = data
return smartfs._edef[name] return smartfs._edef[name]
@ -68,8 +68,8 @@ function smartfs.inventory_mod()
end end
end end
function smartfs.add_to_inventory(form,icon,title)
if unified_inventory then if unified_inventory then
function smartfs.add_to_inventory(form, icon, title)
unified_inventory.register_button(form.name, { unified_inventory.register_button(form.name, {
type = "image", type = "image",
image = icon, image = icon,
@ -78,15 +78,15 @@ function smartfs.add_to_inventory(form,icon,title)
get_formspec = function(player, formspec) get_formspec = function(player, formspec)
local name = player:get_player_name() local name = player:get_player_name()
local opened = smartfs._show_(form, name, nil, true) local opened = smartfs._show_(form, name, nil, true)
return {formspec = opened:_getFS_(false)} return { formspec = opened:_getFS_(false) }
end end
}) })
return true return true
elseif inventory_plus then elseif inventory_plus then
minetest.register_on_joinplayer(function(player) core.register_on_joinplayer(function(player)
inventory_plus.register_button(player, form.name, title) inventory_plus.register_button(player, form.name, title)
end) end)
minetest.register_on_player_receive_fields(function(player, formname, fields) core.register_on_player_receive_fields(function(player, formname, fields)
if formname == "" and fields[form.name] then if formname == "" and fields[form.name] then
local name = player:get_player_name() local name = player:get_player_name()
local opened = smartfs._show_(form, name, nil, true) local opened = smartfs._show_(form, name, nil, true)
@ -99,7 +99,7 @@ function smartfs.add_to_inventory(form,icon,title)
end end
end end
function smartfs._makeState_(form,player,params,is_inv) function smartfs._makeState_(form, player, params, is_inv)
return { return {
_ele = {}, _ele = {},
def = form, def = form,
@ -112,13 +112,13 @@ function smartfs._makeState_(form,player,params,is_inv)
close = function(self) close = function(self)
self.closed = true self.closed = true
end, end,
size = function(self,w,h) size = function(self, w, h)
self._size = {w=w,h=h} self._size = { w = w, h = h }
end, end,
_getFS_ = function(self,size) _getFS_ = function(self,size)
local res = "" local res = ""
if self._size and size then if self._size and size then
res = "size["..self._size.w..","..self._size.h.."]" res = "size[" .. self._size.w .. "," .. self._size.h .. "]"
end end
for key,val in pairs(self._ele) do for key,val in pairs(self._ele) do
res = res .. val:build() res = res .. val:build()
@ -128,25 +128,27 @@ function smartfs._makeState_(form,player,params,is_inv)
_show_ = function(self) _show_ = function(self)
if self.is_inv then if self.is_inv then
if unified_inventory then if unified_inventory then
unified_inventory.set_inventory_formspec(minetest.get_player_by_name(self.player), self.def.name)
elseif inventory_plus then elseif inventory_plus then
inventory_plus.set_inventory_formspec(minetest.get_player_by_name(self.player), self:_getFS_(true)) unified_inventory.set_inventory_formspec(
core.get_player_by_name(self.player), self.def.name)
inventory_plus.set_inventory_formspec(
core.get_player_by_name(self.player), self:_getFS_(true))
end end
else else
local res = self:_getFS_(true) local res = self:_getFS_(true)
minetest.show_formspec(player,form.name,res) core.show_formspec(player, form.name, res)
end end
end, end,
load = function(self,file) load = function(self,file)
local file = io.open(file, "r") local file = io.open(file, "r")
if file then if file then
local table = minetest.deserialize(file:read("*all")) local table = core.deserialize(file:read("*all"))
if type(table) == "table" then if type(table) == "table" then
if table.size then if table.size then
self._size = table.size self._size = table.size
end end
for key,val in pairs(table.ele) do for key,val in pairs(table.ele) do
self:element(val.type,val) self:element(val.type, val)
end end
return true return true
end end
@ -154,7 +156,7 @@ function smartfs._makeState_(form,player,params,is_inv)
return false return false
end, end,
save = function(self,file) save = function(self,file)
local res = {ele={}} local res = { ele = {} }
if self._size then if self._size then
res.size = self._size res.size = self._size
@ -166,65 +168,119 @@ function smartfs._makeState_(form,player,params,is_inv)
local file = io.open(file, "w") local file = io.open(file, "w")
if file then if file then
file:write(minetest.serialize(res)) file:write(core.serialize(res))
file:close() file:close()
return true return true
end end
return false return false
end, end,
setparam = function(self,key,value) setparam = function(self, key, value)
if not key then return end if not key then return end
self.param[key] = value self.param[key] = value
return true return true
end, end,
getparam = function(self,key,default) getparam = function(self, key, default)
if not key then return end if not key then return end
return self.param[key] or default return self.param[key] or default
end, end,
button = function(self,x,y,w,h,name,text,exitf) button = function(self, x, y, w, h, name, text, exitf)
if exitf == nil then exitf = false end if exitf == nil then exitf = false end
return self:element("button",{pos={x=x,y=y},size={w=w,h=h},name=name,value=text,closes=exitf}) return self:element("button", {
pos = { x = x, y = y },
size = { w = w, h = h },
name = name,
value = text,
closes = exitf
})
end, end,
label = function(self,x,y,name,text) label = function(self, x, y, name, text)
return self:element("label",{pos={x=x,y=y},name=name,value=text}) return self:element("label", {
pos = { x = x, y = y },
name = name,
value = text
})
end, end,
toggle = function(self,x,y,w,h,name,list) toggle = function(self, x, y, w, h, name, list)
return self:element("toggle",{pos={x=x,y=y},size={w=w,h=h},name=name,id=1,list=list}) return self:element("toggle", {
pos = { x = x, y = y },
size = { w = w, h = h },
name = name,
id = 1,
list = list
})
end, end,
field = function(self,x,y,w,h,name,label) field = function(self, x, y, w, h, name, label)
return self:element("field",{pos={x=x,y=y},size={w=w,h=h},name=name,value="",label=label}) return self:element("field", {
pos = { x = x, y = y },
size = { w = w, h = h },
name = name,
value = "",
label = label
})
end, end,
pwdfield = function(self,x,y,w,h,name,label) pwdfield = function(self, x, y, w, h, name, label)
local res = self:element("field",{pos={x=x,y=y},size={w=w,h=h},name=name,value="",label=label}) local res = self:element("field", {
pos = { x = x, y = y },
size = { w = w, h = h },
name = name,
value = "",
label = label
})
res:isPassword(true) res:isPassword(true)
return res return res
end, end,
textarea = function(self,x,y,w,h,name,label) textarea = function(self, x, y, w, h, name, label)
local res = self:element("field",{pos={x=x,y=y},size={w=w,h=h},name=name,value="",label=label}) local res = self:element("field", {
pos = { x = x, y = y },
size = { w = w, h = h },
name = name,
value = "",
label = label
})
res:isMultiline(true) res:isMultiline(true)
return res return res
end, end,
image = function(self,x,y,w,h,name,img) image = function(self, x, y, w, h, name, img)
return self:element("image",{pos={x=x,y=y},size={w=w,h=h},name=name,value=img}) return self:element("image", {
pos = { x = x, y = y },
size = { w = w, h = h },
name = name,
value = img
})
end, end,
checkbox = function(self,x,y,name,label,selected) checkbox = function(self, x, y, name, label, selected)
return self:element("checkbox",{pos={x=x,y=y},name=name,value=selected,label=label}) return self:element("checkbox", {
pos = { x = x, y = y },
name = name,
value = selected,
label = label
})
end, end,
listbox = function(self,x,y,w,h,name,selected,transparent) listbox = function(self, x, y, w, h, name, selected, transparent)
return self:element("list", { pos={x=x,y=y}, size={w=w,h=h}, name=name, selected=selected, transparent=transparent }) return self:element("list", {
pos = { x = x, y = y },
size = { w = w, h = h },
name = name,
selected = selected,
transparent = transparent
})
end, end,
inventory = function(self,x,y,w,h,name) inventory = function(self, x, y, w, h, name)
return self:element("inventory", { pos={x=x,y=y}, size={w=w,h=h}, name=name }) return self:element("inventory", {
pos = { x = x, y = y },
size = { w = w, h = h },
name = name
})
end, end,
element = function(self,typen,data) element = function(self, typen, data)
local type = smartfs._edef[typen] local type = smartfs._edef[typen]
if not type then if not type then
error("Element type "..typen.." does not exist!") error("Element type " .. typen .. " does not exist!")
end end
if self._ele[data.name] then if self._ele[data.name] then
error("Element "..data.name.." already exists") error("Element " .. data.name .. " already exists")
end end
data.type = typen data.type = typen
@ -237,7 +293,7 @@ function smartfs._makeState_(form,player,params,is_inv)
end end
} }
for key,val in pairs(type) do for key, val in pairs(type) do
ele[key] = val ele[key] = val
end end
@ -252,7 +308,7 @@ end
function smartfs._show_(form, player, params, is_inv) function smartfs._show_(form, player, params, is_inv)
local state = smartfs._makeState_(form, player, params, is_inv) local state = smartfs._makeState_(form, player, params, is_inv)
state.show = state._show_ state.show = state._show_
if form._reg(state)~=false then if form._reg(state) ~= false then
if not is_inv then if not is_inv then
smartfs.opened[player] = state smartfs.opened[player] = state
state:_show_() state:_show_()
@ -264,22 +320,22 @@ function smartfs._show_(form, player, params, is_inv)
end end
-- Receive fields from formspec -- Receive fields from formspec
local function _sfs_recieve_(state,name,fields) local function _sfs_recieve_(state, name, fields)
if (fields.quit == "true") then if fields.quit == "true" then
if not state.is_inv then if not state.is_inv then
smartfs.opened[name] = nil smartfs.opened[name] = nil
end end
return true return true
end end
for key,val in pairs(fields) do for key, val in pairs(fields) do
if state._ele[key] then if state._ele[key] then
state._ele[key].data.value = val state._ele[key].data.value = val
end end
end end
for key,val in pairs(state._ele) do for key,val in pairs(state._ele) do
if val.submit then if val.submit then
if (val:submit(fields)==true) then if val:submit(fields) == true then
return true return true
end end
end end
@ -287,7 +343,8 @@ local function _sfs_recieve_(state,name,fields)
if state.closed ~= true then if state.closed ~= true then
state:_show_() state:_show_()
else else
minetest.show_formspec(name,"","size[5,1]label[0,0;Formspec closing not yet created!]") core.show_formspec(name, "",
"size[5,1]label[0,0;Formspec closing not yet created!]")
if not state.is_inv then if not state.is_inv then
smartfs.opened[name] = nil smartfs.opened[name] = nil
end end
@ -295,18 +352,18 @@ local function _sfs_recieve_(state,name,fields)
return true return true
end end
minetest.register_on_player_receive_fields(function(player, formname, fields) core.register_on_player_receive_fields(function(player, formname, fields)
local name = player:get_player_name() local name = player:get_player_name()
if smartfs.opened[name] and not smartfs.opened[name].is_inv then if smartfs.opened[name] and not smartfs.opened[name].is_inv then
if smartfs.opened[name].def.name == formname then if smartfs.opened[name].def.name == formname then
local state = smartfs.opened[name] local state = smartfs.opened[name]
return _sfs_recieve_(state,name,fields) return _sfs_recieve_(state, name, fields)
else else
smartfs.opened[name] = nil smartfs.opened[name] = nil
end end
elseif smartfs.inv[name] and smartfs.inv[name].is_inv then elseif smartfs.inv[name] and smartfs.inv[name].is_inv then
local state = smartfs.inv[name] local state = smartfs.inv[name]
_sfs_recieve_(state,name,fields) _sfs_recieve_(state, name, fields)
end end
return false return false
end) end)
@ -316,41 +373,31 @@ end)
------------------------- ELEMENTS ---------------------------- ------------------------- ELEMENTS ----------------------------
----------------------------------------------------------------- -----------------------------------------------------------------
smartfs.element("button",{ smartfs.element("button", {
build = function(self) build = function(self)
if self.data.img then if self.data.img then
return "image_button[".. return "image_button["
self.data.pos.x..","..self.data.pos.y.. .. self.data.pos.x .. "," .. self.data.pos.y
";".. .. ";" .. self.data.size.w .. "," ..self.data.size.h
self.data.size.w..","..self.data.size.h.. .. ";" .. self.data.img
";".. .. ";" .. self.name
self.data.img.. .. ";" .. self.data.value
";".. .. "]"
self.name..
";"..
self.data.value..
"]"
else else
if self.data.closes then if self.data.closes then
return "button_exit[".. return "button_exit["
self.data.pos.x..","..self.data.pos.y.. .. self.data.pos.x .. "," .. self.data.pos.y
";".. .. ";" .. self.data.size.w .. "," ..self.data.size.h
self.data.size.w..","..self.data.size.h.. .. ";" .. self.name
";".. .. ";" .. self.data.value
self.name.. .. "]"
";"..
self.data.value..
"]"
else else
return "button[".. return "button["
self.data.pos.x..","..self.data.pos.y.. .. self.data.pos.x .. "," .. self.data.pos.y
";".. .. ";" .. self.data.size.w .. "," .. self.data.size.h
self.data.size.w..","..self.data.size.h.. .. ";" .. self.name
";".. .. ";" .. self.data.value
self.name.. .. "]"
";"..
self.data.value..
"]"
end end
end end
end, end,
@ -363,52 +410,49 @@ smartfs.element("button",{
return true return true
end end
end, end,
setPosition = function(self,x,y) setPosition = function(self, x, y)
self.data.pos = {x=x,y=y} self.data.pos = { x = x, y = y }
end, end,
getPosition = function(self,x,y) getPosition = function(self,x,y)
return self.data.pos return self.data.pos
end, end,
setSize = function(self,w,h) setSize = function(self, w, h)
self.data.size = {w=w,h=h} self.data.size = { w = w, h = h }
end, end,
getSize = function(self,x,y) getSize = function(self,x,y)
return self.data.size return self.data.size
end, end,
onClick = function(self,func) onClick = function(self, func)
self._click = func self._click = func
end, end,
click = function(self,func) click = function(self, func)
self._click = func self._click = func
end, end,
setText = function(self,text) setText = function(self, text)
self.data.value = text self.data.value = text
end, end,
getText = function(self) getText = function(self)
return self.data.value return self.data.value
end, end,
setImage = function(self,image) setImage = function(self, image)
self.data.img = image self.data.img = image
end, end,
getImage = function(self) getImage = function(self)
return self.data.img return self.data.img
end, end,
setClose = function(self,bool) setClose = function(self, bool)
self.data.closes = bool self.data.closes = bool
end end
}) })
smartfs.element("toggle",{ smartfs.element("toggle", {
build = function(self) build = function(self)
return "button[".. return "button["
self.data.pos.x..","..self.data.pos.y.. .. self.data.pos.x .. "," .. self.data.pos.y
";".. .. ";" .. self.data.size.w .. "," .. self.data.size.h
self.data.size.w..","..self.data.size.h.. .. ";" .. self.name
";".. .. ";" .. self.data.list[self.data.id]
self.name.. .. "]"
";"..
self.data.list[self.data.id]..
"]"
end, end,
submit = function(self,fields) submit = function(self,fields)
if fields[self.name] then if fields[self.name] then
@ -421,22 +465,22 @@ smartfs.element("toggle",{
end end
end end
end, end,
onToggle = function(self,func) onToggle = function(self, func)
self._tog = func self._tog = func
end, end,
setPosition = function(self,x,y) setPosition = function(self, x, y)
self.data.pos = {x=x,y=y} self.data.pos = { x = x, y = y }
end, end,
getPosition = function(self,x,y) getPosition = function(self,x,y)
return self.data.pos return self.data.pos
end, end,
setSize = function(self,w,h) setSize = function(self, w, h)
self.data.size = {w=w,h=h} self.data.size = { w = w, h = h }
end, end,
getSize = function(self,x,y) getSize = function(self,x,y)
return self.data.size return self.data.size
end, end,
setId = function(self,id) setId = function(self, id)
self.data.id = id self.data.id = id
end, end,
getId = function(self) getId = function(self)
@ -447,21 +491,20 @@ smartfs.element("toggle",{
end end
}) })
smartfs.element("label",{ smartfs.element("label", {
build = function(self) build = function(self)
return "label[".. return "label["
self.data.pos.x..","..self.data.pos.y.. .. self.data.pos.x .. "," .. self.data.pos.y
";".. .. ";" .. self.data.value
self.data.value.. .. "]"
"]"
end, end,
setPosition = function(self,x,y) setPosition = function(self, x, y)
self.data.pos = {x=x,y=y} self.data.pos = { x = x, y = y }
end, end,
getPosition = function(self,x,y) getPosition = function(self,x,y)
return self.data.pos return self.data.pos
end, end,
setText = function(self,text) setText = function(self, text)
self.data.value = text self.data.value = text
end, end,
getText = function(self) getText = function(self)
@ -469,93 +512,80 @@ smartfs.element("label",{
end end
}) })
smartfs.element("field",{ smartfs.element("field", {
build = function(self) build = function(self)
if self.data.ml then if self.data.ml then
return "textarea[".. return "textarea["
self.data.pos.x..","..self.data.pos.y.. .. self.data.pos.x .. "," .. self.data.pos.y
";".. .. ";" .. self.data.size.w .. "," .. self.data.size.h
self.data.size.w..","..self.data.size.h.. .. ";" .. self.name
";".. .. ";" .. self.data.label
self.name.. .. ";" .. self.data.value
";".. .. "]"
self.data.label..
";"..
self.data.value..
"]"
elseif self.data.pwd then elseif self.data.pwd then
return "pwdfield[".. return "pwdfield["
self.data.pos.x..","..self.data.pos.y.. .. self.data.pos.x .. "," .. self.data.pos.y
";".. .. ";" .. self.data.size.w .. "," .. self.data.size.h
self.data.size.w..","..self.data.size.h.. .. ";" .. self.name
";".. .. ";" .. self.data.label
self.name.. .. "]"
";"..
self.data.label..
"]"
else else
return "field[".. return "field["
self.data.pos.x..","..self.data.pos.y.. .. self.data.pos.x .. "," .. self.data.pos.y
";".. .. ";" .. self.data.size.w .. "," .. self.data.size.h
self.data.size.w..","..self.data.size.h.. .. ";" .. self.name
";".. .. ";" .. self.data.label
self.name.. .. ";" .. self.data.value
";".. .. "]"
self.data.label..
";"..
self.data.value..
"]"
end end
end, end,
setPosition = function(self,x,y) setPosition = function(self, x, y)
self.data.pos = {x=x,y=y} self.data.pos = { x = x, y = y }
end, end,
getPosition = function(self,x,y) getPosition = function(self,x,y)
return self.data.pos return self.data.pos
end, end,
setSize = function(self,w,h) setSize = function(self, w, h)
self.data.size = {w=w,h=h} self.data.size = { w = w, h = h }
end, end,
getSize = function(self,x,y) getSize = function(self,x,y)
return self.data.size return self.data.size
end, end,
setText = function(self,text) setText = function(self, text)
self.data.value = text self.data.value = text
end, end,
getText = function(self) getText = function(self)
return self.data.value return self.data.value
end, end,
isPassword = function(self,bool) isPassword = function(self, bool)
self.data.pwd = bool self.data.pwd = bool
end, end,
isMultiline = function(self,bool) isMultiline = function(self, bool)
self.data.ml = bool self.data.ml = bool
end end
}) })
smartfs.element("image",{ smartfs.element("image", {
build = function(self) build = function(self)
return "image[".. return "image["
self.data.pos.x..","..self.data.pos.y.. .. self.data.pos.x .. "," .. self.data.pos.y
";".. .. ";" .. self.data.size.w .. "," .. self.data.size.h
self.data.size.w..","..self.data.size.h.. .. ";" .. self.data.value
";".. .. "]"
self.data.value..
"]"
end, end,
setPosition = function(self,x,y) setPosition = function(self, x, y)
self.data.pos = {x=x,y=y} self.data.pos = { x = x, y = y }
end, end,
getPosition = function(self,x,y) getPosition = function(self,x,y)
return self.data.pos return self.data.pos
end, end,
setSize = function(self,w,h) setSize = function(self, w, h)
self.data.size = {w=w,h=h} self.data.size = { w = w, h = h }
end, end,
getSize = function(self,x,y) getSize = function(self,x,y)
return self.data.size return self.data.size
end, end,
setImage = function(self,text) setImage = function(self, text)
self.data.value = text self.data.value = text
end, end,
getImage = function(self) getImage = function(self)
@ -563,7 +593,7 @@ smartfs.element("image",{
end end
}) })
smartfs.element("checkbox",{ smartfs.element("checkbox", {
build = function(self) build = function(self)
if self.data.value then if self.data.value then
return "checkbox[".. return "checkbox["..
@ -583,19 +613,19 @@ smartfs.element("checkbox",{
";false]" ";false]"
end end
end, end,
setPosition = function(self,x,y) setPosition = function(self, x, y)
self.data.pos = {x=x,y=y} self.data.pos = { x = x, y = y }
end, end,
getPosition = function(self,x,y) getPosition = function(self,x,y)
return self.data.pos return self.data.pos
end, end,
setSize = function(self,w,h) setSize = function(self, w, h)
self.data.size = {w=w,h=h} self.data.size = { w = w, h = h }
end, end,
getSize = function(self,x,y) getSize = function(self,x,y)
return self.data.size return self.data.size
end, end,
setText = function(self,text) setText = function(self, text)
self.data.value = text self.data.value = text
end, end,
getText = function(self) getText = function(self)
@ -603,37 +633,33 @@ smartfs.element("checkbox",{
end end
}) })
smartfs.element("list",{ smartfs.element("list", {
build = function(self) build = function(self)
if not self.data.items then if not self.data.items then
self.data.items = {} self.data.items = {}
end end
local listformspec = "textlist[".. local listformspec = "textlist["
self.data.pos.x..","..self.data.pos.y.. .. self.data.pos.x .. "," .. self.data.pos.y
";".. .. ";" .. self.data.size.w .. "," .. self.data.size.h
self.data.size.w..","..self.data.size.h.. .. ";" .. self.data.name
";".. .. ";" .. table.concat(self.data.items, ",")
self.data.name.. .. ";" .. tostring(self.data.selected or "")
";".. .. ";" .. tostring(self.data.transparent or "false")
table.concat(self.data.items, ",").. .. "]"
";"..
tostring(self.data.selected or "")..
";"..
tostring(self.data.transparent or "false").."]"
return listformspec return listformspec
end, end,
submit = function(self,fields) submit = function(self, fields)
if fields[self.name] then if fields[self.name] then
local _type = string.sub(fields[self.data.name],1,3) local _type = string.sub(fields[self.data.name], 1, 3)
local index = string.sub(fields[self.data.name],5) local index = string.sub(fields[self.data.name], 5)
if _type == "CHG" and self._click then if _type == "CHG" and self._click then
self:_click(self.root, index) self:_click(self.root, index)
elseif _type == "DCL" and self._doubleClick then elseif _type == "DCL" and self._doubleClick then
self:_doubleClick(self.root, index) self:_doubleClick(self.root, index)
end end
end end
end, end,
onClick = function(self, func) onClick = function(self, func)
self._click = func self._click = func
end, end,
@ -646,14 +672,14 @@ smartfs.element("list",{
doubleclick = function(self, func) doubleclick = function(self, func)
self._doubleClick = func self._doubleClick = func
end, end,
setPosition = function(self,x,y) setPosition = function(self, x, y)
self.data.pos = {x=x,y=y} self.data.pos = { x = x, y = y }
end, end,
getPosition = function(self,x,y) getPosition = function(self,x,y)
return self.data.pos return self.data.pos
end, end,
setSize = function(self,w,h) setSize = function(self, w, h)
self.data.size = {w=w,h=h} self.data.size = { w = w, h = h }
end, end,
getSize = function(self,x,y) getSize = function(self,x,y)
return self.data.size return self.data.size
@ -664,11 +690,11 @@ smartfs.element("list",{
end end
table.insert(self.data.items, item) table.insert(self.data.items, item)
end, end,
removeItem = function(self,idx) removeItem = function(self, idx)
if not self.data.items then if not self.data.items then
self.data.items = {} self.data.items = {}
end end
table.remove(self.data.items,idx) table.remove(self.data.items, idx)
end, end,
popItem = function(self) popItem = function(self)
if not self.data.items then if not self.data.items then
@ -680,28 +706,24 @@ smartfs.element("list",{
end end
}) })
smartfs.element("inventory",{ smartfs.element("inventory", {
build = function(self) build = function(self)
return "list[".. return "list["
(self.data.location or "current_player") .. .. (self.data.location or "current_player")
";".. .. ";" .. self.name
self.name.. .. ";" .. self.data.pos.x .. "," .. self.data.pos.y
";".. .. ";" .. self.data.size.w .. "," .. self.data.size.h
self.data.pos.x..","..self.data.pos.y.. .. ";" .. (self.data.index or "")
";".. .. "]"
self.data.size.w..","..self.data.size.h..
";"..
(self.data.index or "") ..
"]"
end, end,
setPosition = function(self,x,y) setPosition = function(self, x, y)
self.data.pos = {x=x,y=y} self.data.pos = { x = x, y = y }
end, end,
getPosition = function(self,x,y) getPosition = function(self,x,y)
return self.data.pos return self.data.pos
end, end,
setSize = function(self,w,h) setSize = function(self, w, h)
self.data.size = {w=w,h=h} self.data.size = { w = w, h = h }
end, end,
getSize = function(self,x,y) getSize = function(self,x,y)
return self.data.size return self.data.size
@ -712,7 +734,7 @@ smartfs.element("inventory",{
-- "nodemeta:<X>,<Y>,<Z>": Any node metadata -- "nodemeta:<X>,<Y>,<Z>": Any node metadata
-- "detached:<name>": A detached inventory -- "detached:<name>": A detached inventory
-- "context" does not apply to smartfs, since there is no node-metadata as context available -- "context" does not apply to smartfs, since there is no node-metadata as context available
setLocation = function(self,location) setLocation = function(self, location)
self.data.location = location self.data.location = location
end, end,
getLocation = function(self) getLocation = function(self)
@ -727,7 +749,7 @@ smartfs.element("inventory",{
useDetached = function(self, name) useDetached = function(self, name)
self.data.location = "detached:" .. name self.data.location = "detached:" .. name
end, end,
setIndex = function(self,index) setIndex = function(self, index)
self.data.index = index self.data.index = index
end, end,
getIndex = function(self) getIndex = function(self)
@ -735,7 +757,7 @@ smartfs.element("inventory",{
end end
}) })
smartfs.element("code",{ smartfs.element("code", {
build = function(self) build = function(self)
if self._build then if self._build then
self:_build() self:_build()
@ -743,21 +765,22 @@ smartfs.element("code",{
return self.data.code return self.data.code
end, end,
submit = function(self,fields) submit = function(self, fields)
if self._sub then if self._sub then
self:_sub(fields) self:_sub(fields)
end end
end, end,
onSubmit = function(self,func) onSubmit = function(self, func)
self._sub = func self._sub = func
end, end,
onBuild = function(self,func) onBuild = function(self, func)
self._build = func self._build = func
end, end,
setCode = function(self,code) setCode = function(self, code)
self.data.code = code self.data.code = code
end, end,
getCode = function(self) getCode = function(self)
return self.data.code return self.data.code
end end
}) })