From 8bea6505f8ca8c86ca246da5dc433a165ba1f8eb Mon Sep 17 00:00:00 2001 From: NatureFreshMilk Date: Fri, 8 Feb 2019 10:28:33 +0100 Subject: [PATCH] borders and labels --- mapserver_mod/mapserver/border.lua | 85 ++++++++++++++++++ mapserver_mod/mapserver/label.lua | 81 +++++++++++++++++ mapserver_mod/mapserver/poi.lua | 20 +---- ...r_digimessage.png => mapserver_border.png} | Bin .../mapserver/textures/mapserver_label.png | Bin 0 -> 291 bytes mapserver_mod/mapserver/train.lua | 34 ++----- server/mapobject/border.go | 18 ++++ server/mapobject/label.go | 19 ++++ server/mapobject/poi.go | 1 - server/mapobject/setup.go | 2 + 10 files changed, 214 insertions(+), 46 deletions(-) create mode 100644 mapserver_mod/mapserver/border.lua create mode 100644 mapserver_mod/mapserver/label.lua rename mapserver_mod/mapserver/textures/{mapserver_digimessage.png => mapserver_border.png} (100%) create mode 100644 mapserver_mod/mapserver/textures/mapserver_label.png create mode 100644 server/mapobject/border.go create mode 100644 server/mapobject/label.go diff --git a/mapserver_mod/mapserver/border.lua b/mapserver_mod/mapserver/border.lua new file mode 100644 index 0000000..d3b4bdb --- /dev/null +++ b/mapserver_mod/mapserver/border.lua @@ -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 + + +}) diff --git a/mapserver_mod/mapserver/label.lua b/mapserver_mod/mapserver/label.lua new file mode 100644 index 0000000..a7b25d1 --- /dev/null +++ b/mapserver_mod/mapserver/label.lua @@ -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 + + +}) diff --git a/mapserver_mod/mapserver/poi.lua b/mapserver_mod/mapserver/poi.lua index 353c984..73ab095 100644 --- a/mapserver_mod/mapserver/poi.lua +++ b/mapserver_mod/mapserver/poi.lua @@ -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", "") 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 diff --git a/mapserver_mod/mapserver/textures/mapserver_digimessage.png b/mapserver_mod/mapserver/textures/mapserver_border.png similarity index 100% rename from mapserver_mod/mapserver/textures/mapserver_digimessage.png rename to mapserver_mod/mapserver/textures/mapserver_border.png diff --git a/mapserver_mod/mapserver/textures/mapserver_label.png b/mapserver_mod/mapserver/textures/mapserver_label.png new file mode 100644 index 0000000000000000000000000000000000000000..84fb0740adfbf4e61db3f653caf9c7509e9fe012 GIT binary patch literal 291 zcmeAS@N?(olHy`uVBq!ia0vp^3LwnE1|*BCs=fdzwj^(N7l!{JxM1({$v_d#0*}aI z1_r*vAk26?e?RI*v(rrr+be>Ii<=Ijc$j~+2NkZ^@@F`q=~ zfeQr=ufJ4TxQQQM#y8!@RWV@h%@aV}arwfvmtR?~2B>mvh-BC-6M6Q8Z_ABKT(Pna zULPhuW%%;r*i=1_EJ49+LpymT>!v9I2_ToefAGNIgYTw`iz=YTcf6go@j%y+Mka=- XrCyA}Tibw6XJGJj^>bP0l+XkK53X?N literal 0 HcmV?d00001 diff --git a/mapserver_mod/mapserver/train.lua b/mapserver_mod/mapserver/train.lua index 0f0a782..b222839 100644 --- a/mapserver_mod/mapserver/train.lua +++ b/mapserver_mod/mapserver/train.lua @@ -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 diff --git a/server/mapobject/border.go b/server/mapobject/border.go new file mode 100644 index 0000000..5a362a4 --- /dev/null +++ b/server/mapobject/border.go @@ -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 +} diff --git a/server/mapobject/label.go b/server/mapobject/label.go new file mode 100644 index 0000000..7ac0ca5 --- /dev/null +++ b/server/mapobject/label.go @@ -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 +} diff --git a/server/mapobject/poi.go b/server/mapobject/poi.go index 4deeb78..259bc61 100644 --- a/server/mapobject/poi.go +++ b/server/mapobject/poi.go @@ -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 diff --git a/server/mapobject/setup.go b/server/mapobject/setup.go index 9b9f520..7ec2279 100644 --- a/server/mapobject/setup.go +++ b/server/mapobject/setup.go @@ -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{})