wire deleting
This commit is contained in:
parent
145730434d
commit
116c0d5e01
12
src/common/lang/arrays/helpers/removeElement.ts
Normal file
12
src/common/lang/arrays/helpers/removeElement.ts
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
/**
|
||||||
|
* Removes element from array efficiently
|
||||||
|
* Based on a gist by the creator of rollup.
|
||||||
|
*
|
||||||
|
* @param arr The array to remove the element from
|
||||||
|
* @param element The element to remove
|
||||||
|
*/
|
||||||
|
export const removeElement = <T>(arr: T[], element: T) => {
|
||||||
|
const index = arr.indexOf(element)
|
||||||
|
arr[index] = arr[arr.length - 1]
|
||||||
|
return arr.pop()
|
||||||
|
}
|
|
@ -7,6 +7,7 @@ import { initKeyBindings } from './modules/keybindings/helpers/initialiseKeyBind
|
||||||
import { initBaseTemplates } from './modules/saving/helpers/initBaseTemplates'
|
import { initBaseTemplates } from './modules/saving/helpers/initBaseTemplates'
|
||||||
import { loadSubject } from './modules/core/subjects/loadedSubject'
|
import { loadSubject } from './modules/core/subjects/loadedSubject'
|
||||||
import { take } from 'rxjs/operators'
|
import { take } from 'rxjs/operators'
|
||||||
|
import { logWelcome } from './modules/core/helpers/logWelcome'
|
||||||
|
|
||||||
export const start = async () => {
|
export const start = async () => {
|
||||||
console.clear()
|
console.clear()
|
||||||
|
@ -16,6 +17,7 @@ export const start = async () => {
|
||||||
handleErrors()
|
handleErrors()
|
||||||
initKeyBindings()
|
initKeyBindings()
|
||||||
initBaseTemplates()
|
initBaseTemplates()
|
||||||
|
logWelcome()
|
||||||
|
|
||||||
render(<App />, document.getElementById('app'))
|
render(<App />, document.getElementById('app'))
|
||||||
|
|
||||||
|
|
23
src/modules/core/helpers/logWelcome.ts
Normal file
23
src/modules/core/helpers/logWelcome.ts
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
/**
|
||||||
|
* In case the guys who look at my projet open the console -_-
|
||||||
|
*/
|
||||||
|
export const logWelcome = () => {
|
||||||
|
const commonStyles = 'padding: 3px'
|
||||||
|
const titleStyles = `font-size: 3em;`
|
||||||
|
|
||||||
|
// console.log('%c Hello!',` `${titleStyles})
|
||||||
|
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}`
|
||||||
|
)
|
||||||
|
}
|
9
src/modules/simulation/helpers/deleteWire.ts
Normal file
9
src/modules/simulation/helpers/deleteWire.ts
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
import { Simulation } from '../classes/Simulation'
|
||||||
|
import { Wire } from '../classes/Wire'
|
||||||
|
import { removeElement } from '../../../common/lang/arrays/helpers/removeElement'
|
||||||
|
|
||||||
|
export const deleteWire = (simulation: Simulation, wire: Wire) => {
|
||||||
|
removeElement(simulation.wires, wire)
|
||||||
|
|
||||||
|
wire.dispose()
|
||||||
|
}
|
|
@ -28,6 +28,8 @@ import { updateMouse, handleScroll } from '../helpers/scaleCanvas'
|
||||||
import { RefObject } from 'react'
|
import { RefObject } from 'react'
|
||||||
import { dumpSimulation } from '../../saving/helpers/dumpSimulation'
|
import { dumpSimulation } from '../../saving/helpers/dumpSimulation'
|
||||||
import { modalIsOpen } from '../../modals/helpers/modalIsOpen'
|
import { modalIsOpen } from '../../modals/helpers/modalIsOpen'
|
||||||
|
import { SimulationError } from '../../errors/classes/SimulationError'
|
||||||
|
import { deleteWire } from '../../simulation/helpers/deleteWire'
|
||||||
|
|
||||||
export class SimulationRenderer {
|
export class SimulationRenderer {
|
||||||
public mouseDownOutput = new Subject<MouseEventInfo>()
|
public mouseDownOutput = new Subject<MouseEventInfo>()
|
||||||
|
@ -113,6 +115,24 @@ export class SimulationRenderer {
|
||||||
this.options.gates.pinRadius
|
this.options.gates.pinRadius
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
|
if (pin.value.pairs.size) {
|
||||||
|
if (pin.value.type & 1) {
|
||||||
|
const wire = this.simulation.wires.find(
|
||||||
|
wire => wire.end.value === pin.value
|
||||||
|
)
|
||||||
|
|
||||||
|
if (wire) {
|
||||||
|
deleteWire(this.simulation, wire)
|
||||||
|
} else {
|
||||||
|
throw new SimulationError(
|
||||||
|
`Cannot find wire to remove`
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
this.selectedPins.start &&
|
this.selectedPins.start &&
|
||||||
pin.value === this.selectedPins.start.wrapper.value
|
pin.value === this.selectedPins.start.wrapper.value
|
||||||
|
@ -130,21 +150,14 @@ export class SimulationRenderer {
|
||||||
wrapper: pin,
|
wrapper: pin,
|
||||||
transform
|
transform
|
||||||
}
|
}
|
||||||
} else if (
|
} else if (pin.value.type & 1) {
|
||||||
pin.value.type & 1 &&
|
|
||||||
pin.value.pairs.size === 0
|
|
||||||
) {
|
|
||||||
this.selectedPins.end = {
|
this.selectedPins.end = {
|
||||||
wrapper: pin,
|
wrapper: pin,
|
||||||
transform
|
transform
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (this.selectedPins.start && this.selectedPins.end) {
|
||||||
this.selectedPins.start &&
|
|
||||||
this.selectedPins.end &&
|
|
||||||
this.selectedPins.end.wrapper.value.pairs.size === 0
|
|
||||||
) {
|
|
||||||
this.simulation.wires.push(
|
this.simulation.wires.push(
|
||||||
new Wire(
|
new Wire(
|
||||||
this.selectedPins.start.wrapper,
|
this.selectedPins.start.wrapper,
|
||||||
|
@ -158,7 +171,7 @@ export class SimulationRenderer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.mouseState |= 2
|
this.mouseState |= 0b10
|
||||||
})
|
})
|
||||||
|
|
||||||
this.mouseUpOutput.subscribe(event => {
|
this.mouseUpOutput.subscribe(event => {
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
.Splash > .error {
|
.Splash > .error {
|
||||||
|
color: white;
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,7 +38,7 @@
|
||||||
.Splash > .error > .details {
|
.Splash > .error > .details {
|
||||||
padding: 16px;
|
padding: 16px;
|
||||||
|
|
||||||
background-color: shade(darker);
|
background-color: $grey / 2;
|
||||||
|
|
||||||
border-radius: 3px;
|
border-radius: 3px;
|
||||||
margin-bottom: 16px;
|
margin-bottom: 16px;
|
||||||
|
@ -46,11 +47,15 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
.Splash > .error > .description {
|
.Splash > .error > .description {
|
||||||
color: font-color(normal);
|
color: white;
|
||||||
margin-bottom: 16px;
|
margin-bottom: 16px;
|
||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.Splash > .error > .details > a {
|
||||||
|
color: $primary !important;
|
||||||
|
}
|
||||||
|
|
||||||
.Splash.-hasError {
|
.Splash.-hasError {
|
||||||
> .error {
|
> .error {
|
||||||
display: block;
|
display: block;
|
||||||
|
@ -59,3 +64,7 @@
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.mail {
|
||||||
|
color: $primary * 2;
|
||||||
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ import './Splash.scss'
|
||||||
|
|
||||||
export class Splash {
|
export class Splash {
|
||||||
private element = querySelector<HTMLDivElement>('.Splash')
|
private element = querySelector<HTMLDivElement>('.Splash')
|
||||||
|
private email = 'rafaeladriel11@gmail.com'
|
||||||
|
|
||||||
public fade() {
|
public fade() {
|
||||||
this.element.style.transition = '0.3s'
|
this.element.style.transition = '0.3s'
|
||||||
|
@ -33,6 +34,13 @@ export class Splash {
|
||||||
<p>Your browser might not be supported, or your data might be corrupt.
|
<p>Your browser might not be supported, or your data might be corrupt.
|
||||||
Press "Clear data" below to reset the simulator and try again.</br>
|
Press "Clear data" below to reset the simulator and try again.</br>
|
||||||
</br></br>
|
</br></br>
|
||||||
|
|
||||||
|
If the problem persists, you can <a class="mail" href="mailto:${
|
||||||
|
this.email
|
||||||
|
}">contact the developer</a>
|
||||||
|
|
||||||
|
</br></br>
|
||||||
|
|
||||||
We do not support the following browsers:</p>
|
We do not support the following browsers:</p>
|
||||||
<ul>
|
<ul>
|
||||||
<li><span>Opera Mini</span></li>
|
<li><span>Opera Mini</span></li>
|
||||||
|
|
Loading…
Reference in a new issue