Procházet zdrojové kódy

Fixes code save

main
Steve Ruiz před 4 roky
rodič
revize
e21748f7b7

+ 0
- 1
components/canvas/bounds.tsx Zobrazit soubor

137
           rCorner.current.setPointerCapture(e.pointerId)
137
           rCorner.current.setPointerCapture(e.pointerId)
138
           state.send("POINTED_BOUNDS_CORNER", inputs.pointerDown(e, corner))
138
           state.send("POINTED_BOUNDS_CORNER", inputs.pointerDown(e, corner))
139
         }}
139
         }}
140
-        onPointerCancelCapture={() => console.log("oops")}
141
         onPointerUp={(e) => {
140
         onPointerUp={(e) => {
142
           e.stopPropagation()
141
           e.stopPropagation()
143
           rCorner.current.releasePointerCapture(e.pointerId)
142
           rCorner.current.releasePointerCapture(e.pointerId)

+ 7
- 5
components/code-panel/code-panel.tsx Zobrazit soubor

30
 
30
 
31
 export default function CodePanel() {
31
 export default function CodePanel() {
32
   const rContainer = useRef<HTMLDivElement>(null)
32
   const rContainer = useRef<HTMLDivElement>(null)
33
-
34
-  const fileId = "file0"
35
   const isReadOnly = useSelector((s) => s.data.isReadOnly)
33
   const isReadOnly = useSelector((s) => s.data.isReadOnly)
36
-  const file = useSelector((s) => s.data.document.code[fileId])
34
+  const fileId = useSelector((s) => s.data.currentCodeFileId)
35
+  const file = useSelector(
36
+    (s) => s.data.document.code[s.data.currentCodeFileId]
37
+  )
37
   const isOpen = true
38
   const isOpen = true
38
   const fontSize = useSelector((s) => s.data.settings.fontSize)
39
   const fontSize = useSelector((s) => s.data.settings.fontSize)
39
 
40
 
52
         on: {
53
         on: {
53
           RAN_CODE: "runCode",
54
           RAN_CODE: "runCode",
54
           SAVED_CODE: ["runCode", "saveCode"],
55
           SAVED_CODE: ["runCode", "saveCode"],
55
-          CHANGED_CODE: [{ secretlyDo: "setCode" }],
56
+          CHANGED_CODE: { secretlyDo: "setCode" },
56
           CLEARED_ERROR: { if: "hasError", do: "clearError" },
57
           CLEARED_ERROR: { if: "hasError", do: "clearError" },
57
           TOGGLED_DOCS: { to: "viewingDocs" },
58
           TOGGLED_DOCS: { to: "viewingDocs" },
58
         },
59
         },
89
         data.error = error
90
         data.error = error
90
       },
91
       },
91
       saveCode(data) {
92
       saveCode(data) {
92
-        state.send("CHANGED_CODE", { fileId, code: data.code })
93
+        const { code } = data
94
+        state.send("SAVED_CODE", { code })
93
       },
95
       },
94
       clearError(data) {
96
       clearError(data) {
95
         data.error = null
97
         data.error = null

+ 1
- 1
components/editor.tsx Zobrazit soubor

14
       <Canvas />
14
       <Canvas />
15
       <StatusBar />
15
       <StatusBar />
16
       <Toolbar />
16
       <Toolbar />
17
-      {/* <CodePanel /> */}
17
+      <CodePanel />
18
     </>
18
     </>
19
   )
19
   )
20
 }
20
 }

+ 12
- 1
lib/code/generate.ts Zobrazit soubor

3
 import Ellipse from "./ellipse"
3
 import Ellipse from "./ellipse"
4
 import Polyline from "./polyline"
4
 import Polyline from "./polyline"
5
 import Dot from "./dot"
5
 import Dot from "./dot"
6
+import Ray from "./ray"
6
 import Line from "./line"
7
 import Line from "./line"
7
 import Vector from "./vector"
8
 import Vector from "./vector"
8
 import Utils from "./utils"
9
 import Utils from "./utils"
9
 import { codeShapes } from "./index"
10
 import { codeShapes } from "./index"
10
 
11
 
11
-const scope = { Dot, Circle, Ellipse, Line, Polyline, Rectangle, Vector, Utils }
12
+const scope = {
13
+  Dot,
14
+  Circle,
15
+  Ellipse,
16
+  Ray,
17
+  Line,
18
+  Polyline,
19
+  Rectangle,
20
+  Vector,
21
+  Utils,
22
+}
12
 
23
 
13
 /**
24
 /**
14
  * Evaluate code, collecting generated shapes in the shape set. Return the
25
  * Evaluate code, collecting generated shapes in the shape set. Return the

+ 25
- 0
lib/code/ray.ts Zobrazit soubor

1
+import CodeShape from "./index"
2
+import { v4 as uuid } from "uuid"
3
+import { RayShape, ShapeType } from "types"
4
+
5
+export default class Ray extends CodeShape<RayShape> {
6
+  constructor(props = {} as Partial<RayShape>) {
7
+    super({
8
+      id: uuid(),
9
+      type: ShapeType.Ray,
10
+      isGenerated: false,
11
+      name: "Ray",
12
+      parentId: "page0",
13
+      childIndex: 0,
14
+      point: [0, 0],
15
+      direction: [0, 1],
16
+      rotation: 0,
17
+      style: {
18
+        fill: "#777",
19
+        stroke: "#000",
20
+        strokeWidth: 1,
21
+      },
22
+      ...props,
23
+    })
24
+  }
25
+}

+ 10
- 6
lib/code/vector.ts Zobrazit soubor

274
 
274
 
275
   lrp(b: Vector, t: number) {
275
   lrp(b: Vector, t: number) {
276
     const n = new Vector(this)
276
     const n = new Vector(this)
277
-    this.vec(b)
278
-      .mul(t)
279
-      .add(n)
277
+    this.vec(b).mul(t).add(n)
280
   }
278
   }
281
 
279
 
282
   static lrp(a: Vector, b: Vector, t: number) {
280
   static lrp(a: Vector, b: Vector, t: number) {
283
     const n = new Vector(a)
281
     const n = new Vector(a)
284
-    n.vec(b)
285
-      .mul(t)
286
-      .add(a)
282
+    n.vec(b).mul(t).add(a)
287
     return n
283
     return n
288
   }
284
   }
289
 
285
 
390
     return n.div(n.len())
386
     return n.div(n.len())
391
   }
387
   }
392
 
388
 
389
+  normalize() {
390
+    return this.uni()
391
+  }
392
+
393
+  static normalize(v: Vector) {
394
+    return Vector.uni(v)
395
+  }
396
+
393
   isLeft(center: Vector, b: Vector) {
397
   isLeft(center: Vector, b: Vector) {
394
     return (
398
     return (
395
       (center.x - this.x) * (b.y - this.y) - (b.x - this.x) * (center.y - b.y)
399
       (center.x - this.x) * (b.y - this.y) - (b.x - this.x) * (center.y - b.y)

+ 2
- 2
state/history.ts Zobrazit soubor

106
     const cameraInfo = localStorage.getItem("code_slate_camera")
106
     const cameraInfo = localStorage.getItem("code_slate_camera")
107
 
107
 
108
     if (cameraInfo !== null) {
108
     if (cameraInfo !== null) {
109
-      Object.assign(data.camera, JSON.parse(cameraInfo))
109
+      Object.assign(restoredData.camera, JSON.parse(cameraInfo))
110
 
110
 
111
       // And update the CSS property
111
       // And update the CSS property
112
       document.documentElement.style.setProperty(
112
       document.documentElement.style.setProperty(
113
         "--camera-zoom",
113
         "--camera-zoom",
114
-        data.camera.zoom.toString()
114
+        restoredData.camera.zoom.toString()
115
       )
115
       )
116
     }
116
     }
117
 
117
 

+ 7
- 0
state/state.ts Zobrazit soubor

31
   hoveredId: null,
31
   hoveredId: null,
32
   selectedIds: new Set([]),
32
   selectedIds: new Set([]),
33
   currentPageId: "page0",
33
   currentPageId: "page0",
34
+  currentCodeFileId: "file0",
34
   document: defaultDocument,
35
   document: defaultDocument,
35
 }
36
 }
36
 
37
 
68
         REDO: { do: "redo" },
69
         REDO: { do: "redo" },
69
         CANCELLED: { do: "clearSelectedIds" },
70
         CANCELLED: { do: "clearSelectedIds" },
70
         DELETED: { do: "deleteSelectedIds" },
71
         DELETED: { do: "deleteSelectedIds" },
72
+        SAVED_CODE: "saveCode",
71
         GENERATED_SHAPES_FROM_CODE: "setGeneratedShapes",
73
         GENERATED_SHAPES_FROM_CODE: "setGeneratedShapes",
72
         INCREASED_CODE_FONT_SIZE: "increaseCodeFontSize",
74
         INCREASED_CODE_FONT_SIZE: "increaseCodeFontSize",
73
         DECREASED_CODE_FONT_SIZE: "decreaseCodeFontSize",
75
         DECREASED_CODE_FONT_SIZE: "decreaseCodeFontSize",
502
     },
504
     },
503
 
505
 
504
     // Data
506
     // Data
507
+    saveCode(data, payload: { code: string }) {
508
+      data.document.code[data.currentCodeFileId].code = payload.code
509
+      history.save(data)
510
+    },
511
+
505
     restoreSavedData(data) {
512
     restoreSavedData(data) {
506
       history.load(data)
513
       history.load(data)
507
     },
514
     },

+ 2
- 1
types.ts Zobrazit soubor

13
     zoom: number
13
     zoom: number
14
   }
14
   }
15
   brush?: Bounds
15
   brush?: Bounds
16
-  currentPageId: string
17
   selectedIds: Set<string>
16
   selectedIds: Set<string>
18
   pointedId?: string
17
   pointedId?: string
19
   hoveredId?: string
18
   hoveredId?: string
19
+  currentPageId: string
20
+  currentCodeFileId: string
20
   document: {
21
   document: {
21
     pages: Record<string, Page>
22
     pages: Record<string, Page>
22
     code: Record<string, CodeFile>
23
     code: Record<string, CodeFile>

Načítá se…
Zrušit
Uložit