pull even more device data

This commit is contained in:
Rachel Powers
2024-04-14 22:32:22 -07:00
parent eed4f1f429
commit f29f4d7adc
8 changed files with 13585 additions and 53529 deletions

View File

@@ -378,21 +378,36 @@ export type ReagentMode = "Contents" | "Recipe" | "Required" | "TotalContents";
export type BatchMode = "Average" | "Maximum" | "Minimum" | "Sum";
export type DeviceDBEntry = {
export interface DeviceDBEntry {
name: string;
hash: number;
desc: string;
logic?: { [key in LogicType]: FieldType };
slotlogic?: { [key in SlotLogicType]: number[] };
device: boolean;
dynamic: boolean;
logic?: { [key in LogicType]?: FieldType };
slotlogic?: { [key in SlotLogicType]?: number[] };
slots?: { name: string; typ: SlotClass }[];
modes?: { [key: string]: string };
modes?: { [key: number]: string };
conn?: { [key: number]: [NetworkType, ConnectionRole] };
slotclass?: SlotClass;
sorting?: SortingClass;
pins?: number;
reagents?: boolean;
maxquantity?: number;
filtertype?: string;
states?: DBStates;
};
export type DeviceDB = {
export interface DBStates {
activate: boolean;
color: boolean;
lock: boolean;
mode: boolean;
onoff: boolean;
open: boolean;
}
export interface DeviceDB {
logic_enabled: string[];
slot_logic_enabled: string[];
devices: string[];
@@ -404,29 +419,3 @@ export type DeviceDB = {
names_by_hash: { [key: number]: string };
};
export type PreCastDeviceDBEntry = {
name: string;
hash: number;
desc: string;
logic?: { [key in LogicType]?: string };
slotlogic?: { [key in SlotLogicType]?: number[] };
slots?: { name: string; typ: string }[];
modes?: { [key: string]: string };
conn?: { [key: number]: string[] };
slotclass?: string;
sorting?: string;
pins?: number;
};
export type PreCastDeviceDB = {
logic_enabled: string[];
slot_logic_enabled: string[];
devices: string[];
items: string[];
structures: string[];
db: {
[key: string]: PreCastDeviceDBEntry;
};
names_by_hash: { [key: number]: string };
};

View File

@@ -1,5 +1,5 @@
import { DeviceRef, VM, init } from "ic10emu_wasm";
import { DeviceDB, PreCastDeviceDB } from "./device_db";
import { DeviceDB } from "./device_db";
import "./base_device";
declare global {
@@ -22,7 +22,7 @@ class VirtualMachine extends EventTarget {
_ics: Map<number, DeviceRef>;
accessor db: DeviceDB;
dbPromise: Promise<{ default: PreCastDeviceDB }>;
dbPromise: Promise<{ default: DeviceDB }>;
constructor() {
super();
@@ -35,9 +35,11 @@ class VirtualMachine extends EventTarget {
this._devices = new Map();
this._ics = new Map();
this.dbPromise = import("../../../data/database.json");
this.dbPromise = import("../../../data/database.json", {
assert: { type: "json" },
}) as unknown as Promise<{ default: DeviceDB }>;
this.dbPromise.then((module) =>
this.setupDeviceDatabase(module.default as DeviceDB),
this.setupDeviceDatabase(module.default as any as DeviceDB),
);
this.updateDevices();