logic gate button
This commit is contained in:
parent
0c76f3cdf6
commit
e88244bc9d
29 changed files with 518 additions and 107 deletions
src/modules/simulation/classes
|
@ -22,8 +22,11 @@ export interface PinWrapper {
|
|||
value: Pin
|
||||
}
|
||||
|
||||
export type GateFunction = null | ((ctx: Context) => void)
|
||||
|
||||
export interface GateFunctions {
|
||||
activation: null | ((ctx: Context) => void)
|
||||
activation: GateFunction
|
||||
onClick: GateFunction
|
||||
}
|
||||
|
||||
export class Gate {
|
||||
|
@ -37,7 +40,8 @@ export class Gate {
|
|||
public template: GateTemplate
|
||||
|
||||
private functions: GateFunctions = {
|
||||
activation: null
|
||||
activation: null,
|
||||
onClick: null
|
||||
}
|
||||
|
||||
private subscriptions: Subscription[] = []
|
||||
|
@ -53,6 +57,11 @@ export class Gate {
|
|||
'context'
|
||||
)
|
||||
|
||||
this.functions.onClick = toFunction(
|
||||
this.template.code.onClick,
|
||||
'context'
|
||||
)
|
||||
|
||||
this._pins.inputs = Gate.generatePins(
|
||||
this.template.pins.inputs,
|
||||
1,
|
||||
|
@ -77,6 +86,12 @@ export class Gate {
|
|||
}
|
||||
}
|
||||
|
||||
public onClick() {
|
||||
if (this.functions.onClick) {
|
||||
this.functions.onClick(this.getContext())
|
||||
}
|
||||
}
|
||||
|
||||
public dispose() {
|
||||
for (const pin of this.pins) {
|
||||
pin.value.dispose()
|
||||
|
@ -104,7 +119,12 @@ export class Gate {
|
|||
set: (index: number, state: boolean = false) => {
|
||||
return this._pins.outputs[index].state.next(state)
|
||||
},
|
||||
memory: this.memory
|
||||
memory: this.memory,
|
||||
color: (color: string) => {
|
||||
if (this.template.material.type === 'color') {
|
||||
this.template.material.value = color
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue