Support Phonographs (#376)

* Support Phonographs

* Fix comment

* Add missing import

* Fix variable name
This commit is contained in:
1F616EMO~nya 2024-06-07 01:23:23 +08:00 committed by GitHub
parent cbf58dfbf8
commit 2c0edb328f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 64 additions and 0 deletions

View File

@ -88,6 +88,7 @@ func ParseConfig(filename string) (*Config, error) {
Locator: false,
Signs: true,
MapserverAirutils: true,
Phonograph: true,
}
mapblockaccessor := MapBlockAccessorConfig{

View File

@ -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 {

View File

@ -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/)

24
mapobject/phonograph.go Normal file
View File

@ -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
}

View File

@ -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)
}

View File

@ -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);
}
}
}

View File

@ -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 "<h4>Phonograph</h4><br>" +
"<b>Now playing:</b> <i>" + HtmlSanitizer.SanitizeHtml(obj.attributes.song_title) + "</i> by " +
HtmlSanitizer.SanitizeHtml(obj.attributes.song_artist);
}
});

Binary file not shown.

After

Width:  |  Height:  |  Size: 102 B