fix: fixed pasting between simulations:)

This commit is contained in:
Matei Adriel 2020-04-13 15:53:44 +03:00
parent f56afa7347
commit d0484100ba
5 changed files with 357 additions and 315 deletions

654
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -26,7 +26,7 @@
"babel-loader": "^8.0.6",
"babel-plugin-transform-runtime": "^6.23.0",
"babel-regenerator-runtime": "^6.5.0",
"copy-webpack-plugin": "^5.0.4",
"copy-webpack-plugin": "^5.1.1",
"cross-env": "^5.2.0",
"css-loader": "^3.0.0",
"file-loader": "^4.1.0",
@ -34,7 +34,7 @@
"html-webpack-inline-source-plugin": "0.0.10",
"html-webpack-plugin": "^3.2.0",
"mini-css-extract-plugin": "^0.8.0",
"node-sass": "^4.12.0",
"node-sass": "^4.13.1",
"optimize-css-assets-webpack-plugin": "^5.0.3",
"sass-loader": "^7.1.0",
"style-loader": "^0.23.1",

View file

@ -1,6 +1,7 @@
import { SimulationRenderer } from '../../simulationRenderer/classes/SimulationRenderer'
import { idStore } from '../../simulation/stores/idStore'
import { deleteGate } from '../../simulationRenderer/helpers/deleteGate'
import { substract, averege } from '../../vector2/helpers/basic'
/**
* Helper to copy the selection of a renderer
@ -10,10 +11,12 @@ import { deleteGate } from '../../simulationRenderer/helpers/deleteGate'
export const copy = (renderer: SimulationRenderer) => {
const selected = renderer.getSelected()
const center = averege(...selected.map(({ transform }) => transform.position))
renderer.wireClipboard = []
renderer.clipboard = selected.map(gate => ({
name: gate.template.metadata.name,
position: gate.transform.position
position: substract(gate.transform.position, center)
}))
for (const wire of renderer.simulation.wires) {

View file

@ -85,7 +85,7 @@ export const instantiateGateInitter = (
const gate = renderer.simulation.gates.get(id)
if (gate && gate.data) {
gate.data.transform.position = initter.position
gate.data.transform.position = add(initter.position, renderer.camera.toWordPostition(Screen.center))
}
return id

View file

@ -63,3 +63,10 @@ export const substract = (vector: vector2, other: vector2) =>
relativeTo(other, vector)
export const inverse = (vector: vector2) => vector.map(a => 1 / a) as vector2
/**
* Find the aritmetic averege of n vectors.
*
* @param vectors tHe vectors to find the averege of
*/
export const averege = (...vectors: vector2[]) => multiply(add(...vectors), 1 / vectors.length)