Fixed the dounting id bug, now wires are saved corectly, and there are no more duplicate gates
This commit is contained in:
parent
b58aa196a7
commit
56e55bbe0b
|
@ -1,5 +1,4 @@
|
||||||
import { Vector } from "prelude-ts"
|
import { BehaviorSubject, Subscription, timer } from "rxjs";
|
||||||
import { Subject, BehaviorSubject, Subscription, timer } from "rxjs";
|
|
||||||
import { ComponentState, activationContext } from "./interfaces";
|
import { ComponentState, activationContext } from "./interfaces";
|
||||||
import { map, debounce } from "rxjs/operators";
|
import { map, debounce } from "rxjs/operators";
|
||||||
import { Screen } from "../screen.ts";
|
import { Screen } from "../screen.ts";
|
||||||
|
@ -17,7 +16,6 @@ export class Component {
|
||||||
private static store = new ComponentTemplateStore()
|
private static store = new ComponentTemplateStore()
|
||||||
private static screen = new Screen()
|
private static screen = new Screen()
|
||||||
private static wireManager = new WireManager()
|
private static wireManager = new WireManager()
|
||||||
private static lastId = runCounter.get() + 1
|
|
||||||
|
|
||||||
public position = new BehaviorSubject<number[]>(null)
|
public position = new BehaviorSubject<number[]>(null)
|
||||||
public scale = new BehaviorSubject<number[]>(null)
|
public scale = new BehaviorSubject<number[]>(null)
|
||||||
|
@ -46,7 +44,7 @@ export class Component {
|
||||||
this.scale.next(scale)
|
this.scale.next(scale)
|
||||||
|
|
||||||
//set the correct id
|
//set the correct id
|
||||||
this.id = (typeof id === "number") ? id : Component.lastId++
|
this.id = (typeof id === "number") ? id : Component.getId()
|
||||||
|
|
||||||
//load template
|
//load template
|
||||||
const data = Component.store.store.get(template)
|
const data = Component.store.store.get(template)
|
||||||
|
@ -57,8 +55,8 @@ export class Component {
|
||||||
this.inputs = data.inputs
|
this.inputs = data.inputs
|
||||||
this.outputs = data.outputs
|
this.outputs = data.outputs
|
||||||
|
|
||||||
this.inputPins = [...Array(this.inputs)].fill(true).map(val => new Pin(false, this))
|
this.inputPins = [...Array(this.inputs)].fill(true).map(() => new Pin(false, this))
|
||||||
this.outputPins = [...Array(this.outputs)].fill(true).map(val => new Pin(true, this))
|
this.outputPins = [...Array(this.outputs)].fill(true).map(() => new Pin(true, this))
|
||||||
|
|
||||||
this.activation = new Function(`return (ctx) => {
|
this.activation = new Function(`return (ctx) => {
|
||||||
try{
|
try{
|
||||||
|
@ -71,7 +69,7 @@ export class Component {
|
||||||
|
|
||||||
this.inputPins.forEach(val => {
|
this.inputPins.forEach(val => {
|
||||||
const subscription = val.valueChanges.pipe(debounce(() => timer(1000 / 60)))
|
const subscription = val.valueChanges.pipe(debounce(() => timer(1000 / 60)))
|
||||||
.subscribe(val => this.activate())
|
.subscribe(() => this.activate())
|
||||||
this.subscriptions.push(subscription)
|
this.subscriptions.push(subscription)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -204,4 +202,10 @@ export class Component {
|
||||||
static fromState(state: ComponentState) {
|
static fromState(state: ComponentState) {
|
||||||
return new Component(state.template, state.position, state.scale, state.id)
|
return new Component(state.template, state.position, state.scale, state.id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static getId(){
|
||||||
|
const data = runCounter.get()
|
||||||
|
runCounter.increase()
|
||||||
|
return data
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue