diff --git a/app/config.go b/app/config.go index a2b5675..94f9789 100644 --- a/app/config.go +++ b/app/config.go @@ -88,6 +88,7 @@ func ParseConfig(filename string) (*Config, error) { Locator: false, Signs: true, MapserverAirutils: true, + Phonograph: true, } mapblockaccessor := MapBlockAccessorConfig{ diff --git a/app/types.go b/app/types.go index df542de..760099e 100644 --- a/app/types.go +++ b/app/types.go @@ -64,6 +64,7 @@ type MapObjectConfig struct { Locator bool `json:"locator"` Signs bool `json:"signs"` MapserverAirutils bool `json:"mapserver_airutils"` + Phonograph bool `json:"phonograph"` } type WebApiConfig struct { diff --git a/doc/license.md b/doc/license.md index c40f38b..d3d1ec8 100644 --- a/doc/license.md +++ b/doc/license.md @@ -72,3 +72,7 @@ * unifieddyes_palette_extended.png * GPL 2.0 * Source: https://gitlab.com/VanessaE/unifieddyes + +* phonograph_node_temp.png + * License: CC By-SA 4.0 + * Source: [phonograph](https://github.com/C-C-Minetest-Server/phonograph/) diff --git a/mapobject/phonograph.go b/mapobject/phonograph.go new file mode 100644 index 0000000..c34864d --- /dev/null +++ b/mapobject/phonograph.go @@ -0,0 +1,24 @@ +package mapobject + +import ( + "mapserver/mapobjectdb" + "mapserver/types" + + "github.com/minetest-go/mapparser" +) + +type Phonograph struct{} + +func (this *Phonograph) onMapObject(mbpos *types.MapBlockCoords, x, y, z int, block *mapparser.MapBlock) *mapobjectdb.MapObject { + md := block.Metadata.GetMetadata(x, y, z) + + if _, ok := md["song_title"]; !ok { + return nil + } + + o := mapobjectdb.NewMapObject(mbpos, x, y, z, "phonograph") + o.Attributes["song_title"] = md["song_title"] + o.Attributes["song_artist"] = md["song_artist"] + + return o +} diff --git a/mapobject/setup.go b/mapobject/setup.go index d502659..d5d215f 100644 --- a/mapobject/setup.go +++ b/mapobject/setup.go @@ -192,5 +192,10 @@ func Setup(ctx *app.App) { l.AddMapObject("default:sign_wall_steel", &SignBlock{Material: "steel"}) } + //Phonograph + if ctx.Config.MapObjects.Phonograph { + l.AddMapObject("phonograph:phonograph", &Phonograph{}) + } + ctx.MapBlockAccessor.Eventbus.AddListener(&l) } diff --git a/public/js/map/Overlaysetup.js b/public/js/map/Overlaysetup.js index c155dd3..094a318 100644 --- a/public/js/map/Overlaysetup.js +++ b/public/js/map/Overlaysetup.js @@ -23,6 +23,7 @@ import TrainOverlay from './overlays/TrainOverlay.js'; import TrainsignalOverlay from './overlays/TrainsignalOverlay.js'; import SignOverlay from './overlays/SignOverlay.js'; import AirUtilsPlanesOverlay from "./overlays/AirUtilsPlanesOverlay.js"; +import PhonographOverlay from "./overlays/PhonographOverlay.js"; export default function(cfg, map, overlays, wsChannel){ @@ -207,4 +208,10 @@ export default function(cfg, map, overlays, wsChannel){ } } + if (cfg.mapobjects.phonograph) { + overlays.Phonographs = new PhonographOverlay(); + if (isDefault("phonograph")) { + map.addLayer(overlays.Phonographs); + } + } } diff --git a/public/js/map/overlays/PhonographOverlay.js b/public/js/map/overlays/PhonographOverlay.js new file mode 100644 index 0000000..feb485d --- /dev/null +++ b/public/js/map/overlays/PhonographOverlay.js @@ -0,0 +1,22 @@ +import AbstractIconOverlay from './AbstractIconOverlay.js'; +import {HtmlSanitizer} from '../../lib/HtmlSanitizer.js'; + +var PhonographIcon = L.icon({ + iconUrl: 'pics/phonograph_node_temp.png', + + iconSize: [16, 16], + iconAnchor: [8, 8], + popupAnchor: [0, -16] +}); + +export default AbstractIconOverlay.extend({ + initialize: function() { + AbstractIconOverlay.prototype.initialize.call(this, "phonograph", PhonographIcon); + }, + + createPopup: function(obj){ + return "

Phonograph


" + + "Now playing: " + HtmlSanitizer.SanitizeHtml(obj.attributes.song_title) + " by " + + HtmlSanitizer.SanitizeHtml(obj.attributes.song_artist); + } +}); diff --git a/public/pics/phonograph_node_temp.png b/public/pics/phonograph_node_temp.png new file mode 100644 index 0000000..7fb15b7 Binary files /dev/null and b/public/pics/phonograph_node_temp.png differ