Updates code to mark isGenerated

This commit is contained in:
Steve Ruiz 2021-05-25 10:09:51 +01:00
parent a1cc578bb9
commit 71b8ac94af
10 changed files with 29 additions and 18 deletions

View file

@ -10,7 +10,7 @@ export default class Dot extends CodeShape<DotShape> {
super({ super({
id: uuid(), id: uuid(),
type: ShapeType.Dot, type: ShapeType.Dot,
isGenerated: false, isGenerated: true,
name: "Dot", name: "Dot",
parentId: "page0", parentId: "page0",
childIndex: 0, childIndex: 0,

View file

@ -10,7 +10,7 @@ export default class Ellipse extends CodeShape<EllipseShape> {
super({ super({
id: uuid(), id: uuid(),
type: ShapeType.Ellipse, type: ShapeType.Ellipse,
isGenerated: false, isGenerated: true,
name: "Ellipse", name: "Ellipse",
parentId: "page0", parentId: "page0",
childIndex: 0, childIndex: 0,

View file

@ -1,5 +1,9 @@
import { Shape } from "types" import { Shape } from "types"
import { getShapeUtils, ShapeUtility } from "lib/shape-utils" import shapeUtilityMap, {
createShape,
getShapeUtils,
ShapeUtility,
} from "lib/shape-utils"
import * as vec from "utils/vec" import * as vec from "utils/vec"
import Vector from "./vector" import Vector from "./vector"
import { vectorToPoint } from "utils/utils" import { vectorToPoint } from "utils/utils"
@ -12,12 +16,11 @@ export const codeShapes = new Set<CodeShape<Shape>>([])
*/ */
export default class CodeShape<T extends Shape> { export default class CodeShape<T extends Shape> {
private _shape: T private _shape: T
private utils: ShapeUtility<Shape> private utils: ShapeUtility<T>
constructor(props: T) { constructor(props: T) {
this._shape = props this._shape = createShape<T>(props.type, props)
this.utils = getShapeUtils(this.shape) this.utils = getShapeUtils<T>(this._shape)
codeShapes.add(this) codeShapes.add(this)
} }

View file

@ -11,7 +11,7 @@ export default class Line extends CodeShape<LineShape> {
super({ super({
id: uuid(), id: uuid(),
type: ShapeType.Line, type: ShapeType.Line,
isGenerated: false, isGenerated: true,
name: "Line", name: "Line",
parentId: "page0", parentId: "page0",
childIndex: 0, childIndex: 0,

View file

@ -11,7 +11,7 @@ export default class Polyline extends CodeShape<PolylineShape> {
super({ super({
id: uuid(), id: uuid(),
type: ShapeType.Polyline, type: ShapeType.Polyline,
isGenerated: false, isGenerated: true,
name: "Polyline", name: "Polyline",
parentId: "page0", parentId: "page0",
childIndex: 0, childIndex: 0,

View file

@ -11,7 +11,7 @@ export default class Ray extends CodeShape<RayShape> {
super({ super({
id: uuid(), id: uuid(),
type: ShapeType.Ray, type: ShapeType.Ray,
isGenerated: false, isGenerated: true,
name: "Ray", name: "Ray",
parentId: "page0", parentId: "page0",
childIndex: 0, childIndex: 0,

View file

@ -1,7 +1,7 @@
import { v4 as uuid } from "uuid" import { v4 as uuid } from "uuid"
import * as vec from "utils/vec" import * as vec from "utils/vec"
import { CircleShape, ShapeType, Corner, Edge } from "types" import { CircleShape, ShapeType, Corner, Edge } from "types"
import { registerShapeUtils } from "./index" import shapeUtilityMap, { registerShapeUtils } from "./index"
import { boundsContained } from "utils/bounds" import { boundsContained } from "utils/bounds"
import { intersectCircleBounds } from "utils/intersections" import { intersectCircleBounds } from "utils/intersections"
import { pointInCircle } from "utils/hitTests" import { pointInCircle } from "utils/hitTests"

View file

@ -134,11 +134,11 @@ export function registerShapeUtils<T extends Shape>(
return Object.freeze(shape) return Object.freeze(shape)
} }
export function createShape<T extends ShapeType>( export function createShape<T extends Shape>(
type: T, type: T["type"],
props: Partial<ShapeByType<T>> props: Partial<T>
) { ) {
return shapeUtilityMap[type].create(props) as ShapeByType<T> return shapeUtilityMap[type].create(props) as T
} }
export default shapeUtilityMap export default shapeUtilityMap

View file

@ -19,7 +19,7 @@ class MyDocument extends NextDocument {
), ),
} }
} catch (e) { } catch (e) {
console.log(e.message) console.error(e.message)
} finally { } finally {
} }
} }

View file

@ -72,8 +72,16 @@ const state = createState({
SELECTED_RECTANGLE_TOOL: { unless: "isReadOnly", to: "rectangle" }, SELECTED_RECTANGLE_TOOL: { unless: "isReadOnly", to: "rectangle" },
TOGGLED_CODE_PANEL_OPEN: "toggleCodePanel", TOGGLED_CODE_PANEL_OPEN: "toggleCodePanel",
RESET_CAMERA: "resetCamera", RESET_CAMERA: "resetCamera",
ZOOMED_TO_FIT: "zoomCameraToFit", ZOOMED_TO_FIT: {
ZOOMED_TO_SELECTION: { if: "hasSelection", do: "zoomCameraToSelection" }, if: "hasSelection",
do: "zoomCameraToFit",
else: "resetCamera",
},
ZOOMED_TO_SELECTION: {
if: "hasSelection",
do: "zoomCameraToSelection",
else: "resetCamera",
},
ZOOMED_TO_ACTUAL: { ZOOMED_TO_ACTUAL: {
if: "hasSelection", if: "hasSelection",
do: "zoomCameraToSelectionActual", do: "zoomCameraToSelectionActual",