pass along more generated types

This commit is contained in:
Rachel Powers
2024-04-18 15:31:31 -07:00
parent 3f65360811
commit c63a1b3a4f
6 changed files with 52 additions and 125 deletions

View File

@@ -1,6 +1,7 @@
use std::collections::HashSet;
use serde::{Deserialize, Serialize};
use strum_macros::{AsRefStr, EnumIter};
use thiserror::Error;
use itertools::Itertools;
@@ -23,7 +24,9 @@ pub enum Connection {
Other,
}
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[derive(
Debug, Default, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, EnumIter, AsRefStr,
)]
pub enum ConnectionType {
Pipe,
Power,
@@ -39,7 +42,9 @@ pub enum ConnectionType {
None,
}
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[derive(
Debug, Default, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, EnumIter, AsRefStr,
)]
pub enum ConnectionRole {
Input,
Input2,

View File

@@ -48,6 +48,38 @@ fn main() {
let rm_tstype = format!("\nexport type ReagentMode = {};", rm_tsunion);
ts_types.push_str(&rm_tstype);
let sc_tsunion: String = Itertools::intersperse(
ic10emu::device::SortingClass::iter().map(|rm| format!("\"{}\"", rm.as_ref())),
"\n | ".to_owned(),
)
.collect();
let sc_tstype = format!("\nexport type SlotType = {};", sc_tsunion);
ts_types.push_str(&sc_tstype);
let st_tsunion: String = Itertools::intersperse(
ic10emu::device::SlotType::iter().map(|rm| format!("\"{}\"", rm.as_ref())),
"\n | ".to_owned(),
)
.collect();
let st_tstype = format!("\nexport type SortingClass = {};", st_tsunion);
ts_types.push_str(&st_tstype);
let ct_tsunion: String = Itertools::intersperse(
ic10emu::network::ConnectionType::iter().map(|rm| format!("\"{}\"", rm.as_ref())),
"\n | ".to_owned(),
)
.collect();
let ct_tstype = format!("\nexport type ConnectionType = {};", ct_tsunion);
ts_types.push_str(&ct_tstype);
let cr_tsunion: String = Itertools::intersperse(
ic10emu::network::ConnectionRole::iter().map(|rm| format!("\"{}\"", rm.as_ref())),
"\n | ".to_owned(),
)
.collect();
let cr_tstype = format!("\nexport type ConnectionRole = {};", cr_tsunion);
ts_types.push_str(&cr_tstype);
let infile = Path::new("src/types.ts");
let contents = fs::read_to_string(infile).unwrap();

View File

@@ -288,7 +288,7 @@ impl DeviceRef {
self.device.borrow_mut().set_name(name)
}
#[wasm_bindgen(js_name = "setField")]
#[wasm_bindgen(js_name = "setField", skip_typescript)]
pub fn set_field(&self, field: &str, value: f64, force: bool) -> Result<(), JsError> {
let logic_typ = LogicType::from_str(field)?;
let mut device_ref = self.device.borrow_mut();
@@ -296,7 +296,7 @@ impl DeviceRef {
Ok(())
}
#[wasm_bindgen(js_name = "setSlotField")]
#[wasm_bindgen(js_name = "setSlotField", skip_typescript)]
pub fn set_slot_field(&self, slot: f64, field: &str, value: f64, force: bool) -> Result<(), JsError> {
let logic_typ = SlotLogicType::from_str(field)?;
let mut device_ref = self.device.borrow_mut();
@@ -304,7 +304,7 @@ impl DeviceRef {
Ok(())
}
#[wasm_bindgen(js_name = "getSlotField")]
#[wasm_bindgen(js_name = "getSlotField", skip_typescript)]
pub fn get_slot_field(&self, slot: f64, field: &str) -> Result<f64, JsError> {
let logic_typ = SlotLogicType::from_str(field)?;
let device_ref = self.device.borrow_mut();

View File

@@ -7,40 +7,6 @@ export interface LogicField {
export type LogicFields = Map<LogicType, LogicField>;
export type SlotLogicFields = Map<SlotLogicType, LogicField>;
export type SlotType =
| "AccessCard"
| "Appliance"
| "Back"
| "Battery"
| "Blocked"
| "Bottle"
| "Cartridge"
| "Circuitboard"
| "CreditCard"
| "DataDisk"
| "DrillHead"
| "Egg"
| "Entity"
| "Flare"
| "GasCanister"
| "GasFilter"
| "Helmet"
| "Ingot"
| "LiquidBottle"
| "LiquidCanister"
| "Magazine"
| "Ore"
| "Organ"
| "Plant"
| "ProgramableChip"
| "ScanningHead"
| "SensorProcessingUnit"
| "SoundCartridge"
| "Suit"
| "Tool"
| "Torpedo"
| "None";
export interface SlotOccupant {
readonly id: number;
readonly prefab_hash: number;
@@ -156,6 +122,9 @@ export interface DeviceRef {
readonly pins?: Pins;
readonly program?: Program;
getSlotFields(slot: number): SlotLogicFields;
setField(field: LogicType, value: number, force: boolean): void;
setSlotField(slot: number, field: SlotLogicType, value: number, force: boolean): void;
getSlotField(slot: number, field: SlotLogicType): number;
}
export interface SlotOccupantTemplate {
@@ -178,6 +147,6 @@ export interface DeviceTemplate {
fields: { [key in LogicType]?: LogicField };
}
export interface VM {
export interface VMRef {
addDeviceFromTemplate(template: DeviceTemplate): number;
}

View File

@@ -1,85 +1,6 @@
import { LogicType, SlotLogicType } from "ic10emu_wasm";
export type SortingClass =
| "Default"
| "Kits"
| "Tools"
| "Resources"
| "Food"
| "Clothing"
| "Appliances"
| "Atmospherics"
| "Storage"
| "Ores"
| "Ices";
export type SlotClass =
| "None"
| "Helmet"
| "Suit"
| "Back"
| "GasFilter"
| "GasCanister"
| "Motherboard"
| "Circuitboard"
| "DataDisk"
| "Organ"
| "Ore"
| "Plant"
| "Uniform"
| "Entity"
| "Battery"
| "Egg"
| "Belt"
| "Tool"
| "Appliance"
| "Ingot"
| "Torpedo"
| "Cartridge"
| "AccessCard"
| "Magazine"
| "Circuit"
| "Bottle"
| "ProgrammableChip"
| "Glasses"
| "CreditCard"
| "DirtCanister"
| "SensorProcessingUnit"
| "LiquidCanister"
| "LiquidBottle"
| "Wreckage"
| "SoundCartridge"
| "DrillHead"
| "ScanningHead"
| "Flare"
| "Blocked";
export type NetworkType =
| "None"
| "Pipe"
| "Power"
| "Data"
| "Chute"
| "Elevator"
| "PipeLiquid"
| "LandingPad"
| "LaunchPad"
| "PowerAndData"
| "All";
export type ConnectionRole =
| "None"
| "Input"
| "Input2"
| "Output"
| "Output2"
| "Waste";
export type FieldType = "Read" | "Write" | "ReadWrite";
export type ReagentMode = "Contents" | "Recipe" | "Required" | "TotalContents";
export type BatchMode = "Average" | "Maximum" | "Minimum" | "Sum";
import { LogicType, SlotLogicType, SortingClass, SlotType, FieldType, ReagentMode, BatchMode, ConnectionType, ConnectionRole } from "ic10emu_wasm";
export interface DeviceDBItem {
slotclass: SlotClass;
slotclass: SlotType;
sorting: SortingClass;
maxquantity?: number;
filtertype?: string;
@@ -96,7 +17,7 @@ export interface DeviceDBDevice {
}
export interface DeviceDBConnection {
typ: NetworkType;
typ: ConnectionType;
role: ConnectionRole;
name: string;
}
@@ -106,7 +27,7 @@ export interface DeviceDBEntry {
hash: number;
title: string;
desc: string;
slots?: { name: string; typ: SlotClass }[];
slots?: { name: string; typ: SlotType }[];
logic?: { [key in LogicType]?: FieldType };
slotlogic?: { [key in SlotLogicType]?: number[] };
modes?: { [key: number]: string };

View File

@@ -1,4 +1,4 @@
import { DeviceRef, DeviceTemplate, LogicType, SlotLogicType, VM, init } from "ic10emu_wasm";
import { DeviceRef, DeviceTemplate, LogicType, SlotLogicType, VMRef, init } from "ic10emu_wasm";
import { DeviceDB } from "./device_db";
import "./base_device";
@@ -17,7 +17,7 @@ export interface ToastMessage {
}
class VirtualMachine extends EventTarget {
ic10vm: VM;
ic10vm: VMRef;
_devices: Map<number, DeviceRef>;
_ics: Map<number, DeviceRef>;