From 13521ba3ee4d6fe3c3e170a38c2d122ae8631829 Mon Sep 17 00:00:00 2001
From: Matei Adriel <rafaeladriel11@gmail.com>
Date: Fri, 2 Aug 2019 12:01:32 +0300
Subject: [PATCH] changed a texture

---
 src/assets/ic.svg                             | 22 +++++++++++++++++++
 .../integrated-circuits/helpers/compileIc.ts  |  6 ++++-
 src/modules/saving/helpers/fromState.ts       |  8 +++----
 src/modules/simulation/helpers/addGate.ts     | 16 +++++++++-----
 4 files changed, 42 insertions(+), 10 deletions(-)
 create mode 100644 src/assets/ic.svg

diff --git a/src/assets/ic.svg b/src/assets/ic.svg
new file mode 100644
index 0000000..0016a8c
--- /dev/null
+++ b/src/assets/ic.svg
@@ -0,0 +1,22 @@
+<svg width="800" height="800" viewBox="0 0 800 800" fill="none" xmlns="http://www.w3.org/2000/svg">
+<rect width="800" height="800" fill="#211E33"/>
+<rect x="330" y="331" width="140" height="140" fill="#211E33" stroke="white" stroke-width="10"/>
+<path d="M360 365V439.5" stroke="white" stroke-width="10"/>
+<path d="M440 377.5H360.5" stroke="white" stroke-width="10"/>
+<path d="M439.5 426H360" stroke="white" stroke-width="10"/>
+<path d="M400 364V438.5" stroke="white" stroke-width="10"/>
+<path d="M441 365V439.5" stroke="white" stroke-width="10"/>
+<path d="M466.5 331.5L507.208 288H564.5" stroke="white" stroke-width="10"/>
+<path d="M466 464L506.708 507.5H564" stroke="white" stroke-width="10"/>
+<path d="M333 335.5L292.292 292H235" stroke="white" stroke-width="10"/>
+<path d="M333 468.5L292.292 512H235" stroke="white" stroke-width="10"/>
+<path d="M467.5 361H558.5" stroke="white" stroke-width="10"/>
+<path d="M466 402H557" stroke="white" stroke-width="10"/>
+<path d="M464.5 443H555.5" stroke="white" stroke-width="10"/>
+<path d="M240 360H331" stroke="white" stroke-width="10"/>
+<path d="M239 401H330" stroke="white" stroke-width="10"/>
+<path d="M237 442H328" stroke="white" stroke-width="10"/>
+<path d="M329 401H358.5" stroke="white" stroke-width="10"/>
+<path d="M329 401H358.5" stroke="white" stroke-width="10"/>
+<path d="M438 402H467.5" stroke="white" stroke-width="10"/>
+</svg>
diff --git a/src/modules/integrated-circuits/helpers/compileIc.ts b/src/modules/integrated-circuits/helpers/compileIc.ts
index 3e7fd5c..8566a62 100644
--- a/src/modules/integrated-circuits/helpers/compileIc.ts
+++ b/src/modules/integrated-circuits/helpers/compileIc.ts
@@ -48,7 +48,11 @@ export const compileIc = (state: SimulationState) => {
                 count: outputCount
             }
         },
-        category: categories.ic
+        category: categories.ic,
+        material: {
+            type: 'image',
+            fill: require('../../../assets/ic')
+        }
     }
 
     templateStore.set(name, result)
diff --git a/src/modules/saving/helpers/fromState.ts b/src/modules/saving/helpers/fromState.ts
index 454c0c9..a0dcb6e 100644
--- a/src/modules/saving/helpers/fromState.ts
+++ b/src/modules/saving/helpers/fromState.ts
@@ -13,6 +13,7 @@ import { calculateGateHeight } from '../../simulationRenderer/helpers/calculateG
 import { getRendererSafely } from '../../logic-gates/helpers/getRendererSafely'
 import { rendererSubject } from '../../core/subjects/rendererSubject'
 import { filter, take } from 'rxjs/operators'
+import { vector2 } from '../../../common/math/types/vector2'
 
 /**
  * Contains methods for transforming saved state into the respective class instances
@@ -46,10 +47,9 @@ export const fromSimulationState = (
         gate.transform = fromTransformState(gateState.transform)
 
         const fixWrongHeight = () => {
-            gate.transform.height = calculateGateHeight(
-                getRendererSafely(),
-                gate
-            )
+            gate.transform.scale = [...Array(2)].fill(
+                calculateGateHeight(getRendererSafely(), gate)
+            ) as vector2
         }
 
         try {
diff --git a/src/modules/simulation/helpers/addGate.ts b/src/modules/simulation/helpers/addGate.ts
index 2e0fb81..207d877 100644
--- a/src/modules/simulation/helpers/addGate.ts
+++ b/src/modules/simulation/helpers/addGate.ts
@@ -1,7 +1,12 @@
 import { templateStore } from '../../saving/stores/templateStore'
 import { SimulationError } from '../../errors/classes/SimulationError'
 import { Gate } from '../classes/Gate'
-import { add, relativeTo, multiply } from '../../vector2/helpers/basic'
+import {
+    add,
+    relativeTo,
+    multiply,
+    multiplyVectors
+} from '../../vector2/helpers/basic'
 import { SimulationRenderer } from '../../simulationRenderer/classes/SimulationRenderer'
 import { DefaultGateTemplate } from '../constants'
 import { vector2 } from '../../../common/math/types/vector2'
@@ -35,16 +40,17 @@ export const addGate = (
             ? (template.shape.scale as vector2)
             : DefaultGateTemplate.shape.scale
 
-    const origin = relativeTo(
-        multiply(gateScale, 0.5),
-        relativeTo(renderer.camera.transform.position, Screen.center)
+    const origin = renderer.camera.toWordPostition(
+        add(multiply(gateScale, 0.5), Screen.center)
     )
 
     const scalarOffset = renderer.options.spawning.spawnOffset
     const offset = multiply([scalarOffset, scalarOffset], renderer.spawnCount)
 
     gate.transform.position = add(origin, offset)
-    gate.transform.height = calculateGateHeight(renderer, gate)
+    gate.transform.scale = [...Array(2)].fill(
+        calculateGateHeight(renderer, gate)
+    ) as vector2
 
     renderer.simulation.push(gate)
     renderer.spawnCount++