mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-23 08:23:12 +09:00
Switch to custom canvas based map renderer
This commit is contained in:
1 parent
063e622721
commit
3bf7a84de4
5 files changed
+795
-10
No files matched your search
@@ -1,16 +1,41 @@
|
||||
import React from "react";
|
||||
import { BaseWebPlugin } from "@clusterio/web_ui";
|
||||
import MinimapPage from "./MinimapPage";
|
||||
import CanvasMinimapPage from "./CanvasMinimapPage";
|
||||
import { ChunkUpdateEvent } from "../messages";
|
||||
|
||||
export class WebPlugin extends BaseWebPlugin {
|
||||
chunkUpdateCallbacks: Array<(event: ChunkUpdateEvent) => void> = [];
|
||||
|
||||
async init() {
|
||||
this.pages = [
|
||||
{
|
||||
path: "/minimap",
|
||||
sidebarName: "Minimap",
|
||||
sidebarName: "Minimap",
|
||||
permission: "minimap.view",
|
||||
content: <MinimapPage />,
|
||||
content: <CanvasMinimapPage />,
|
||||
},
|
||||
];
|
||||
|
||||
// Handle chunk update events from the controller
|
||||
this.control.handle(ChunkUpdateEvent, this.handleChunkUpdateEvent.bind(this));
|
||||
}
|
||||
|
||||
async handleChunkUpdateEvent(event: ChunkUpdateEvent) {
|
||||
// Notify all registered callbacks
|
||||
for (let callback of this.chunkUpdateCallbacks) {
|
||||
callback(event);
|
||||
}
|
||||
}
|
||||
|
||||
onChunkUpdate(callback: (event: ChunkUpdateEvent) => void) {
|
||||
this.chunkUpdateCallbacks.push(callback);
|
||||
}
|
||||
|
||||
offChunkUpdate(callback: (event: ChunkUpdateEvent) => void) {
|
||||
let index = this.chunkUpdateCallbacks.lastIndexOf(callback);
|
||||
if (index === -1) {
|
||||
throw new Error("callback is not registered");
|
||||
}
|
||||
this.chunkUpdateCallbacks.splice(index, 1);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user