2019-07-23 13:56:11 +02:00
|
|
|
import { SimulationState } from '../../saving/types/SimulationSave'
|
|
|
|
import { SimulationError } from '../../errors/classes/SimulationError'
|
|
|
|
import { GateTemplate } from '../../simulation/types/GateTemplate'
|
|
|
|
import {
|
|
|
|
simulationInputCount,
|
|
|
|
simulationOutputCount
|
|
|
|
} from './simulationIoCount'
|
|
|
|
import { templateStore } from '../../saving/stores/templateStore'
|
2019-07-23 21:53:59 +02:00
|
|
|
import { toast } from 'react-toastify'
|
|
|
|
import { createToastArguments } from '../../toasts/helpers/createToastArguments'
|
|
|
|
import { CurrentLanguage } from '../../internalisation/stores/currentLanguage'
|
2019-07-23 13:56:11 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Compiles a simulation into a logicGate
|
|
|
|
*
|
|
|
|
* @param simulaton The simulation to compile
|
|
|
|
*/
|
|
|
|
export const compileIc = ({ mode, name, gates }: SimulationState) => {
|
|
|
|
if (mode === 'project') {
|
|
|
|
throw new SimulationError('Cannot compile project')
|
|
|
|
}
|
|
|
|
|
2019-07-23 21:53:59 +02:00
|
|
|
const translation = CurrentLanguage.getTranslation()
|
2019-07-23 13:56:11 +02:00
|
|
|
const inputCount = simulationInputCount(gates)
|
|
|
|
const outputCount = simulationOutputCount(gates)
|
|
|
|
|
|
|
|
const result: DeepPartial<GateTemplate> = {
|
|
|
|
metadata: {
|
|
|
|
name
|
|
|
|
},
|
|
|
|
tags: ['integrated'],
|
|
|
|
pins: {
|
|
|
|
inputs: {
|
|
|
|
count: inputCount
|
|
|
|
},
|
|
|
|
outputs: {
|
|
|
|
count: outputCount
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
templateStore.set(name, result)
|
2019-07-23 21:53:59 +02:00
|
|
|
toast(
|
|
|
|
...createToastArguments(
|
|
|
|
translation.messages.compiledIc(name),
|
|
|
|
'markunread_mailbox'
|
|
|
|
)
|
|
|
|
)
|
2019-07-23 13:56:11 +02:00
|
|
|
}
|