From 2c0edb328f5c9d957ab28407f53a95ee433d5917 Mon Sep 17 00:00:00 2001 From: 1F616EMO~nya Date: Fri, 7 Jun 2024 01:23:23 +0800 Subject: [PATCH] Support Phonographs (#376) * Support Phonographs * Fix comment * Add missing import * Fix variable name --- app/config.go | 1 + app/types.go | 1 + doc/license.md | 4 ++++ mapobject/phonograph.go | 24 ++++++++++++++++++++ mapobject/setup.go | 5 ++++ public/js/map/Overlaysetup.js | 7 ++++++ public/js/map/overlays/PhonographOverlay.js | 22 ++++++++++++++++++ public/pics/phonograph_node_temp.png | Bin 0 -> 102 bytes 8 files changed, 64 insertions(+) create mode 100644 mapobject/phonograph.go create mode 100644 public/js/map/overlays/PhonographOverlay.js create mode 100644 public/pics/phonograph_node_temp.png 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 0000000000000000000000000000000000000000..7fb15b72e01dbe52b9c42f989b70cf93e17df828 GIT binary patch literal 102 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!93?!50ihlx9oB=)|uBxi4(UEp#eU2CS<0OEB y5}q!OAsp9}6Brn`ZrLKjc5K^$ literal 0 HcmV?d00001