mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-24 16:23:12 +09:00
Implement recipe overlay
This commit is contained in:
1 parent
cf2efb1380
commit
3b7fd164af
7 files changed
+755
-89
No files matched your search
@@ -1,11 +1,12 @@
|
||||
import React from "react";
|
||||
import { BaseWebPlugin } from "@clusterio/web_ui";
|
||||
import CanvasMinimapPage from "./CanvasMinimapPage";
|
||||
import { TileDataEvent, ChartTagDataEvent } from "../messages";
|
||||
import { TileDataEvent, ChartTagDataEvent, RecipeDataEvent } from "../messages";
|
||||
|
||||
export class WebPlugin extends BaseWebPlugin {
|
||||
tileUpdateCallbacks: Array<(event: TileDataEvent) => void> = [];
|
||||
chartTagUpdateCallbacks: Array<(event: ChartTagDataEvent) => void> = [];
|
||||
recipeUpdateCallbacks: Array<(event: RecipeDataEvent) => void> = [];
|
||||
|
||||
async init() {
|
||||
this.pages = [
|
||||
@@ -20,6 +21,7 @@ export class WebPlugin extends BaseWebPlugin {
|
||||
// Handle tile update events from the controller
|
||||
this.control.handle(TileDataEvent, this.handleTileDataEvent.bind(this));
|
||||
this.control.handle(ChartTagDataEvent, this.handleChartTagDataEvent.bind(this));
|
||||
this.control.handle(RecipeDataEvent, this.handleRecipeDataEvent.bind(this));
|
||||
}
|
||||
|
||||
async handleTileDataEvent(event: TileDataEvent) {
|
||||
@@ -36,6 +38,12 @@ export class WebPlugin extends BaseWebPlugin {
|
||||
}
|
||||
}
|
||||
|
||||
async handleRecipeDataEvent(event: RecipeDataEvent) {
|
||||
for (let callback of this.recipeUpdateCallbacks) {
|
||||
callback(event);
|
||||
}
|
||||
}
|
||||
|
||||
onTileUpdate(callback: (event: TileDataEvent) => void) {
|
||||
this.tileUpdateCallbacks.push(callback);
|
||||
}
|
||||
@@ -59,4 +67,16 @@ export class WebPlugin extends BaseWebPlugin {
|
||||
}
|
||||
this.chartTagUpdateCallbacks.splice(index, 1);
|
||||
}
|
||||
|
||||
onRecipeUpdate(callback: (event: RecipeDataEvent) => void) {
|
||||
this.recipeUpdateCallbacks.push(callback);
|
||||
}
|
||||
|
||||
offRecipeUpdate(callback: (event: RecipeDataEvent) => void) {
|
||||
const index = this.recipeUpdateCallbacks.lastIndexOf(callback);
|
||||
if (index === -1) {
|
||||
throw new Error("callback is not registered");
|
||||
}
|
||||
this.recipeUpdateCallbacks.splice(index, 1);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user