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

File diff suppressed because it is too large Load Diff

View File

@@ -359,12 +359,6 @@ pub enum SlotType {
None = 0,
}
#[derive(Debug, Default, Clone, Serialize, Deserialize)]
pub struct SlotTemplate {
pub name: String,
pub typ: SlotType,
}
#[derive(Debug, Default)]
pub struct Device {
pub id: u32,

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

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();

View File

@@ -3,8 +3,7 @@ import re
from collections import defaultdict
from pathlib import Path
from pprint import pprint
from typing import Any, NotRequired # type: ignore[Any]
from typing import TypedDict
from typing import Any, NotRequired, TypedDict # type: ignore[Any]
class SlotInsert(TypedDict):
@@ -33,6 +32,18 @@ class PediaPage(TypedDict):
SlotClass: NotRequired[str]
SortingClass: NotRequired[str]
DevicesLength: NotRequired[int]
HasReagents: NotRequired[bool]
HasAtmosphere: NotRequired[bool]
HasLockState: NotRequired[bool]
HasOpenState: NotRequired[bool]
HasOnOffState: NotRequired[bool]
HasActivateState: NotRequired[bool]
HasModeState: NotRequired[bool]
HasColorState: NotRequired[bool]
IsDynamic: NotRequired[bool]
IsDevice: NotRequired[bool]
FilterType: NotRequired[str]
MaxQuantity: NotRequired[float]
class Pedia(TypedDict):
@@ -43,6 +54,14 @@ class DBSlot(TypedDict):
name: str
typ: str
class DBPageStates(TypedDict):
lock: NotRequired[bool]
open: NotRequired[bool]
mode: NotRequired[bool]
onoff: NotRequired[bool]
color: NotRequired[bool]
activate: NotRequired[bool]
class DBPage(TypedDict):
name: str
@@ -56,6 +75,13 @@ class DBPage(TypedDict):
slotclass: str | None
sorting: str | None
pins: int | None
dynamic: bool
device: bool
reagents: bool
atmosphere: bool
states: NotRequired[DBPageStates]
filtertype: NotRequired[str]
maxquantity: NotRequired[int]
def extract_all() -> None:
@@ -84,6 +110,18 @@ def extract_all() -> None:
slotclass = page.get("SlotClass", None)
sortingclass = page.get("SortingClass", None)
deviceslength = page.get("DevicesLength", None)
hasRreagents = page.get("HasReagents", None)
hasAtmosphere = page.get("HasAtmosphere", None)
hasLockState = page.get("HasLockState", None)
hasOpenState = page.get("HasOpenState", None)
hasOnOffState = page.get("HasOnOffState", None)
hasActivateState = page.get("HasActivateState", None)
hasModeState = page.get("HasModeState", None)
hasColorState = page.get("HasColorState", None)
isDynamic = page.get("IsDynamic", None)
isDevice = page.get("IsDevice", None)
filterType = page.get("FilterType", None)
maxQuantity = page.get("MaxQuantity", None)
item["name"] = name
item["hash"] = name_hash
@@ -137,10 +175,75 @@ def extract_all() -> None:
for index, [conn_typ, conn_role] in enumerate(connections):
item["conn"][index] = [conn_typ, conn_role]
match hasRreagents:
case None:
item["reagents"] = False
case _:
item["reagents"] = hasRreagents
match hasAtmosphere:
case None:
item["atmosphere"] = False
case _:
item["atmosphere"] = hasAtmosphere
states: DBPageStates = {}
match hasLockState:
case None:
pass
case _:
states["lock"] = hasLockState
match hasOpenState:
case None:
pass
case _:
states["open"] = hasOpenState
match hasModeState:
case None:
pass
case _:
states["mode"] = hasModeState
match hasActivateState:
case None:
pass
case _:
states["activate"] = hasActivateState
match hasOnOffState:
case None:
pass
case _:
states["onoff"] = hasOnOffState
match hasColorState:
case None:
pass
case _:
states["color"] = hasColorState
if len(list(states.keys())) > 0:
item["states"] = states
item["slotclass"] = slotclass
item["sorting"] = sortingclass
item["pins"] = deviceslength
item["dynamic"] = isDynamic is True
item["device"] = isDevice is True
match filterType:
case None:
pass
case _:
item["filtertype"] = filterType
match maxQuantity:
case None:
pass
case _:
item["maxquantity"] = int(maxQuantity)
case _:
print(f"NON-CONFORMING: ")
@@ -154,17 +257,13 @@ def extract_all() -> None:
item["name"] for item in db.values() if item["slotlogic"] is not None
]
devices = [
item["name"]
for item in db.values()
if item["logic"] is not None and item["conn"] is not None
]
devices = [item["name"] for item in db.values() if item["device"] is True]
structures = [
item["name"] for item in db.values() if item["name"].startswith("Structure")
]
items = [item["name"] for item in db.values() if item["name"] not in structures]
items = [item["name"] for item in db.values() if item["dynamic"] is True]
def clean_nones(value: Any) -> Any: # type: ignore[Any]
if isinstance(value, list):
@@ -186,7 +285,9 @@ def extract_all() -> None:
"structures": structures,
"items": items,
"db": db,
"names_by_hash": {page["hash"]: page["name"] for page in db.values()}
"names_by_hash": {
page["hash"]: page["name"] for page in db.values()
},
}
),
f,
@@ -194,6 +295,7 @@ def extract_all() -> None:
sort_keys=True,
)
if __name__ == "__main__":
# extract_logicable()
extract_all()

View File

@@ -3,11 +3,12 @@
"outDir": "./dist/",
"sourceMap": true,
"noImplicitAny": true,
"module": "es2022",
"module": "esnext",
"target": "es2021",
"allowJs": true,
"moduleResolution": "bundler",
"resolveJsonModule": true,
"esModuleInterop": true,
"isolatedModules": true,
"experimentalDecorators": true,
"types": ["@types/wicg-file-system-access", "@types/ace"],