mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-17 15:33:12 +09:00
Add chart tag support
Also fixes react state management issues, moving a few things over to useRef and showing all instances instead of using a custom solution
This commit is contained in:
1 parent
f5aeaff256
commit
fc466ec799
8 files changed
+843
-189
No files matched your search
@@ -1,6 +1,6 @@
|
||||
import * as lib from "@clusterio/lib";
|
||||
import { BaseInstancePlugin } from "@clusterio/host";
|
||||
import { TileDataEvent, ChartData } from "./messages";
|
||||
import { TileDataEvent, ChartData, ChartTagDataEvent, ChartTagData } from "./messages";
|
||||
|
||||
interface TileDataIpc {
|
||||
type: "chart";
|
||||
@@ -9,6 +9,18 @@ interface TileDataIpc {
|
||||
tick: number;
|
||||
}
|
||||
|
||||
interface ChartTagDataIpc {
|
||||
tag_number: number;
|
||||
start_tick: number | null;
|
||||
end_tick: number | null;
|
||||
force: string;
|
||||
surface: string;
|
||||
position: [number, number];
|
||||
text: string;
|
||||
icon: string | null;
|
||||
last_user: string | null;
|
||||
}
|
||||
|
||||
export class InstancePlugin extends BaseInstancePlugin {
|
||||
pendingTileUpdates = new Map<string, Set<[number, number, [number, number, number, number]]>>();
|
||||
|
||||
@@ -23,6 +35,13 @@ export class InstancePlugin extends BaseInstancePlugin {
|
||||
`Error handling tile data from Lua:\n${err}`
|
||||
));
|
||||
});
|
||||
|
||||
// Listen for chart tag data from the Lua module
|
||||
this.instance.server.on("ipc-minimap:chart_tag_data", (data: ChartTagDataIpc) => {
|
||||
this.handleChartTagDataFromLua(data).catch(err => this.logger.error(
|
||||
`Error handling chart tag data from Lua:\n${err}`
|
||||
));
|
||||
});
|
||||
}
|
||||
|
||||
async handleTileDataFromLua(data: TileDataIpc) {
|
||||
@@ -57,6 +76,23 @@ export class InstancePlugin extends BaseInstancePlugin {
|
||||
}
|
||||
}
|
||||
|
||||
async handleChartTagDataFromLua(data: ChartTagDataIpc) {
|
||||
// Validate the chart tag data
|
||||
if (!data || typeof data.tag_number !== 'number') {
|
||||
this.logger.error("Invalid chart tag data received");
|
||||
return;
|
||||
}
|
||||
|
||||
// Create chart tag data event
|
||||
const chartTagEvent = new ChartTagDataEvent(
|
||||
this.instance.config.get("instance.id"),
|
||||
data as ChartTagData
|
||||
);
|
||||
|
||||
// Send to controller
|
||||
return this.instance.sendTo("controller", chartTagEvent);
|
||||
}
|
||||
|
||||
async onStart() {
|
||||
// Initialize the Lua module when the instance starts
|
||||
try {
|
||||
|
||||
Reference in new issue
Block a user