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:
parent
283b5bec25
commit
c8012c7266
51
crafts.lua
51
crafts.lua
@ -1,78 +1,73 @@
|
||||
|
||||
-- craft recipes
|
||||
minetest.register_craft( -- wooden flag pole
|
||||
{
|
||||
|
||||
-- wooden flag pole
|
||||
core.register_craft({
|
||||
output = "banners:wooden_pole 1",
|
||||
recipe = {
|
||||
{ "", "", "default:stick" },
|
||||
{ "", "default:stick", "" },
|
||||
{ "default:stick", "", "" }
|
||||
}
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
minetest.register_craft( -- steel flag pole
|
||||
{
|
||||
-- steel flag pole
|
||||
core.register_craft({
|
||||
output = "banners:steel_pole 1",
|
||||
recipe = {
|
||||
{ "", "", "default:steel_ingot" },
|
||||
{ "default:stick", "default:steel_ingot", "default:stick" },
|
||||
{ "default:steel_ingot", "", "" }
|
||||
}
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
minetest.register_craft( -- wooden flag support base
|
||||
{
|
||||
-- wooden flag support base
|
||||
core.register_craft({
|
||||
output = "banners:wooden_base 1",
|
||||
recipe = {
|
||||
{ "", "default:stick", "" },
|
||||
{ "default:stick", "", "default:stick" },
|
||||
{ "group:wood", "group:wood", "group:wood" }
|
||||
}
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
minetest.register_craft( -- steel support
|
||||
{
|
||||
-- steel support
|
||||
core.register_craft({
|
||||
output = "banners:steel_base",
|
||||
recipe = {
|
||||
{ "", "default:steel_ingot", "" },
|
||||
{ "default:steel_ingot", "", "default:steel_ingot" },
|
||||
{ "", "default:steelblock", "" }
|
||||
}
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
minetest.register_craft( -- banner sheet
|
||||
{
|
||||
-- banner sheet
|
||||
core.register_craft({
|
||||
output = "banners:banner_sheet 1",
|
||||
recipe = {
|
||||
{ "", "", "" },
|
||||
{ "farming:cotton", "farming:cotton", "farming:cotton" },
|
||||
{ "farming:cotton", "farming:cotton", "farming:cotton" }
|
||||
}
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
minetest.register_craft( -- wooden support
|
||||
{
|
||||
-- wooden support
|
||||
core.register_craft({
|
||||
output = "banners:wooden_banner 1",
|
||||
recipe = {
|
||||
{ "", "banners:banner_sheet", "" },
|
||||
{ "", "banners:wooden_pole", "" },
|
||||
{ "", "banners:wooden_base", "" }
|
||||
}
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
minetest.register_craft( -- steel support
|
||||
{
|
||||
-- steel support
|
||||
core.register_craft({
|
||||
output = "banners:steel_banner 1",
|
||||
recipe = {
|
||||
{ "", "banners:banner_sheet", "" },
|
||||
{ "", "banners:steel_pole", "" },
|
||||
{ "", "banners:steel_base", "" }
|
||||
}
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
|
109
factions.lua
109
factions.lua
@ -1,43 +1,43 @@
|
||||
banners.power_per_banner = 10.
|
||||
|
||||
-- items
|
||||
minetest.register_craftitem("banners:golden_finial", {
|
||||
core.register_craftitem("banners:golden_finial", {
|
||||
groups = {},
|
||||
description = "Golden finial",
|
||||
inventory_image = "gold_finial.png",
|
||||
})
|
||||
|
||||
minetest.register_craftitem("banners:silver_pole", {
|
||||
core.register_craftitem("banners:silver_pole", {
|
||||
groups = {},
|
||||
description = "Silver pole",
|
||||
inventory_image = "silver_pole.png"
|
||||
})
|
||||
|
||||
minetest.register_craftitem("banners:power_pole", {
|
||||
core.register_craftitem("banners:power_pole", {
|
||||
groups = {},
|
||||
description = "Power pole",
|
||||
inventory_image = "power_pole.png"
|
||||
})
|
||||
|
||||
minetest.register_craftitem("banners:golden_sheet", {
|
||||
core.register_craftitem("banners:golden_sheet", {
|
||||
groups = {},
|
||||
description = "Golden sheet",
|
||||
inventory_image = "golden_sheet.png"
|
||||
})
|
||||
|
||||
minetest.register_craftitem("banners:death_pole", {
|
||||
core.register_craftitem("banners:death_pole", {
|
||||
groups = {},
|
||||
description = "Death pole",
|
||||
inventory_image = "death_pole.png"
|
||||
})
|
||||
|
||||
minetest.register_craftitem("banners:death_sheet", {
|
||||
core.register_craftitem("banners:death_sheet", {
|
||||
groups = {},
|
||||
description = "Death sheet",
|
||||
inventory_image = "death_sheet.png"
|
||||
})
|
||||
|
||||
minetest.register_craftitem("banners:death_base", {
|
||||
core.register_craftitem("banners:death_base", {
|
||||
groups = {},
|
||||
description = "Death base",
|
||||
inventory_image = "death_base.png"
|
||||
@ -46,102 +46,93 @@ minetest.register_craftitem("banners:death_base", {
|
||||
|
||||
-- crafts
|
||||
|
||||
minetest.register_craft( -- silver flag pole
|
||||
{
|
||||
-- silver flag pole
|
||||
core.register_craft({
|
||||
output = "banners:silver_pole 1",
|
||||
recipe = {
|
||||
{ "", "", "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",
|
||||
recipe = {
|
||||
{ "", "", "default:diamond" },
|
||||
{ "", "default:obsidian", "" },
|
||||
{ "default:obsidian", "", "" }
|
||||
}
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
minetest.register_craft( -- golden finial
|
||||
{
|
||||
-- golden finial
|
||||
core.register_craft({
|
||||
output = "banners:golden_finial",
|
||||
recipe = {
|
||||
{ "", "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",
|
||||
recipe = {
|
||||
{ "", "", "" },
|
||||
{ "", "banners:golden_finial", "" },
|
||||
{ "banners:silver_pole", "", "" }
|
||||
}
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
minetest.register_craft( -- golden sheet
|
||||
{
|
||||
-- golden sheet
|
||||
core.register_craft({
|
||||
output = "banners:golden_sheet 1",
|
||||
type = "shapeless",
|
||||
recipe = { "default:gold_ingot", "banners:banner_sheet" }
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
minetest.register_craft( -- death sheet
|
||||
{
|
||||
-- death sheet
|
||||
core.register_craft({
|
||||
output = "banners:death_sheet 1",
|
||||
type = "shapeless",
|
||||
recipe = { "default:obsidian", "banners:banner_sheet" }
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
minetest.register_craft( -- death sheet
|
||||
{
|
||||
-- death sheet
|
||||
core.register_craft({
|
||||
output = "banners:death_base 1",
|
||||
recipe = {
|
||||
{ "", "", "" },
|
||||
{ "", "banners:steel_base", "" },
|
||||
{ "default:obsidian", "default:obsidian", "default:obsidian" }
|
||||
}
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
minetest.register_craft( -- power banner
|
||||
{
|
||||
-- power banner
|
||||
core.register_craft({
|
||||
output = "banners:power_banner",
|
||||
recipe = {
|
||||
{ "", "banners:golden_sheet", "" },
|
||||
{ "", "banners:power_pole", "" },
|
||||
{ "", "banners:steel_base", "" }
|
||||
}
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
minetest.register_craft( -- death banner
|
||||
{
|
||||
-- death banner
|
||||
core.register_craft({
|
||||
output = "banners:death_banner",
|
||||
recipe = {
|
||||
{ "", "banners:death_sheet", "" },
|
||||
{ "", "banners:death_pole", "" },
|
||||
{ "", "banners:death_base", "" }
|
||||
}
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
|
||||
-- nodes
|
||||
minetest.register_node("banners:power_banner", {
|
||||
core.register_node("banners:power_banner", {
|
||||
drawtype = "mesh",
|
||||
mesh = "banner_support.x",
|
||||
tiles = { "gold_support.png" },
|
||||
@ -159,10 +150,10 @@ minetest.register_node("banners:power_banner", {
|
||||
banners.banner_on_destruct(pos)
|
||||
end,
|
||||
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
|
||||
end
|
||||
local meta = minetest.get_meta(pos)
|
||||
local meta = core.get_meta(pos)
|
||||
local facname = meta:get_string("faction")
|
||||
if facname then
|
||||
local faction = factions.factions[facname]
|
||||
@ -174,7 +165,7 @@ minetest.register_node("banners:power_banner", {
|
||||
end,
|
||||
})
|
||||
|
||||
minetest.register_node("banners:death_banner", {
|
||||
core.register_node("banners:death_banner", {
|
||||
drawtype = "mesh",
|
||||
mesh = "banner_support.x",
|
||||
tiles = { "death_uv.png" },
|
||||
@ -192,10 +183,10 @@ minetest.register_node("banners:death_banner", {
|
||||
banners.banner_on_destruct(pos)
|
||||
end,
|
||||
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
|
||||
end
|
||||
local meta = minetest.get_meta(pos)
|
||||
local meta = core.get_meta(pos)
|
||||
local defending_facname = meta:get_string("faction")
|
||||
local parcelpos = factions.get_parcel_pos(pos)
|
||||
if defending_facname then
|
||||
@ -204,34 +195,34 @@ minetest.register_node("banners:death_banner", {
|
||||
faction:stop_attack(parcelpos)
|
||||
end
|
||||
end
|
||||
minetest.remove_node(pos)
|
||||
core.remove_node(pos)
|
||||
end,
|
||||
})
|
||||
|
||||
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()]
|
||||
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
|
||||
local banner_string = factions.factions[faction].banner
|
||||
minetest.get_meta(pos):set_string("banner", banner_string)
|
||||
minetest.get_meta(pos):set_string("faction", faction)
|
||||
core.get_meta(pos):set_string("banner", banner_string)
|
||||
core.get_meta(pos):set_string("faction", faction)
|
||||
factions.factions[faction]:increase_maxpower(banners.power_per_banner)
|
||||
end
|
||||
minetest.add_entity(pos, "banners:banner_ent")
|
||||
core.add_entity(pos, "banners:banner_ent")
|
||||
end
|
||||
|
||||
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()]
|
||||
if attacking_faction then
|
||||
local parcelpos = factions.get_parcel_pos(pos)
|
||||
attacking_faction = factions.factions[attacking_faction]
|
||||
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
|
||||
minetest.get_meta(pos):set_string("banner", "death_uv.png")
|
||||
minetest.add_entity(pos, "banners:banner_ent")
|
||||
core.get_meta(pos):set_string("banner", "death_uv.png")
|
||||
core.add_entity(pos, "banners:banner_ent")
|
||||
end
|
||||
|
||||
|
58
init.lua
58
init.lua
@ -35,13 +35,15 @@ banners.colors = {
|
||||
"brown", "darkbrown"
|
||||
}
|
||||
|
||||
banners.base_transform = ({texture = "bg_white.png",
|
||||
mask="mask_background.png"})
|
||||
banners.base_transform = {
|
||||
texture = "bg_white.png",
|
||||
mask = "mask_background.png"
|
||||
}
|
||||
|
||||
banners.creation_form_func = function(state)
|
||||
-- helper functions
|
||||
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()
|
||||
newbanner:get_meta():set_string("", state.banner:get_transform_string())
|
||||
player:set_wielded_item(newbanner)
|
||||
@ -80,13 +82,12 @@ banners.creation_form_func = function(state)
|
||||
local y = .3
|
||||
for i in ipairs(banners.colors) do
|
||||
local b = state:button(x, y, 1, 1, banners.colors[i], "")
|
||||
b:setImage("bg_"..banners.colors[i]..".png")
|
||||
b:click(function(self, state)
|
||||
state.current_color = "bg_"..self.name..".png"
|
||||
state:update_preview()
|
||||
b:setImage("bg_" .. banners.colors[i] .. ".png")
|
||||
-- todo: update masks or something
|
||||
end
|
||||
)
|
||||
end)
|
||||
x = x + 1
|
||||
if x > 19 then
|
||||
y = y + 1
|
||||
@ -98,12 +99,13 @@ banners.creation_form_func = function(state)
|
||||
local y = 3
|
||||
for i in ipairs(banners.masks) do
|
||||
local b = state:button(x, y, 2, 1, banners.masks[i], "")
|
||||
b:setImage(banners.masks[i]..".png")
|
||||
b:click(function(self, state)
|
||||
state.banner:push_transform({texture=state.current_color, mask=self.name..".png"})
|
||||
state:update_all()
|
||||
end
|
||||
)
|
||||
b:setImage(banners.masks[i] .. ".png")
|
||||
end)
|
||||
x = x + 2
|
||||
if x > 17.5 then
|
||||
y = y + 1
|
||||
@ -114,7 +116,7 @@ banners.creation_form_func = function(state)
|
||||
end
|
||||
|
||||
banners.creation_form = smartfs.create("banners:banner_creation",
|
||||
banners.creation_form_func);
|
||||
banners.creation_form_func)
|
||||
|
||||
|
||||
-- banner definition
|
||||
@ -136,7 +138,8 @@ end
|
||||
function banners.Banner.get_transform_string(self)
|
||||
local final = {}
|
||||
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
|
||||
local ret = table.concat(final, "^")
|
||||
return ret
|
||||
@ -146,10 +149,12 @@ end
|
||||
banners.determine_flag_direction = function(pos, pointed_thing)
|
||||
local above = pointed_thing.above
|
||||
local under = pointed_thing.under
|
||||
local dir = {x = under.x - above.x,
|
||||
local dir = {
|
||||
x = under.x - above.x,
|
||||
y = under.y - above.y,
|
||||
z = under.z - above.z}
|
||||
return minetest.dir_to_wallmounted(dir)
|
||||
z = under.z - above.z
|
||||
}
|
||||
return core.dir_to_wallmounted(dir)
|
||||
end
|
||||
|
||||
banners.banner_on_use = function(itemstack, player, pointed_thing)
|
||||
@ -159,17 +164,22 @@ banners.banner_on_use = function(itemstack, player, pointed_thing)
|
||||
end
|
||||
|
||||
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
|
||||
end
|
||||
local meta = minetest.get_meta(pos)
|
||||
local meta = core.get_meta(pos)
|
||||
local inventory = player:get_inventory()
|
||||
inventory:add_item("main", {name=node.name, count=1, wear=0, metadata=meta:get_string("banner")})
|
||||
minetest.remove_node(pos)
|
||||
inventory:add_item("main", {
|
||||
name = node.name,
|
||||
count = 1,
|
||||
wear = 0,
|
||||
metadata = meta:get_string("banner")
|
||||
})
|
||||
core.remove_node(pos)
|
||||
end
|
||||
|
||||
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
|
||||
local e = v:get_luaentity()
|
||||
if e and e.name == "banners:banner_ent" then
|
||||
@ -179,9 +189,9 @@ banners.banner_on_destruct = function(pos, node, player)
|
||||
end
|
||||
|
||||
banners.banner_after_place = function (pos, player, itemstack, pointed_thing)
|
||||
minetest.get_node(pos).param2 = banners.determine_flag_direction(pos, pointed_thing)
|
||||
minetest.get_meta(pos):set_string("banner", itemstack:get_meta():get_string(""))
|
||||
minetest.add_entity(pos, "banners:banner_ent")
|
||||
core.get_node(pos).param2 = banners.determine_flag_direction(pos, pointed_thing)
|
||||
core.get_meta(pos):set_string("banner", itemstack:get_meta():get_string(""))
|
||||
core.add_entity(pos, "banners:banner_ent")
|
||||
end
|
||||
|
||||
-- banner entity
|
||||
@ -193,8 +203,8 @@ end
|
||||
|
||||
banners.banner_on_activate = function(self)
|
||||
local pos = self.object:get_pos()
|
||||
local banner = minetest.get_meta(pos):get_string("banner")
|
||||
local banner_face = minetest.get_node(pos).param2
|
||||
local banner = core.get_meta(pos):get_string("banner")
|
||||
local banner_face = core.get_node(pos).param2
|
||||
local yaw = 0.
|
||||
if banner_face == 2 then
|
||||
yaw = 0.
|
||||
@ -211,7 +221,7 @@ banners.banner_on_activate = function(self)
|
||||
end
|
||||
end
|
||||
|
||||
minetest.register_entity("banners:banner_ent", {
|
||||
core.register_entity("banners:banner_ent", {
|
||||
initial_properties = {
|
||||
collisionbox = { 0, 0, 0, 0, 0, 0 },
|
||||
visual = "mesh",
|
||||
@ -221,8 +231,8 @@ minetest.register_entity("banners:banner_ent", {
|
||||
on_activate = banners.banner_on_activate,
|
||||
})
|
||||
|
||||
if minetest.get_modpath("factions") then
|
||||
dofile(minetest.get_modpath("banners").."/factions.lua")
|
||||
if core.get_modpath("factions") then
|
||||
end
|
||||
|
||||
dofile(minetest.get_modpath("banners").."/items.lua")
|
||||
|
31
items.lua
31
items.lua
@ -2,44 +2,35 @@
|
||||
|
||||
-- items
|
||||
|
||||
minetest.register_craftitem("banners:banner_sheet",
|
||||
{
|
||||
core.register_craftitem("banners:banner_sheet", {
|
||||
groups = {},
|
||||
description = "Banner sheet",
|
||||
inventory_image = "banner_sheet.png",
|
||||
stack_max = 1,
|
||||
metadata = "",
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
minetest.register_craftitem("banners:wooden_pole",
|
||||
{
|
||||
core.register_craftitem("banners:wooden_pole", {
|
||||
groups = {},
|
||||
description = "Wooden pole",
|
||||
inventory_image = "wooden_pole.png"
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
minetest.register_craftitem("banners:wooden_base",
|
||||
{
|
||||
core.register_craftitem("banners:wooden_base", {
|
||||
groups = {},
|
||||
description = "Wooden base",
|
||||
inventory_image = "wooden_base.png"
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
minetest.register_craftitem("banners:steel_pole",
|
||||
{
|
||||
core.register_craftitem("banners:steel_pole", {
|
||||
groups = {},
|
||||
description = "Steel pole",
|
||||
inventory_image = "steel_pole.png"
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
minetest.register_craftitem("banners:steel_base",
|
||||
{
|
||||
core.register_craftitem("banners:steel_base", {
|
||||
groups = {},
|
||||
description = "Steel base",
|
||||
inventory_image = "steel_base.png"
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
|
12
nodes.lua
12
nodes.lua
@ -1,6 +1,5 @@
|
||||
-- da wooden banner
|
||||
minetest.register_node("banners:wooden_banner",
|
||||
{
|
||||
core.register_node("banners:wooden_banner", {
|
||||
drawtype = "mesh",
|
||||
mesh = "banner_support.x",
|
||||
tiles = { "banner_support.png" },
|
||||
@ -23,12 +22,10 @@ minetest.register_node("banners:wooden_banner",
|
||||
on_dig = function(pos, n, p)
|
||||
banners.banner_on_dig(pos, n, p)
|
||||
end
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
-- steel banner
|
||||
minetest.register_node("banners:steel_banner",
|
||||
{
|
||||
core.register_node("banners:steel_banner", {
|
||||
drawtype = "mesh",
|
||||
mesh = "banner_support.x",
|
||||
tiles = { "steel_support.png" },
|
||||
@ -52,6 +49,5 @@ minetest.register_node("banners:steel_banner",
|
||||
banners.banner_on_dig(pos, n, p)
|
||||
end
|
||||
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
|
277
smartfs.lua
277
smartfs.lua
@ -37,7 +37,7 @@ function smartfs.override_load_checks()
|
||||
smartfs._loaded_override = true
|
||||
end
|
||||
|
||||
minetest.after(0, function()
|
||||
core.after(0, function()
|
||||
smartfs.loaded = true
|
||||
end)
|
||||
function smartfs.dynamic(name,player)
|
||||
@ -68,8 +68,8 @@ function smartfs.inventory_mod()
|
||||
end
|
||||
end
|
||||
|
||||
function smartfs.add_to_inventory(form,icon,title)
|
||||
if unified_inventory then
|
||||
function smartfs.add_to_inventory(form, icon, title)
|
||||
unified_inventory.register_button(form.name, {
|
||||
type = "image",
|
||||
image = icon,
|
||||
@ -83,10 +83,10 @@ function smartfs.add_to_inventory(form,icon,title)
|
||||
})
|
||||
return true
|
||||
elseif inventory_plus then
|
||||
minetest.register_on_joinplayer(function(player)
|
||||
core.register_on_joinplayer(function(player)
|
||||
inventory_plus.register_button(player, form.name, title)
|
||||
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
|
||||
local name = player:get_player_name()
|
||||
local opened = smartfs._show_(form, name, nil, true)
|
||||
@ -128,19 +128,21 @@ function smartfs._makeState_(form,player,params,is_inv)
|
||||
_show_ = function(self)
|
||||
if self.is_inv then
|
||||
if unified_inventory then
|
||||
unified_inventory.set_inventory_formspec(minetest.get_player_by_name(self.player), self.def.name)
|
||||
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
|
||||
else
|
||||
local res = self:_getFS_(true)
|
||||
minetest.show_formspec(player,form.name,res)
|
||||
core.show_formspec(player, form.name, res)
|
||||
end
|
||||
end,
|
||||
load = function(self,file)
|
||||
local file = io.open(file, "r")
|
||||
if file then
|
||||
local table = minetest.deserialize(file:read("*all"))
|
||||
local table = core.deserialize(file:read("*all"))
|
||||
if type(table) == "table" then
|
||||
if table.size then
|
||||
self._size = table.size
|
||||
@ -166,7 +168,7 @@ function smartfs._makeState_(form,player,params,is_inv)
|
||||
|
||||
local file = io.open(file, "w")
|
||||
if file then
|
||||
file:write(minetest.serialize(res))
|
||||
file:write(core.serialize(res))
|
||||
file:close()
|
||||
return true
|
||||
end
|
||||
@ -183,38 +185,92 @@ function smartfs._makeState_(form,player,params,is_inv)
|
||||
end,
|
||||
button = function(self, x, y, w, h, name, text, exitf)
|
||||
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,
|
||||
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,
|
||||
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,
|
||||
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,
|
||||
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)
|
||||
return res
|
||||
end,
|
||||
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)
|
||||
return res
|
||||
end,
|
||||
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,
|
||||
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,
|
||||
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,
|
||||
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,
|
||||
element = function(self, typen, data)
|
||||
local type = smartfs._edef[typen]
|
||||
@ -265,7 +321,7 @@ end
|
||||
|
||||
-- Receive fields from formspec
|
||||
local function _sfs_recieve_(state, name, fields)
|
||||
if (fields.quit == "true") then
|
||||
if fields.quit == "true" then
|
||||
if not state.is_inv then
|
||||
smartfs.opened[name] = nil
|
||||
end
|
||||
@ -279,7 +335,7 @@ local function _sfs_recieve_(state,name,fields)
|
||||
end
|
||||
for key,val in pairs(state._ele) do
|
||||
if val.submit then
|
||||
if (val:submit(fields)==true) then
|
||||
if val:submit(fields) == true then
|
||||
return true
|
||||
end
|
||||
end
|
||||
@ -287,7 +343,8 @@ local function _sfs_recieve_(state,name,fields)
|
||||
if state.closed ~= true then
|
||||
state:_show_()
|
||||
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
|
||||
smartfs.opened[name] = nil
|
||||
end
|
||||
@ -295,7 +352,7 @@ local function _sfs_recieve_(state,name,fields)
|
||||
return true
|
||||
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()
|
||||
if smartfs.opened[name] and not smartfs.opened[name].is_inv then
|
||||
if smartfs.opened[name].def.name == formname then
|
||||
@ -319,38 +376,28 @@ end)
|
||||
smartfs.element("button", {
|
||||
build = function(self)
|
||||
if self.data.img then
|
||||
return "image_button["..
|
||||
self.data.pos.x..","..self.data.pos.y..
|
||||
";"..
|
||||
self.data.size.w..","..self.data.size.h..
|
||||
";"..
|
||||
self.data.img..
|
||||
";"..
|
||||
self.name..
|
||||
";"..
|
||||
self.data.value..
|
||||
"]"
|
||||
return "image_button["
|
||||
.. self.data.pos.x .. "," .. self.data.pos.y
|
||||
.. ";" .. self.data.size.w .. "," ..self.data.size.h
|
||||
.. ";" .. self.data.img
|
||||
.. ";" .. self.name
|
||||
.. ";" .. self.data.value
|
||||
.. "]"
|
||||
else
|
||||
if self.data.closes then
|
||||
return "button_exit["..
|
||||
self.data.pos.x..","..self.data.pos.y..
|
||||
";"..
|
||||
self.data.size.w..","..self.data.size.h..
|
||||
";"..
|
||||
self.name..
|
||||
";"..
|
||||
self.data.value..
|
||||
"]"
|
||||
return "button_exit["
|
||||
.. self.data.pos.x .. "," .. self.data.pos.y
|
||||
.. ";" .. self.data.size.w .. "," ..self.data.size.h
|
||||
.. ";" .. self.name
|
||||
.. ";" .. self.data.value
|
||||
.. "]"
|
||||
else
|
||||
return "button["..
|
||||
self.data.pos.x..","..self.data.pos.y..
|
||||
";"..
|
||||
self.data.size.w..","..self.data.size.h..
|
||||
";"..
|
||||
self.name..
|
||||
";"..
|
||||
self.data.value..
|
||||
"]"
|
||||
return "button["
|
||||
.. self.data.pos.x .. "," .. self.data.pos.y
|
||||
.. ";" .. self.data.size.w .. "," .. self.data.size.h
|
||||
.. ";" .. self.name
|
||||
.. ";" .. self.data.value
|
||||
.. "]"
|
||||
end
|
||||
end
|
||||
end,
|
||||
@ -400,15 +447,12 @@ smartfs.element("button",{
|
||||
|
||||
smartfs.element("toggle", {
|
||||
build = function(self)
|
||||
return "button["..
|
||||
self.data.pos.x..","..self.data.pos.y..
|
||||
";"..
|
||||
self.data.size.w..","..self.data.size.h..
|
||||
";"..
|
||||
self.name..
|
||||
";"..
|
||||
self.data.list[self.data.id]..
|
||||
"]"
|
||||
return "button["
|
||||
.. self.data.pos.x .. "," .. self.data.pos.y
|
||||
.. ";" .. self.data.size.w .. "," .. self.data.size.h
|
||||
.. ";" .. self.name
|
||||
.. ";" .. self.data.list[self.data.id]
|
||||
.. "]"
|
||||
end,
|
||||
submit = function(self,fields)
|
||||
if fields[self.name] then
|
||||
@ -449,11 +493,10 @@ smartfs.element("toggle",{
|
||||
|
||||
smartfs.element("label", {
|
||||
build = function(self)
|
||||
return "label["..
|
||||
self.data.pos.x..","..self.data.pos.y..
|
||||
";"..
|
||||
self.data.value..
|
||||
"]"
|
||||
return "label["
|
||||
.. self.data.pos.x .. "," .. self.data.pos.y
|
||||
.. ";" .. self.data.value
|
||||
.. "]"
|
||||
end,
|
||||
setPosition = function(self, x, y)
|
||||
self.data.pos = { x = x, y = y }
|
||||
@ -472,39 +515,28 @@ smartfs.element("label",{
|
||||
smartfs.element("field", {
|
||||
build = function(self)
|
||||
if self.data.ml then
|
||||
return "textarea["..
|
||||
self.data.pos.x..","..self.data.pos.y..
|
||||
";"..
|
||||
self.data.size.w..","..self.data.size.h..
|
||||
";"..
|
||||
self.name..
|
||||
";"..
|
||||
self.data.label..
|
||||
";"..
|
||||
self.data.value..
|
||||
"]"
|
||||
return "textarea["
|
||||
.. self.data.pos.x .. "," .. self.data.pos.y
|
||||
.. ";" .. self.data.size.w .. "," .. self.data.size.h
|
||||
.. ";" .. self.name
|
||||
.. ";" .. self.data.label
|
||||
.. ";" .. self.data.value
|
||||
.. "]"
|
||||
elseif self.data.pwd then
|
||||
return "pwdfield["..
|
||||
self.data.pos.x..","..self.data.pos.y..
|
||||
";"..
|
||||
self.data.size.w..","..self.data.size.h..
|
||||
";"..
|
||||
self.name..
|
||||
";"..
|
||||
self.data.label..
|
||||
"]"
|
||||
return "pwdfield["
|
||||
.. self.data.pos.x .. "," .. self.data.pos.y
|
||||
.. ";" .. self.data.size.w .. "," .. self.data.size.h
|
||||
.. ";" .. self.name
|
||||
.. ";" .. self.data.label
|
||||
.. "]"
|
||||
else
|
||||
return "field["..
|
||||
self.data.pos.x..","..self.data.pos.y..
|
||||
";"..
|
||||
self.data.size.w..","..self.data.size.h..
|
||||
";"..
|
||||
self.name..
|
||||
";"..
|
||||
self.data.label..
|
||||
";"..
|
||||
self.data.value..
|
||||
"]"
|
||||
return "field["
|
||||
.. self.data.pos.x .. "," .. self.data.pos.y
|
||||
.. ";" .. self.data.size.w .. "," .. self.data.size.h
|
||||
.. ";" .. self.name
|
||||
.. ";" .. self.data.label
|
||||
.. ";" .. self.data.value
|
||||
.. "]"
|
||||
end
|
||||
end,
|
||||
setPosition = function(self, x, y)
|
||||
@ -535,13 +567,11 @@ smartfs.element("field",{
|
||||
|
||||
smartfs.element("image", {
|
||||
build = function(self)
|
||||
return "image["..
|
||||
self.data.pos.x..","..self.data.pos.y..
|
||||
";"..
|
||||
self.data.size.w..","..self.data.size.h..
|
||||
";"..
|
||||
self.data.value..
|
||||
"]"
|
||||
return "image["
|
||||
.. self.data.pos.x .. "," .. self.data.pos.y
|
||||
.. ";" .. self.data.size.w .. "," .. self.data.size.h
|
||||
.. ";" .. self.data.value
|
||||
.. "]"
|
||||
end,
|
||||
setPosition = function(self, x, y)
|
||||
self.data.pos = { x = x, y = y }
|
||||
@ -608,18 +638,14 @@ smartfs.element("list",{
|
||||
if not self.data.items then
|
||||
self.data.items = {}
|
||||
end
|
||||
local listformspec = "textlist["..
|
||||
self.data.pos.x..","..self.data.pos.y..
|
||||
";"..
|
||||
self.data.size.w..","..self.data.size.h..
|
||||
";"..
|
||||
self.data.name..
|
||||
";"..
|
||||
table.concat(self.data.items, ",")..
|
||||
";"..
|
||||
tostring(self.data.selected or "")..
|
||||
";"..
|
||||
tostring(self.data.transparent or "false").."]"
|
||||
local listformspec = "textlist["
|
||||
.. self.data.pos.x .. "," .. self.data.pos.y
|
||||
.. ";" .. self.data.size.w .. "," .. self.data.size.h
|
||||
.. ";" .. self.data.name
|
||||
.. ";" .. table.concat(self.data.items, ",")
|
||||
.. ";" .. tostring(self.data.selected or "")
|
||||
.. ";" .. tostring(self.data.transparent or "false")
|
||||
.. "]"
|
||||
|
||||
return listformspec
|
||||
end,
|
||||
@ -682,17 +708,13 @@ smartfs.element("list",{
|
||||
|
||||
smartfs.element("inventory", {
|
||||
build = function(self)
|
||||
return "list["..
|
||||
(self.data.location or "current_player") ..
|
||||
";"..
|
||||
self.name..
|
||||
";"..
|
||||
self.data.pos.x..","..self.data.pos.y..
|
||||
";"..
|
||||
self.data.size.w..","..self.data.size.h..
|
||||
";"..
|
||||
(self.data.index or "") ..
|
||||
"]"
|
||||
return "list["
|
||||
.. (self.data.location or "current_player")
|
||||
.. ";" .. self.name
|
||||
.. ";" .. self.data.pos.x .. "," .. self.data.pos.y
|
||||
.. ";" .. self.data.size.w .. "," .. self.data.size.h
|
||||
.. ";" .. (self.data.index or "")
|
||||
.. "]"
|
||||
end,
|
||||
setPosition = function(self, x, y)
|
||||
self.data.pos = { x = x, y = y }
|
||||
@ -761,3 +783,4 @@ smartfs.element("code",{
|
||||
return self.data.code
|
||||
end
|
||||
})
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user