forked from MTSR/mapserver
borders and labels
This commit is contained in:
parent
386ad832c3
commit
8bea6505f8
85
mapserver_mod/mapserver/border.lua
Normal file
85
mapserver_mod/mapserver/border.lua
Normal file
@ -0,0 +1,85 @@
|
||||
|
||||
local last_index = 0
|
||||
local last_name = ""
|
||||
|
||||
local update_formspec = function(meta)
|
||||
local inv = meta:get_inventory()
|
||||
|
||||
local name = meta:get_string("name")
|
||||
local index = meta:get_string("index")
|
||||
|
||||
meta:set_string("infotext", "Border: Name=" .. name .. ", Index=" .. index)
|
||||
|
||||
meta:set_string("formspec", "size[8,3;]" ..
|
||||
-- col 1
|
||||
"field[0,1;4,1;name;Name;" .. name .. "]" ..
|
||||
"button_exit[4,1;4,1;save;Save]" ..
|
||||
|
||||
-- col 2
|
||||
"field[4,2.5;4,1;index;Index;" .. index .. "]"
|
||||
"")
|
||||
|
||||
end
|
||||
|
||||
|
||||
minetest.register_node("mapserver:border", {
|
||||
description = "Mapserver Border",
|
||||
tiles = {
|
||||
"mapserver_border.png",
|
||||
"mapserver_border.png",
|
||||
"mapserver_border.png",
|
||||
"mapserver_border.png",
|
||||
"mapserver_border.png",
|
||||
"mapserver_border.png"
|
||||
},
|
||||
groups = {cracky=3,oddly_breakable_by_hand=3},
|
||||
sounds = default.node_sound_glass_defaults(),
|
||||
|
||||
can_dig = function(pos, player)
|
||||
local meta = minetest.env:get_meta(pos)
|
||||
local owner = meta:get_string("owner")
|
||||
|
||||
return player and player:get_player_name() == owner
|
||||
end,
|
||||
|
||||
after_place_node = function(pos, placer)
|
||||
local meta = minetest.get_meta(pos)
|
||||
meta:set_string("owner", placer:get_player_name() or "")
|
||||
end,
|
||||
|
||||
on_construct = function(pos)
|
||||
local meta = minetest.get_meta(pos)
|
||||
|
||||
last_index = last_index + 5
|
||||
|
||||
meta:set_string("name", last_name)
|
||||
meta:set_int("index", last_index)
|
||||
|
||||
update_formspec(meta)
|
||||
end,
|
||||
|
||||
on_receive_fields = function(pos, formname, fields, sender)
|
||||
local meta = minetest.get_meta(pos)
|
||||
local playername = sender:get_player_name()
|
||||
|
||||
if playername == meta:get_string("owner") then
|
||||
-- owner
|
||||
if fields.save then
|
||||
last_name = fields.name
|
||||
meta:set_string("name", fields.name)
|
||||
local index = tonumber(fields.index)
|
||||
if index ~= nil then
|
||||
last_index = index
|
||||
meta:set_int("index", index)
|
||||
end
|
||||
end
|
||||
else
|
||||
-- non-owner
|
||||
end
|
||||
|
||||
|
||||
update_formspec(meta)
|
||||
end
|
||||
|
||||
|
||||
})
|
81
mapserver_mod/mapserver/label.lua
Normal file
81
mapserver_mod/mapserver/label.lua
Normal file
@ -0,0 +1,81 @@
|
||||
|
||||
local update_formspec = function(meta)
|
||||
local inv = meta:get_inventory()
|
||||
|
||||
local text = meta:get_string("text")
|
||||
local size = meta:get_string("size")
|
||||
local direction = meta:get_string("direction")
|
||||
|
||||
meta:set_string("infotext", "Label, Text:" .. text .. ", Size:" .. size .. ", Direction:" .. direction)
|
||||
|
||||
meta:set_string("formspec", "size[8,5;]" ..
|
||||
-- col 1
|
||||
"field[0,1;4,1;text;Text;" .. text .. "]" ..
|
||||
"button_exit[4,1;4,1;save;Save]" ..
|
||||
|
||||
-- col 2
|
||||
"field[0,2.5;4,1;size;Size (1-10);" .. size .. "]" ..
|
||||
|
||||
-- col 3
|
||||
"field[0,3.5;8,1;direction;Direction (0-360);" .. direction .. "]" ..
|
||||
"")
|
||||
|
||||
end
|
||||
|
||||
|
||||
minetest.register_node("mapserver:label", {
|
||||
description = "Mapserver Label",
|
||||
tiles = {
|
||||
"mapserver_label.png",
|
||||
"mapserver_label.png",
|
||||
"mapserver_label.png",
|
||||
"mapserver_label.png",
|
||||
"mapserver_label.png",
|
||||
"mapserver_label.png"
|
||||
},
|
||||
groups = {cracky=3,oddly_breakable_by_hand=3},
|
||||
sounds = default.node_sound_glass_defaults(),
|
||||
|
||||
can_dig = function(pos, player)
|
||||
local meta = minetest.env:get_meta(pos)
|
||||
local owner = meta:get_string("owner")
|
||||
|
||||
return player and player:get_player_name() == owner
|
||||
end,
|
||||
|
||||
after_place_node = function(pos, placer)
|
||||
local meta = minetest.get_meta(pos)
|
||||
meta:set_string("owner", placer:get_player_name() or "")
|
||||
end,
|
||||
|
||||
on_construct = function(pos)
|
||||
local meta = minetest.get_meta(pos)
|
||||
|
||||
meta:set_string("text", "")
|
||||
meta:set_string("direction", "0")
|
||||
meta:set_string("size", "1")
|
||||
|
||||
update_formspec(meta)
|
||||
end,
|
||||
|
||||
on_receive_fields = function(pos, formname, fields, sender)
|
||||
local meta = minetest.get_meta(pos)
|
||||
local playername = sender:get_player_name()
|
||||
|
||||
if playername == meta:get_string("owner") then
|
||||
-- owner
|
||||
if fields.save then
|
||||
meta:set_string("text", fields.text)
|
||||
meta:set_string("direction", fields.direction)
|
||||
meta:set_string("size", fields.size)
|
||||
end
|
||||
else
|
||||
-- non-owner
|
||||
end
|
||||
|
||||
|
||||
update_formspec(meta)
|
||||
end
|
||||
|
||||
|
||||
})
|
@ -2,18 +2,11 @@
|
||||
local update_formspec = function(meta)
|
||||
local inv = meta:get_inventory()
|
||||
|
||||
local active = meta:get_int("active") == 1
|
||||
local state = "Inactive"
|
||||
|
||||
if active then
|
||||
state = "Active"
|
||||
end
|
||||
|
||||
local name = meta:get_string("name")
|
||||
local category = meta:get_string("category")
|
||||
local url = meta:get_string("url") or ""
|
||||
|
||||
meta:set_string("infotext", "POI: " .. name .. ", " .. category .. " (" .. state .. ")")
|
||||
meta:set_string("infotext", "POI: " .. name .. ", " .. category)
|
||||
|
||||
meta:set_string("formspec", "size[8,5;]" ..
|
||||
-- col 1
|
||||
@ -22,7 +15,6 @@ local update_formspec = function(meta)
|
||||
|
||||
-- col 2
|
||||
"field[0,2.5;4,1;category;Category;" .. category .. "]" ..
|
||||
"button_exit[4,2;4,1;toggle;Toggle]" ..
|
||||
|
||||
-- col 3
|
||||
"field[0,3.5;8,1;url;URL;" .. url .. "]" ..
|
||||
@ -62,7 +54,6 @@ minetest.register_node("mapserver:poi", {
|
||||
meta:set_string("name", "<unconfigured>")
|
||||
meta:set_string("category", "main")
|
||||
meta:set_string("url", "")
|
||||
meta:set_int("active", 0)
|
||||
|
||||
update_formspec(meta)
|
||||
end,
|
||||
@ -78,15 +69,6 @@ minetest.register_node("mapserver:poi", {
|
||||
meta:set_string("url", fields.url)
|
||||
meta:set_string("category", fields.category)
|
||||
end
|
||||
|
||||
if fields.toggle then
|
||||
if meta:get_int("active") == 1 then
|
||||
meta:set_int("active", 0)
|
||||
else
|
||||
meta:set_int("active", 1)
|
||||
end
|
||||
end
|
||||
|
||||
else
|
||||
-- non-owner
|
||||
end
|
||||
|
Before Width: | Height: | Size: 291 B After Width: | Height: | Size: 291 B |
BIN
mapserver_mod/mapserver/textures/mapserver_label.png
Normal file
BIN
mapserver_mod/mapserver/textures/mapserver_label.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 291 B |
@ -5,18 +5,11 @@ local last_line = ""
|
||||
local update_formspec = function(meta)
|
||||
local inv = meta:get_inventory()
|
||||
|
||||
local active = meta:get_int("active") == 1
|
||||
local state = "Inactive"
|
||||
|
||||
if active then
|
||||
state = "Active"
|
||||
end
|
||||
|
||||
local line = meta:get_string("line")
|
||||
local station = meta:get_string("station")
|
||||
local index = meta:get_string("index")
|
||||
|
||||
meta:set_string("infotext", "Train: Line=" .. line .. ", Station=" .. station .. " (" .. state .. ")")
|
||||
meta:set_string("infotext", "Train: Line=" .. line .. ", Station=" .. station)
|
||||
|
||||
meta:set_string("formspec", "size[8,3;]" ..
|
||||
-- col 1
|
||||
@ -25,10 +18,7 @@ local update_formspec = function(meta)
|
||||
|
||||
-- col 2
|
||||
"field[0,2.5;4,1;station;Station;" .. station .. "]" ..
|
||||
"field[4,2.5;4,1;index;Index;" .. index .. "]" ..
|
||||
|
||||
-- col 3
|
||||
"button_exit[4,3;4,1;toggle;Toggle]" ..
|
||||
"field[4,2.5;4,1;index;Index;" .. index .. "]"
|
||||
"")
|
||||
|
||||
end
|
||||
@ -37,12 +27,12 @@ end
|
||||
minetest.register_node("mapserver:train", {
|
||||
description = "Mapserver Train",
|
||||
tiles = {
|
||||
"tileserver_train.png",
|
||||
"tileserver_train.png",
|
||||
"tileserver_train.png",
|
||||
"tileserver_train.png",
|
||||
"tileserver_train.png",
|
||||
"tileserver_train.png"
|
||||
"mapserver_train.png",
|
||||
"mapserver_train.png",
|
||||
"mapserver_train.png",
|
||||
"mapserver_train.png",
|
||||
"mapserver_train.png",
|
||||
"mapserver_train.png"
|
||||
},
|
||||
groups = {cracky=3,oddly_breakable_by_hand=3},
|
||||
sounds = default.node_sound_glass_defaults(),
|
||||
@ -66,7 +56,6 @@ minetest.register_node("mapserver:train", {
|
||||
|
||||
meta:set_string("station", "")
|
||||
meta:set_string("line", last_line)
|
||||
meta:set_int("active", 1)
|
||||
meta:set_int("index", last_index)
|
||||
|
||||
update_formspec(meta)
|
||||
@ -89,13 +78,6 @@ minetest.register_node("mapserver:train", {
|
||||
end
|
||||
end
|
||||
|
||||
if fields.toggle then
|
||||
if meta:get_int("active") == 1 then
|
||||
meta:set_int("active", 0)
|
||||
else
|
||||
meta:set_int("active", 1)
|
||||
end
|
||||
end
|
||||
else
|
||||
-- non-owner
|
||||
end
|
||||
|
18
server/mapobject/border.go
Normal file
18
server/mapobject/border.go
Normal file
@ -0,0 +1,18 @@
|
||||
package mapobject
|
||||
|
||||
import (
|
||||
"mapserver/mapblockparser"
|
||||
"mapserver/mapobjectdb"
|
||||
)
|
||||
|
||||
type BorderBlock struct{}
|
||||
|
||||
func (this *BorderBlock) onMapObject(x, y, z int, block *mapblockparser.MapBlock) *mapobjectdb.MapObject {
|
||||
md := block.Metadata.GetMetadata(x, y, z)
|
||||
|
||||
o := mapobjectdb.NewMapObject(block.Pos, x, y, z, "border")
|
||||
o.Attributes["name"] = md["name"]
|
||||
o.Attributes["index"] = md["index"]
|
||||
|
||||
return o
|
||||
}
|
19
server/mapobject/label.go
Normal file
19
server/mapobject/label.go
Normal file
@ -0,0 +1,19 @@
|
||||
package mapobject
|
||||
|
||||
import (
|
||||
"mapserver/mapblockparser"
|
||||
"mapserver/mapobjectdb"
|
||||
)
|
||||
|
||||
type LabelBlock struct{}
|
||||
|
||||
func (this *LabelBlock) onMapObject(x, y, z int, block *mapblockparser.MapBlock) *mapobjectdb.MapObject {
|
||||
md := block.Metadata.GetMetadata(x, y, z)
|
||||
|
||||
o := mapobjectdb.NewMapObject(block.Pos, x, y, z, "label")
|
||||
o.Attributes["text"] = md["text"]
|
||||
o.Attributes["size"] = md["size"]
|
||||
o.Attributes["direction"] = md["direction"]
|
||||
|
||||
return o
|
||||
}
|
@ -14,7 +14,6 @@ func (this *PoiBlock) onMapObject(x, y, z int, block *mapblockparser.MapBlock) *
|
||||
o.Attributes["name"] = md["name"]
|
||||
o.Attributes["category"] = md["category"]
|
||||
o.Attributes["url"] = md["url"]
|
||||
o.Attributes["active"] = md["active"]
|
||||
o.Attributes["owner"] = md["owner"]
|
||||
|
||||
return o
|
||||
|
@ -81,6 +81,8 @@ func Setup(ctx *app.App) {
|
||||
//mapserver stuff
|
||||
l.AddMapObject("mapserver:poi", &PoiBlock{})
|
||||
l.AddMapObject("mapserver:train", &TrainBlock{})
|
||||
l.AddMapObject("mapserver:border", &BorderBlock{})
|
||||
l.AddMapObject("mapserver:label", &LabelBlock{})
|
||||
|
||||
//travelnet
|
||||
l.AddMapObject("travelnet:travelnet", &TravelnetBlock{})
|
||||
|
Loading…
Reference in New Issue
Block a user