Switch to custom canvas based map renderer

This commit is contained in:
Danielv123 committed 2025-08-10 00:28:48 +02:00
1 parent 063e622721
commit 3bf7a84de4
5 files changed
+795 -10

No files matched your search

+28 -3
View File
@@ -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);
}
}