fixes code bug, adds sketchy circle
This commit is contained in:
parent
dd1210c617
commit
5a7e79121a
17 changed files with 188 additions and 144 deletions
|
@ -11,10 +11,10 @@ export default class Circle extends CodeShape<CircleShape> {
|
|||
super({
|
||||
id: uuid(),
|
||||
seed: Math.random(),
|
||||
parentId: (window as any).currentPageId,
|
||||
type: ShapeType.Circle,
|
||||
isGenerated: true,
|
||||
name: 'Circle',
|
||||
parentId: 'page0',
|
||||
childIndex: 0,
|
||||
point: [0, 0],
|
||||
rotation: 0,
|
||||
|
@ -22,8 +22,8 @@ export default class Circle extends CodeShape<CircleShape> {
|
|||
isAspectRatioLocked: false,
|
||||
isLocked: false,
|
||||
isHidden: false,
|
||||
style: defaultStyle,
|
||||
...props,
|
||||
style: { ...defaultStyle, ...props.style },
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -11,10 +11,10 @@ export default class Dot extends CodeShape<DotShape> {
|
|||
super({
|
||||
id: uuid(),
|
||||
seed: Math.random(),
|
||||
parentId: (window as any).currentPageId,
|
||||
type: ShapeType.Dot,
|
||||
isGenerated: true,
|
||||
name: 'Dot',
|
||||
parentId: 'page0',
|
||||
childIndex: 0,
|
||||
point: [0, 0],
|
||||
rotation: 0,
|
||||
|
@ -25,7 +25,7 @@ export default class Dot extends CodeShape<DotShape> {
|
|||
style: {
|
||||
...defaultStyle,
|
||||
...props.style,
|
||||
isFilled: false,
|
||||
isFilled: true,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
|
|
@ -11,10 +11,10 @@ export default class Ellipse extends CodeShape<EllipseShape> {
|
|||
super({
|
||||
id: uuid(),
|
||||
seed: Math.random(),
|
||||
parentId: (window as any).currentPageId,
|
||||
type: ShapeType.Ellipse,
|
||||
isGenerated: true,
|
||||
name: 'Ellipse',
|
||||
parentId: 'page0',
|
||||
childIndex: 0,
|
||||
point: [0, 0],
|
||||
radiusX: 20,
|
||||
|
@ -23,8 +23,8 @@ export default class Ellipse extends CodeShape<EllipseShape> {
|
|||
isAspectRatioLocked: false,
|
||||
isLocked: false,
|
||||
isHidden: false,
|
||||
style: defaultStyle,
|
||||
...props,
|
||||
style: { ...defaultStyle, ...props.style },
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
import Rectangle from "./rectangle"
|
||||
import Circle from "./circle"
|
||||
import Ellipse from "./ellipse"
|
||||
import Polyline from "./polyline"
|
||||
import Dot from "./dot"
|
||||
import Ray from "./ray"
|
||||
import Line from "./line"
|
||||
import Vector from "./vector"
|
||||
import Utils from "./utils"
|
||||
import { NumberControl, VectorControl, codeControls, controls } from "./control"
|
||||
import { codeShapes } from "./index"
|
||||
import { CodeControl } from "types"
|
||||
import Rectangle from './rectangle'
|
||||
import Circle from './circle'
|
||||
import Ellipse from './ellipse'
|
||||
import Polyline from './polyline'
|
||||
import Dot from './dot'
|
||||
import Ray from './ray'
|
||||
import Line from './line'
|
||||
import Vector from './vector'
|
||||
import Utils from './utils'
|
||||
import { NumberControl, VectorControl, codeControls, controls } from './control'
|
||||
import { codeShapes } from './index'
|
||||
import { CodeControl, Data } from 'types'
|
||||
|
||||
const baseScope = {
|
||||
Dot,
|
||||
|
@ -30,12 +30,14 @@ const baseScope = {
|
|||
* collected shapes as an array.
|
||||
* @param code
|
||||
*/
|
||||
export function generateFromCode(code: string) {
|
||||
export function generateFromCode(data: Data, code: string) {
|
||||
codeControls.clear()
|
||||
codeShapes.clear()
|
||||
;(window as any).isUpdatingCode = false
|
||||
;(window as any).currentPageId = data.currentPageId
|
||||
|
||||
const scope = { ...baseScope, controls }
|
||||
const { currentPageId } = data
|
||||
const scope = { ...baseScope, controls, currentPageId }
|
||||
|
||||
new Function(...Object.keys(scope), `${code}`)(...Object.values(scope))
|
||||
|
||||
|
@ -53,15 +55,16 @@ export function generateFromCode(code: string) {
|
|||
* collected shapes as an array.
|
||||
* @param code
|
||||
*/
|
||||
export function updateFromCode(
|
||||
code: string,
|
||||
controls: Record<string, CodeControl>
|
||||
) {
|
||||
export function updateFromCode(data: Data, code: string) {
|
||||
codeShapes.clear()
|
||||
;(window as any).isUpdatingCode = true
|
||||
;(window as any).currentPageId = data.currentPageId
|
||||
|
||||
const { currentPageId } = data
|
||||
|
||||
const scope = {
|
||||
...baseScope,
|
||||
currentPageId,
|
||||
controls: Object.fromEntries(
|
||||
Object.entries(controls).map(([id, control]) => [
|
||||
control.label,
|
||||
|
|
|
@ -12,10 +12,10 @@ export default class Line extends CodeShape<LineShape> {
|
|||
super({
|
||||
id: uuid(),
|
||||
seed: Math.random(),
|
||||
parentId: (window as any).currentPageId,
|
||||
type: ShapeType.Line,
|
||||
isGenerated: true,
|
||||
name: 'Line',
|
||||
parentId: 'page0',
|
||||
childIndex: 0,
|
||||
point: [0, 0],
|
||||
direction: [-0.5, 0.5],
|
||||
|
|
|
@ -12,10 +12,10 @@ export default class Polyline extends CodeShape<PolylineShape> {
|
|||
super({
|
||||
id: uuid(),
|
||||
seed: Math.random(),
|
||||
parentId: (window as any).currentPageId,
|
||||
type: ShapeType.Polyline,
|
||||
isGenerated: true,
|
||||
name: 'Polyline',
|
||||
parentId: 'page0',
|
||||
childIndex: 0,
|
||||
point: [0, 0],
|
||||
points: [[0, 0]],
|
||||
|
|
|
@ -12,10 +12,10 @@ export default class Rectangle extends CodeShape<RectangleShape> {
|
|||
super({
|
||||
id: uuid(),
|
||||
seed: Math.random(),
|
||||
parentId: (window as any).currentPageId,
|
||||
type: ShapeType.Rectangle,
|
||||
isGenerated: true,
|
||||
name: 'Rectangle',
|
||||
parentId: 'page0',
|
||||
childIndex: 0,
|
||||
point: [0, 0],
|
||||
size: [100, 100],
|
||||
|
@ -24,8 +24,8 @@ export default class Rectangle extends CodeShape<RectangleShape> {
|
|||
isAspectRatioLocked: false,
|
||||
isLocked: false,
|
||||
isHidden: false,
|
||||
style: defaultStyle,
|
||||
...props,
|
||||
style: { ...defaultStyle, ...props.style },
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { Bounds } from "types"
|
||||
import Vector, { Point } from "./vector"
|
||||
import { Bounds } from 'types'
|
||||
import Vector, { Point } from './vector'
|
||||
|
||||
export default class Utils {
|
||||
static getRayRayIntersection(p0: Vector, n0: Vector, p1: Vector, n1: Vector) {
|
||||
|
|
|
@ -16,7 +16,7 @@ export default class Vector {
|
|||
constructor(vector: Vector, b?: undefined)
|
||||
constructor(options: Point, b?: undefined)
|
||||
constructor(a: VectorOptions | Vector | number, b?: number) {
|
||||
if (typeof a === "number") {
|
||||
if (typeof a === 'number') {
|
||||
this.x = a
|
||||
this.y = b
|
||||
} else {
|
||||
|
@ -415,7 +415,7 @@ export default class Vector {
|
|||
}
|
||||
|
||||
static cast(v: Point | Vector) {
|
||||
return "cast" in v ? v : new Vector(v)
|
||||
return 'cast' in v ? v : new Vector(v)
|
||||
}
|
||||
|
||||
static from(v: Vector) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue