diff --git a/build.js b/build.js index 83d8394..4691a3a 100644 --- a/build.js +++ b/build.js @@ -4,13 +4,13 @@ import { sassPlugin } from 'esbuild-sass-plugin' import * as fs from 'fs' const serve = process.env.ESBUILD_SERVE === '1' -const baseurl = process.env.ESBUILD_BASEURL +const baseurl = process.env.ESBUILD_BASEURL || '/' console.log(`Building with baseurl ${baseurl}`) const ctx = await esbuild.context({ entryPoints: ['src/index.ts'], - minify: !serve, + minify: true, bundle: true, metafile: true, splitting: true, diff --git a/src/modules/core/helpers/logWelcome.ts b/src/modules/core/helpers/logWelcome.ts index bf58a53..77c6b1d 100644 --- a/src/modules/core/helpers/logWelcome.ts +++ b/src/modules/core/helpers/logWelcome.ts @@ -1,23 +1,22 @@ /** - * In case the guys who look at my projet open the console -_- + * In case the people who look at my projet open the console -_- */ export const logWelcome = () => { - const commonStyles = 'padding: 3px' - const titleStyles = `font-size: 3em;` + const commonStyles = 'padding: 3px' + const titleStyles = `font-size: 3em;` - // console.log('%c Hello!',` `${titleStyles}) - console.log( - `%c Hello + console.log( + `%c Hello %c I don't know if you see this, but if you do than you are probably wondering... Why did I include this? The answer is - I don't know. At first, it seemed like a good idea to include a welcome message in the console (in case someone randomly openes it), but now i don't even know what i'm doing :) Anyways, I hope you are having a good time in my simulator!!!` - .split('\n') - .map(s => s.trim()) - .join(' '), - `${titleStyles}`, - `${commonStyles}` - ) + .split('\n') + .map((s) => s.trim()) + .join(' '), + `${titleStyles}`, + `${commonStyles}` + ) } diff --git a/src/modules/logic-gates/components/LogicGatesPage.tsx b/src/modules/logic-gates/components/LogicGatesPage.tsx index 04ed657..4d34f78 100644 --- a/src/modules/logic-gates/components/LogicGatesPage.tsx +++ b/src/modules/logic-gates/components/LogicGatesPage.tsx @@ -10,31 +10,29 @@ import LogicGate from './LogicGate' * The component containing the info / actions about all logic gates */ const LogicGatePage = () => { - const gates = useObservable(() => LogicGateList, []) - const renderer = getRendererSafely() - console.log('got this far') + const gates = useObservable(() => LogicGateList, []) + const renderer = getRendererSafely() - return ( -
-
-
- {gates - .map(getTemplateSafely) - .sort((a, b) => a.category - b.category) - .filter((template) => { - return ( - renderer.simulation.mode === 'project' || - template.metadata.name !== - renderer.simulation.name - ) - }) - .map((template, index) => { - return - })} -
-
-
- ) + return ( +
+
+
+ {gates + .map(getTemplateSafely) + .sort((a, b) => a.category - b.category) + .filter((template) => { + return ( + renderer.simulation.mode === 'project' || + template.metadata.name !== renderer.simulation.name + ) + }) + .map((template, index) => { + return + })} +
+
+
+ ) } export default LogicGatePage diff --git a/src/modules/simulation/classes/Wire.ts b/src/modules/simulation/classes/Wire.ts index dbadc39..f34f749 100644 --- a/src/modules/simulation/classes/Wire.ts +++ b/src/modules/simulation/classes/Wire.ts @@ -3,35 +3,30 @@ import { PinWrapper } from './Gate' import { SimulationError } from '../../errors/classes/SimulationError' export class Wire { - public id: number - public active = true + public id: number + public active = true - public constructor( - public start: PinWrapper, - public end: PinWrapper, - ic: boolean = false, - id?: number - ) { - if (!ic && end.value.pairs.size !== 0) { - throw new SimulationError('An input pin can only have 1 pair') - } - - end.value.addPair(start.value, true, !ic) - start.value.addPair(end.value, false, !ic) - - // if (ic) { - // start.value.state.subscribe(console.log) - // end.value.state.subscribe(console.log) - // } - - this.id = id !== undefined ? id : idStore.generate() + public constructor( + public start: PinWrapper, + public end: PinWrapper, + ic: boolean = false, + id?: number + ) { + if (!ic && end.value.pairs.size !== 0) { + throw new SimulationError('An input pin can only have 1 pair') } - public dispose() { - this.end.value.removePair(this.start.value) - this.start.value.removePair(this.end.value) - this.end.value.state.next("0") + end.value.addPair(start.value, true, !ic) + start.value.addPair(end.value, false, !ic) - this.active = false - } + this.id = id !== undefined ? id : idStore.generate() + } + + public dispose() { + this.end.value.removePair(this.start.value) + this.start.value.removePair(this.end.value) + this.end.value.state.next('0') + + this.active = false + } } diff --git a/src/modules/simulationRenderer/helpers/pinFill.ts b/src/modules/simulationRenderer/helpers/pinFill.ts index 17619a8..0b1f456 100644 --- a/src/modules/simulationRenderer/helpers/pinFill.ts +++ b/src/modules/simulationRenderer/helpers/pinFill.ts @@ -3,28 +3,26 @@ import { SimulationRenderer } from '../classes/SimulationRenderer' import { fromHexColorString, fromChunks } from '../../colors/helpers/fromHex' export const pinFill = (renderer: SimulationRenderer, pin: Pin) => { - let color = 'rgba(0,0,0,0)' + let color = 'rgba(0,0,0,0)' - if (pin.pairs.size) { - const { open, closed } = renderer.options.gates.pinFill - const digits = Array.from(pin.state.value).map(Number) + if (pin.pairs.size) { + const { open, closed } = renderer.options.gates.pinFill + const digits = Array.from(pin.state.value).map(Number) - const colors = digits.map(digit => (digit ? open : closed)) - const chunked = colors.map(fromHexColorString) + const colors = digits.map((digit) => (digit ? open : closed)) + const chunked = colors.map(fromHexColorString) - const summed = [0, 1, 2] - .map(key => - chunked - .flat() - .filter((v, index) => index % 3 === key) - .reduce((acc, curr) => acc + curr, 0) - ) - .map(value => Math.floor(value / digits.length)) + const summed = [0, 1, 2] + .map((key) => + chunked + .flat() + .filter((v, index) => index % 3 === key) + .reduce((acc, curr) => acc + curr, 0) + ) + .map((value) => Math.floor(value / digits.length)) - color = fromChunks(summed) + color = fromChunks(summed) + } - // console.log(color) - } - - return color + return color } diff --git a/src/modules/simulationRenderer/helpers/scaleCanvas.ts b/src/modules/simulationRenderer/helpers/scaleCanvas.ts index 663e709..e61f1b2 100644 --- a/src/modules/simulationRenderer/helpers/scaleCanvas.ts +++ b/src/modules/simulationRenderer/helpers/scaleCanvas.ts @@ -20,28 +20,29 @@ b * (a - x0) = a - x1 x1 = a - b * (a - x0) */ export const handleScroll = (e: WheelEvent, camera: Camera) => { - const sign = -e.deltaY / Math.abs(e.deltaY) - const zoom = scrollStep ** sign + console.log('got here') + const sign = -e.deltaY / Math.abs(e.deltaY) + const zoom = scrollStep ** sign - if (!e.deltaY) { - return - } + if (!e.deltaY) { + return + } - const { position, scale } = camera.transform + const { position, scale } = camera.transform - const mousePosition = [e.clientX, e.clientY] - const oldPosition = [...mousePosition] as vector2 + const mousePosition = [e.clientX, e.clientY] + const oldPosition = [...mousePosition] as vector2 - const oldScale = scale[0] - const newScale = clamp(zoomLimits[0], zoomLimits[1], oldScale * zoom) + const oldScale = scale[0] + const newScale = clamp(zoomLimits[0], zoomLimits[1], oldScale * zoom) - camera.transform.scale = repeat(newScale, 2) as vector2 + camera.transform.scale = repeat(newScale, 2) as vector2 - const scaleFraction = newScale / oldScale - const newPosition = substract( - oldPosition, - multiply(substract(oldPosition, position), scaleFraction) - ) + const scaleFraction = newScale / oldScale + const newPosition = substract( + oldPosition, + multiply(substract(oldPosition, position), scaleFraction) + ) - camera.transform.position = newPosition + camera.transform.position = newPosition }