use full vm state to restore backwards compatable links
This commit is contained in:
@@ -113,7 +113,43 @@ impl SlotOccupant {
|
||||
|
||||
/// chainable constructor
|
||||
pub fn get_fields(&self) -> HashMap<SlotLogicType, LogicField> {
|
||||
self.fields.clone()
|
||||
let mut copy = self.fields.clone();
|
||||
copy.insert(
|
||||
SlotLogicType::PrefabHash,
|
||||
LogicField {
|
||||
field_type: FieldType::Read,
|
||||
value: self.prefab_hash as f64,
|
||||
},
|
||||
);
|
||||
copy.insert(
|
||||
SlotLogicType::SortingClass,
|
||||
LogicField {
|
||||
field_type: FieldType::Read,
|
||||
value: self.sorting_class as u32 as f64,
|
||||
},
|
||||
);
|
||||
copy.insert(
|
||||
SlotLogicType::Quantity,
|
||||
LogicField {
|
||||
field_type: FieldType::Read,
|
||||
value: self.quantity as f64,
|
||||
},
|
||||
);
|
||||
copy.insert(
|
||||
SlotLogicType::MaxQuantity,
|
||||
LogicField {
|
||||
field_type: FieldType::Read,
|
||||
value: self.max_quantity as f64,
|
||||
},
|
||||
);
|
||||
copy.insert(
|
||||
SlotLogicType::Damage,
|
||||
LogicField {
|
||||
field_type: FieldType::Read,
|
||||
value: self.damage,
|
||||
},
|
||||
);
|
||||
copy
|
||||
}
|
||||
|
||||
pub fn set_field(
|
||||
@@ -574,10 +610,11 @@ impl Device {
|
||||
},
|
||||
),
|
||||
]);
|
||||
let occupant = SlotOccupant::new(ic, -744098481);
|
||||
device.slots.push(Slot::with_occupant(
|
||||
SlotType::ProgrammableChip,
|
||||
// -744098481 = ItemIntegratedCircuit10
|
||||
SlotOccupant::new(ic, -744098481),
|
||||
occupant,
|
||||
));
|
||||
|
||||
device
|
||||
|
||||
@@ -53,7 +53,7 @@ fn main() {
|
||||
"\n | ".to_owned(),
|
||||
)
|
||||
.collect();
|
||||
let sc_tstype = format!("\nexport type SlotType = {};", sc_tsunion);
|
||||
let sc_tstype = format!("\nexport type SortingClass = {};", sc_tsunion);
|
||||
ts_types.push_str(&sc_tstype);
|
||||
|
||||
let st_tsunion: String = Itertools::intersperse(
|
||||
@@ -61,7 +61,7 @@ fn main() {
|
||||
"\n | ".to_owned(),
|
||||
)
|
||||
.collect();
|
||||
let st_tstype = format!("\nexport type SortingClass = {};", st_tsunion);
|
||||
let st_tstype = format!("\nexport type SlotType = {};", st_tsunion);
|
||||
ts_types.push_str(&st_tstype);
|
||||
|
||||
let ct_tsunion: String = Itertools::intersperse(
|
||||
|
||||
@@ -152,7 +152,7 @@ export interface FrozenIC {
|
||||
id: number;
|
||||
registers: number[];
|
||||
ip: number;
|
||||
ic: number[];
|
||||
ic: number;
|
||||
stack: number[];
|
||||
aliases: Aliases;
|
||||
defines: Defines;
|
||||
|
||||
137
www/src/ts/presets/demo.ts
Normal file
137
www/src/ts/presets/demo.ts
Normal file
@@ -0,0 +1,137 @@
|
||||
import { VMState } from "../session";
|
||||
|
||||
export const demoCode = `# Highlighting Demo
|
||||
|
||||
# This is a comment
|
||||
|
||||
# Hover a define id anywhere to see it's definition
|
||||
define a_def 10
|
||||
|
||||
# Hover HASH("String")'s to see computed crc32
|
||||
# hover here vvvvvvvvvvvvvvvv
|
||||
define a_hash HASH("This is a String")
|
||||
|
||||
# hover over an alias anywhere in the code
|
||||
# to see it's definition
|
||||
alias a_var r0
|
||||
alias a_device d0
|
||||
|
||||
# instructions have Auto Completion,
|
||||
# numeric logic types are identified on hover
|
||||
s db 12 0
|
||||
# ^^
|
||||
# hover here
|
||||
|
||||
# Enums and their values are Known, Hover them!
|
||||
# vvvvvvvvvvvvvvvvvv
|
||||
move r2 LogicType.Temperature
|
||||
push r2
|
||||
|
||||
# same with constants
|
||||
# vvvv
|
||||
move r3 pinf
|
||||
|
||||
# Labels are known
|
||||
main:
|
||||
l r1 dr15 RatioWater
|
||||
move r2 100000.001
|
||||
push r2
|
||||
|
||||
# Hover Hash Strings of Known prefab names
|
||||
# to get their documentation
|
||||
# vvvvvvvvvvvvvvv
|
||||
move r0 HASH("AccessCardBlack")
|
||||
push r0
|
||||
beqzal r1 test
|
||||
|
||||
# -2045627372 is the crc32 hash of a SolarPanel,
|
||||
# hover it to see the documentation!
|
||||
# vvvvvvvvvv
|
||||
move r1 -2045627372
|
||||
jal test
|
||||
move r1 $FF
|
||||
push r1
|
||||
beqzal 0 test
|
||||
move r1 %1000
|
||||
push r1
|
||||
yield
|
||||
j main
|
||||
|
||||
test:
|
||||
add r15 r15 1
|
||||
j ra
|
||||
|
||||
`;
|
||||
|
||||
export const demoVMState: VMState = {
|
||||
vm: {
|
||||
ics: [
|
||||
{
|
||||
device: 1,
|
||||
id: 2,
|
||||
registers: Array(18).fill(0),
|
||||
ip: 0,
|
||||
ic: 0,
|
||||
stack: Array(512).fill(0),
|
||||
aliases: new Map(),
|
||||
defines: new Map(),
|
||||
pins: Array(6).fill(undefined),
|
||||
state: "Start",
|
||||
code: demoCode,
|
||||
},
|
||||
],
|
||||
devices: [
|
||||
{
|
||||
id: 1,
|
||||
prefab_name: "StructureCircuitHousing",
|
||||
slots: [
|
||||
{
|
||||
typ: "ProgrammableChip",
|
||||
occupant: {
|
||||
id: 2,
|
||||
fields: {
|
||||
"Quantity":{
|
||||
field_type: "Read",
|
||||
value: 1
|
||||
},
|
||||
"MaxQuantity": {
|
||||
field_type: "Read",
|
||||
value: 1,
|
||||
},
|
||||
"SortingClass": {
|
||||
field_type: "Read",
|
||||
value: 0,
|
||||
}
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
connections: [
|
||||
{
|
||||
CableNetwork: {
|
||||
net: 1,
|
||||
typ: "Data",
|
||||
},
|
||||
},
|
||||
{
|
||||
CableNetwork: {
|
||||
net: undefined,
|
||||
typ: "Power",
|
||||
},
|
||||
},
|
||||
],
|
||||
fields: {},
|
||||
},
|
||||
],
|
||||
networks: [
|
||||
{
|
||||
id: 1,
|
||||
devices: [1],
|
||||
power_only: [],
|
||||
channels: Array(8).fill(NaN),
|
||||
},
|
||||
],
|
||||
default_network: 1,
|
||||
},
|
||||
activeIC: 1,
|
||||
};
|
||||
3
www/src/ts/presets/index.ts
Normal file
3
www/src/ts/presets/index.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
import { demoVMState } from "./demo";
|
||||
|
||||
export { demoVMState };
|
||||
@@ -1,71 +1,13 @@
|
||||
const demoCode = `# Highlighting Demo
|
||||
# This is a comment
|
||||
|
||||
# Hover a define id anywhere to see it's definition
|
||||
define a_def 10
|
||||
|
||||
# Hover HASH("String")'s to see computed crc32
|
||||
# hover here vvvvvvvvvvvvvvvv
|
||||
define a_hash HASH("This is a String")
|
||||
|
||||
# hover over an alias anywhere in the code
|
||||
# to see it's definition
|
||||
alias a_var r0
|
||||
alias a_device d0
|
||||
|
||||
# instructions have Auto Completion,
|
||||
# numeric logic types are identified on hover
|
||||
s db 12 0
|
||||
# ^^
|
||||
# hover here
|
||||
|
||||
# Enums and their values are Known, Hover them!
|
||||
# vvvvvvvvvvvvvvvvvv
|
||||
move r2 LogicType.Temperature
|
||||
push r2
|
||||
|
||||
# same with constants
|
||||
# vvvv
|
||||
move r3 pinf
|
||||
|
||||
# Labels are known
|
||||
main:
|
||||
l r1 dr15 RatioWater
|
||||
move r2 100000.001
|
||||
push r2
|
||||
|
||||
# Hover Hash Strings of Known prefab names
|
||||
# to get their documentation
|
||||
# vvvvvvvvvvvvvvv
|
||||
move r0 HASH("AccessCardBlack")
|
||||
push r0
|
||||
beqzal r1 test
|
||||
|
||||
# -2045627372 is the crc32 hash of a SolarPanel,
|
||||
# hover it to see the documentation!
|
||||
# vvvvvvvvvv
|
||||
move r1 -2045627372
|
||||
jal test
|
||||
move r1 $FF
|
||||
push r1
|
||||
beqzal 0 test
|
||||
move r1 %1000
|
||||
push r1
|
||||
yield
|
||||
j main
|
||||
|
||||
test:
|
||||
add r15 r15 1
|
||||
j ra
|
||||
|
||||
`;
|
||||
|
||||
import type { ICError, FrozenVM } from "ic10emu_wasm";
|
||||
import type { ICError, FrozenVM, SlotType } from "ic10emu_wasm";
|
||||
import { App } from "./app";
|
||||
|
||||
import { openDB, DBSchema } from 'idb';
|
||||
import { openDB, DBSchema } from "idb";
|
||||
import { fromJson, toJson } from "./utils";
|
||||
|
||||
import * as presets from "./presets";
|
||||
const { demoVMState } = presets;
|
||||
|
||||
const LOCAL_DB_VERSION = 1;
|
||||
|
||||
export class Session extends EventTarget {
|
||||
@@ -207,10 +149,14 @@ export class Session extends EventTarget {
|
||||
|
||||
async load(data: VMState | OldPrograms | string) {
|
||||
if (typeof data === "string") {
|
||||
this._activeIC = 1;
|
||||
this.app.vm.restoreVMState(demoVMState.vm);
|
||||
this._programs = new Map([[1, data]]);
|
||||
} else if ( "programs" in data) {
|
||||
} else if ("programs" in data) {
|
||||
this._activeIC = 1;
|
||||
this.app.vm.restoreVMState(demoVMState.vm);
|
||||
this._programs = new Map(data.programs);
|
||||
} else if ( "vm" in data ) {
|
||||
} else if ("vm" in data) {
|
||||
this._programs = new Map();
|
||||
const state = data.vm;
|
||||
// assign first so it's present when the
|
||||
@@ -227,7 +173,7 @@ export class Session extends EventTarget {
|
||||
async loadFromFragment() {
|
||||
const fragment = window.location.hash.slice(1);
|
||||
if (fragment === "demo") {
|
||||
this.load(demoCode);
|
||||
this.load(demoVMState);
|
||||
return;
|
||||
}
|
||||
if (fragment.length > 0) {
|
||||
@@ -257,9 +203,9 @@ export class Session extends EventTarget {
|
||||
upgrade(db, oldVersion, newVersion, transaction, event) {
|
||||
// only db verison currently known is v1
|
||||
if (oldVersion < 1) {
|
||||
const sessionStore = db.createObjectStore('sessions');
|
||||
sessionStore.createIndex('by-date', 'date');
|
||||
sessionStore.createIndex('by-name', 'name');
|
||||
const sessionStore = db.createObjectStore("sessions");
|
||||
sessionStore.createIndex("by-date", "date");
|
||||
sessionStore.createIndex("by-name", "name");
|
||||
}
|
||||
},
|
||||
});
|
||||
@@ -271,14 +217,17 @@ export class Session extends EventTarget {
|
||||
activeIC: this.activeIC,
|
||||
};
|
||||
const db = await this.openIndexDB();
|
||||
const transaction = db.transaction(['sessions'], "readwrite");
|
||||
const transaction = db.transaction(["sessions"], "readwrite");
|
||||
const sessionStore = transaction.objectStore("sessions");
|
||||
await sessionStore.put({
|
||||
await sessionStore.put(
|
||||
{
|
||||
name,
|
||||
date: new Date(),
|
||||
session: state,
|
||||
},
|
||||
name,
|
||||
date: new Date(),
|
||||
session: state,
|
||||
}, name);
|
||||
this.dispatchEvent(new CustomEvent("sessions-local-update"))
|
||||
);
|
||||
this.dispatchEvent(new CustomEvent("sessions-local-update"));
|
||||
}
|
||||
|
||||
async loadFromLocal(name: string) {
|
||||
@@ -292,14 +241,14 @@ export class Session extends EventTarget {
|
||||
|
||||
async deleteLocalSave(name: string) {
|
||||
const db = await this.openIndexDB();
|
||||
const transaction = db.transaction(['sessions'], "readwrite");
|
||||
const transaction = db.transaction(["sessions"], "readwrite");
|
||||
const sessionStore = transaction.objectStore("sessions");
|
||||
await sessionStore.delete(name);
|
||||
this.dispatchEvent(new CustomEvent("sessions-local-update"))
|
||||
this.dispatchEvent(new CustomEvent("sessions-local-update"));
|
||||
}
|
||||
async getLocalSaved() {
|
||||
const db = await this.openIndexDB();
|
||||
const sessions = await db.getAll('sessions');
|
||||
const sessions = await db.getAll("sessions");
|
||||
return sessions;
|
||||
}
|
||||
}
|
||||
@@ -316,16 +265,16 @@ interface AppDBSchemaV1 extends DBSchema {
|
||||
name: string;
|
||||
date: Date;
|
||||
session: VMState;
|
||||
}
|
||||
indexes: {
|
||||
'by-date': Date;
|
||||
'by-name': string;
|
||||
};
|
||||
}
|
||||
indexes: {
|
||||
"by-date": Date;
|
||||
"by-name": string;
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
export interface OldPrograms {
|
||||
programs: [number, string][]
|
||||
programs: [number, string][];
|
||||
}
|
||||
|
||||
const byteToHex: string[] = [];
|
||||
|
||||
@@ -165,6 +165,8 @@ export class VMDeviceCard extends VMDeviceMixin(BaseElement) {
|
||||
@state()
|
||||
set deviceDB(val: DeviceDB) {
|
||||
this._deviceDB = val;
|
||||
this.updateDevice();
|
||||
this.requestUpdate();
|
||||
}
|
||||
|
||||
connectedCallback(): void {
|
||||
|
||||
Reference in New Issue
Block a user