@makefully/platypus 4.1.4 → 4.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +20 -0
- package/README.md +4 -2
- package/lib/platypus.js +1 -1
- package/package.json +7 -2
- package/src/AABB.js +685 -0
- package/src/ActionState.js +121 -0
- package/src/AssetManager.js +206 -0
- package/src/CollisionData.js +96 -0
- package/src/CollisionDataContainer.js +127 -0
- package/src/CollisionShape.js +315 -0
- package/src/Component.js +231 -0
- package/src/Data.js +64 -0
- package/src/DataMap.js +204 -0
- package/src/Entity.js +404 -0
- package/src/EntityLinker.js +113 -0
- package/src/EventHandler.js +115 -0
- package/src/EventHandlerList.js +251 -0
- package/src/Game.js +840 -0
- package/src/Gamepad.js +175 -0
- package/src/ID3CaptionPlayer.js +61 -0
- package/src/Messenger.js +365 -0
- package/src/PIXIAnimation.js +622 -0
- package/src/RandomSet.js +140 -0
- package/src/SFXPlayer.js +120 -0
- package/src/StateMap.js +252 -0
- package/src/Storage.js +152 -0
- package/src/TickerClient.js +48 -0
- package/src/TickerServer.js +23 -0
- package/src/TimeEvent.js +50 -0
- package/src/TimeEventList.js +100 -0
- package/src/VOPlayer.js +684 -0
- package/src/Vector.js +702 -0
- package/src/components/AIChaser.js +161 -0
- package/src/components/AIPacer.js +107 -0
- package/src/components/AudioMusic.js +151 -0
- package/src/components/AudioSFX.js +673 -0
- package/src/components/AudioVO.js +301 -0
- package/src/components/CollisionBasic.js +826 -0
- package/src/components/CollisionFilter.js +74 -0
- package/src/components/CollisionGroup.js +448 -0
- package/src/components/CollisionTiles.js +608 -0
- package/src/components/ComponentSwitcher.js +173 -0
- package/src/components/ControllerInput.js +65 -0
- package/src/components/Counter.js +165 -0
- package/src/components/EntityCamera.js +215 -0
- package/src/components/EntityContainer.js +549 -0
- package/src/components/EntityController.js +541 -0
- package/src/components/HandlerCamera.js +1052 -0
- package/src/components/HandlerCollision.js +1318 -0
- package/src/components/HandlerController.js +291 -0
- package/src/components/HandlerLogic.js +394 -0
- package/src/components/HandlerRender.js +217 -0
- package/src/components/Interactive.js +502 -0
- package/src/components/LevelBuilder.js +524 -0
- package/src/components/LogicAngularMovement.js +154 -0
- package/src/components/LogicAttachment.js +265 -0
- package/src/components/LogicButton.js +466 -0
- package/src/components/LogicCarrier.js +39 -0
- package/src/components/LogicDestroyMe.js +58 -0
- package/src/components/LogicDirectionalMovement.js +325 -0
- package/src/components/LogicDragDrop.js +371 -0
- package/src/components/LogicImpactLaunch.js +144 -0
- package/src/components/LogicPacingPlatform.js +64 -0
- package/src/components/LogicPortable.js +112 -0
- package/src/components/LogicPortal.js +115 -0
- package/src/components/LogicPushable.js +98 -0
- package/src/components/LogicRebounder.js +136 -0
- package/src/components/LogicRegionSpawner.js +139 -0
- package/src/components/LogicRotationalMovement.js +205 -0
- package/src/components/LogicSpawner.js +159 -0
- package/src/components/LogicStateMachine.js +382 -0
- package/src/components/LogicSwitch.js +77 -0
- package/src/components/LogicTeleportee.js +68 -0
- package/src/components/LogicTeleporter.js +93 -0
- package/src/components/LogicTimer.js +178 -0
- package/src/components/LogicWindUpRacer.js +179 -0
- package/src/components/Motion.js +371 -0
- package/src/components/Mover.js +566 -0
- package/src/components/Node.js +289 -0
- package/src/components/NodeMap.js +295 -0
- package/src/components/NodeResident.js +636 -0
- package/src/components/Orientation.js +697 -0
- package/src/components/RandomEvents.js +73 -0
- package/src/components/RelativePosition.js +204 -0
- package/src/components/RelayFamily.js +106 -0
- package/src/components/RelayGame.js +53 -0
- package/src/components/RelayLinker.js +94 -0
- package/src/components/RelayParent.js +57 -0
- package/src/components/RelaySelf.js +55 -0
- package/src/components/Render.js +178 -0
- package/src/components/RenderAnimator.js +275 -0
- package/src/components/RenderContainer.js +646 -0
- package/src/components/RenderDebug.js +319 -0
- package/src/components/RenderDestroyMe.js +59 -0
- package/src/components/RenderLottie.js +149 -0
- package/src/components/RenderProgress.js +120 -0
- package/src/components/RenderSpine.js +833 -0
- package/src/components/RenderSprite.js +527 -0
- package/src/components/RenderText.js +147 -0
- package/src/components/RenderTiles.js +1391 -0
- package/src/components/SceneChanger.js +128 -0
- package/src/components/TiledLoader.js +1451 -0
- package/src/components/Timeline.js +314 -0
- package/src/components/Tutorial.js +267 -0
- package/src/components/Tween.js +296 -0
- package/src/components/VoiceOver.js +373 -0
- package/src/components/XHR.js +129 -0
- package/src/components/index.js +79 -0
- package/src/factory.js +305 -0
- package/src/index.js +159 -0
- package/src/mixins/PIXI.Graphics.js +41 -0
- package/src/platypus.css +68 -0
- package/src/sayHello.js +50 -0
- package/src/shapes/Capsule.js +74 -0
- package/src/shapes/Circle.js +43 -0
- package/src/shapes/Ellipse.js +117 -0
- package/src/shapes/Point.js +191 -0
- package/src/shapes/Polygon.js +112 -0
- package/src/shapes/Polyline.js +97 -0
- package/src/shapes/Rectangle.js +78 -0
- package/src/shapes/RoundedRectangle.js +33 -0
- package/src/shapes/Segment.js +346 -0
- package/src/shapes/adjustedXY.js +19 -0
- package/src/shapes/castFromBox2D.js +92 -0
- package/src/shapes/castFromObject.js +53 -0
- package/src/shapes/castFromPixiGraphics.js +6 -0
- package/src/shapes/castFromPixiShape.js +89 -0
- package/src/shapes/castToBox2D.js +190 -0
- package/src/shapes/castToPixiGraphics.js +100 -0
- package/src/shapes/castToPixiShape.js +61 -0
- package/src/shapes/checkPointsMap.js +313 -0
- package/src/shapes/index.js +35 -0
- package/src/utils/array.js +73 -0
- package/src/utils/string.js +39 -0
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/* global platypus */
|
|
2
|
+
import Capsule from './Capsule';
|
|
3
|
+
import Circle from './Circle';
|
|
4
|
+
import Ellipse from './Ellipse';
|
|
5
|
+
import Polygon from './Polygon';
|
|
6
|
+
import Polyline from './Polyline';
|
|
7
|
+
import Rectangle from './Rectangle';
|
|
8
|
+
import RoundedRectangle from './RoundedRectangle';
|
|
9
|
+
import Segment from './Segment';
|
|
10
|
+
import Point from './Point';
|
|
11
|
+
|
|
12
|
+
const
|
|
13
|
+
SHAPES = {
|
|
14
|
+
capsule: Capsule,
|
|
15
|
+
circle: Circle,
|
|
16
|
+
ellipse: Ellipse,
|
|
17
|
+
polygon: Polygon,
|
|
18
|
+
polyline: Polyline,
|
|
19
|
+
rectangle: Rectangle,
|
|
20
|
+
roundedRectangle: RoundedRectangle,
|
|
21
|
+
segment: Segment,
|
|
22
|
+
point: Point
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export default function castFromObject (shapeData, prioritizedShapeList = ['roundedRectangle', 'rectangle', 'capsule', 'ellipse', 'segment', 'polygon', 'polyline', 'circle', 'point']) {
|
|
26
|
+
const
|
|
27
|
+
{type} = shapeData;
|
|
28
|
+
|
|
29
|
+
if (type && prioritizedShapeList.indexOf(type) >= 0) {
|
|
30
|
+
const
|
|
31
|
+
Shape = SHAPES[type];
|
|
32
|
+
|
|
33
|
+
if (Shape?.validateDefinition(shapeData)) {
|
|
34
|
+
return new Shape(shapeData);
|
|
35
|
+
}
|
|
36
|
+
} else {
|
|
37
|
+
const
|
|
38
|
+
{length} = prioritizedShapeList;
|
|
39
|
+
|
|
40
|
+
for (let i = 0; i < length; i++) {
|
|
41
|
+
const
|
|
42
|
+
Shape = SHAPES[prioritizedShapeList[i]];
|
|
43
|
+
|
|
44
|
+
if (Shape?.validateDefinition(shapeData)) {
|
|
45
|
+
return new Shape(shapeData);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
platypus.debug.warn('Unable to create a shape matching provided data.', shapeData);
|
|
51
|
+
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import castFromObject from "./castFromObject";
|
|
2
|
+
|
|
3
|
+
/* global platypus */
|
|
4
|
+
const
|
|
5
|
+
castTo = {
|
|
6
|
+
circle: (shape, {scale = 1}) => {
|
|
7
|
+
const
|
|
8
|
+
{radius, type, x, y} = shape;
|
|
9
|
+
|
|
10
|
+
return {
|
|
11
|
+
radius: radius * scale,
|
|
12
|
+
type,
|
|
13
|
+
x: x * scale,
|
|
14
|
+
y: y * scale
|
|
15
|
+
};
|
|
16
|
+
},
|
|
17
|
+
ellipse: (shape, {scale = 1}) => {
|
|
18
|
+
const
|
|
19
|
+
{halfHeight, halfWidth, type, x, y} = shape;
|
|
20
|
+
|
|
21
|
+
return {
|
|
22
|
+
height: halfHeight * 2 * scale,
|
|
23
|
+
type,
|
|
24
|
+
width: halfWidth * 2 * scale,
|
|
25
|
+
x: x * scale,
|
|
26
|
+
y: y * scale
|
|
27
|
+
};
|
|
28
|
+
},
|
|
29
|
+
point: (shape, {scale = 1}) => {
|
|
30
|
+
const
|
|
31
|
+
{x, y} = shape;
|
|
32
|
+
|
|
33
|
+
return {
|
|
34
|
+
type: 'point',
|
|
35
|
+
x: x * scale,
|
|
36
|
+
y: y * scale
|
|
37
|
+
};
|
|
38
|
+
},
|
|
39
|
+
polygon: (shape, {scale = 1}) => {
|
|
40
|
+
const
|
|
41
|
+
{closePath, points} = shape;
|
|
42
|
+
|
|
43
|
+
return {
|
|
44
|
+
type: closePath ? 'polygon' : 'polyline',
|
|
45
|
+
points: points.map(({x, y}) => ({
|
|
46
|
+
x: x * scale,
|
|
47
|
+
y: y * scale
|
|
48
|
+
}))
|
|
49
|
+
};
|
|
50
|
+
},
|
|
51
|
+
rectangle: (shape, {scale = 1}) => {
|
|
52
|
+
const
|
|
53
|
+
{height, type, width, x, y} = shape;
|
|
54
|
+
|
|
55
|
+
return {
|
|
56
|
+
height: height * scale,
|
|
57
|
+
type,
|
|
58
|
+
width: width * scale,
|
|
59
|
+
x: x * scale,
|
|
60
|
+
y: y * scale
|
|
61
|
+
};
|
|
62
|
+
},
|
|
63
|
+
roundedRectangle: (shape, {scale = 1}) => {
|
|
64
|
+
const
|
|
65
|
+
{height, radius, type, width, x, y} = shape;
|
|
66
|
+
|
|
67
|
+
return {
|
|
68
|
+
height: height * scale,
|
|
69
|
+
radius: radius * scale,
|
|
70
|
+
type,
|
|
71
|
+
width: width * scale,
|
|
72
|
+
x: x * scale,
|
|
73
|
+
y: y * scale
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
export default function castFromPixiShape (shape, options) {
|
|
79
|
+
const
|
|
80
|
+
{type} = shape,
|
|
81
|
+
cast = typeof type === 'string' ? castTo[type] : castTo.point;
|
|
82
|
+
|
|
83
|
+
if (cast) {
|
|
84
|
+
return castFromObject(cast(shape, options));
|
|
85
|
+
} else {
|
|
86
|
+
platypus.debug.warn(`Unable to cast shape of type "${type}" from Box2D.`, shape);
|
|
87
|
+
return null;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
import adjustedXY from "./adjustedXY";
|
|
2
|
+
|
|
3
|
+
/* global platypus */
|
|
4
|
+
const
|
|
5
|
+
formatChainSD = (shapeDefinition) => {
|
|
6
|
+
const
|
|
7
|
+
{b2DefaultChainDef} = platypus.game.box2d;
|
|
8
|
+
|
|
9
|
+
if (shapeDefinition instanceof b2DefaultChainDef) {
|
|
10
|
+
return shapeDefinition;
|
|
11
|
+
} else {
|
|
12
|
+
const
|
|
13
|
+
{
|
|
14
|
+
enableSensorEvents = false,
|
|
15
|
+
filter,
|
|
16
|
+
isLoop = false,
|
|
17
|
+
materials,
|
|
18
|
+
points
|
|
19
|
+
} = shapeDefinition,
|
|
20
|
+
csd = new b2DefaultChainDef();
|
|
21
|
+
|
|
22
|
+
if (filter) {
|
|
23
|
+
csd.filter.categoryBits = filter.categoryBits ?? 0;
|
|
24
|
+
csd.filter.groupIndex = filter.groupIndex ?? 0;
|
|
25
|
+
csd.filter.maskBits = filter.maskBits ?? 0xffff;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
csd.SetMaterials(materials);
|
|
29
|
+
csd.SetPoints(points);
|
|
30
|
+
|
|
31
|
+
csd.enableSensorEvents = enableSensorEvents;
|
|
32
|
+
csd.isLoop = isLoop;
|
|
33
|
+
|
|
34
|
+
return csd;
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
formatSD = (shapeDefinition) => {
|
|
38
|
+
const
|
|
39
|
+
{b2DefaultShapeDef} = platypus.game.box2d;
|
|
40
|
+
|
|
41
|
+
if (shapeDefinition instanceof b2DefaultShapeDef) {
|
|
42
|
+
return shapeDefinition;
|
|
43
|
+
} else {
|
|
44
|
+
const
|
|
45
|
+
{
|
|
46
|
+
density = 1,
|
|
47
|
+
enableContactEvents = false,
|
|
48
|
+
enableHitEvents = false,
|
|
49
|
+
enablePreSolveEvents = false,
|
|
50
|
+
enableSensorEvents = false,
|
|
51
|
+
filter,
|
|
52
|
+
invokeContactCreation = false,
|
|
53
|
+
isSensor = false,
|
|
54
|
+
material,
|
|
55
|
+
updateBodyMass = true
|
|
56
|
+
} = shapeDefinition,
|
|
57
|
+
sd = new b2DefaultShapeDef();
|
|
58
|
+
|
|
59
|
+
if (filter) {
|
|
60
|
+
sd.filter.categoryBits = filter.categoryBits ?? 0;
|
|
61
|
+
sd.filter.groupIndex = filter.groupIndex ?? 0;
|
|
62
|
+
sd.filter.maskBits = filter.maskBits ?? 0xffff;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (material) {
|
|
66
|
+
sd.material.customColor = material.customColor ?? 0;
|
|
67
|
+
sd.material.friction = material.friction ?? 0.5;
|
|
68
|
+
sd.material.restitution = material.restitution ?? 0.2;
|
|
69
|
+
sd.material.rollingResistance = material.rollingResistance ?? 0;
|
|
70
|
+
sd.material.tangentSpeed = material.tangentSpeed ?? 0;
|
|
71
|
+
sd.material.userMaterialId = material.userMaterialId ?? 0;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
sd.density = density;
|
|
75
|
+
sd.enableContactEvents = enableContactEvents;
|
|
76
|
+
sd.enableHitEvents = enableHitEvents;
|
|
77
|
+
sd.enablePreSolveEvents = enablePreSolveEvents;
|
|
78
|
+
sd.enableSensorEvents = enableSensorEvents;
|
|
79
|
+
sd.invokeContactCreation = invokeContactCreation;
|
|
80
|
+
sd.isSensor = isSensor;
|
|
81
|
+
sd.updateBodyMass = updateBodyMass;
|
|
82
|
+
|
|
83
|
+
return sd;
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
createCapsule = (shape, options) => {
|
|
87
|
+
const
|
|
88
|
+
{bodyId, scale = 1, shapeDefinition} = options,
|
|
89
|
+
{b2Capsule, b2CreateCapsuleShape} = platypus.game.box2d,
|
|
90
|
+
{radius, a, b} = shape,
|
|
91
|
+
{x: ax, y: ay} = adjustedXY(a, options),
|
|
92
|
+
{x: bx, y: by} = adjustedXY(b, options),
|
|
93
|
+
capsule = new b2Capsule();
|
|
94
|
+
|
|
95
|
+
capsule.radius = radius * scale;
|
|
96
|
+
capsule.center1.Set(ax, ay);
|
|
97
|
+
capsule.center2.Set(bx, by);
|
|
98
|
+
|
|
99
|
+
return b2CreateCapsuleShape(bodyId, formatSD(shapeDefinition), capsule);
|
|
100
|
+
},
|
|
101
|
+
createPoint = (shape, options) => {
|
|
102
|
+
const
|
|
103
|
+
v = new platypus.game.box2d.b2Vec2(),
|
|
104
|
+
{x, y} = adjustedXY(shape, options);
|
|
105
|
+
|
|
106
|
+
v.x = x;
|
|
107
|
+
v.y = y;
|
|
108
|
+
|
|
109
|
+
return v;
|
|
110
|
+
},
|
|
111
|
+
createPolygon = (shape, options) => {
|
|
112
|
+
const
|
|
113
|
+
{chain = false, shapeDefinition} = options;
|
|
114
|
+
|
|
115
|
+
if (chain) {
|
|
116
|
+
return createPolyline(shape, {
|
|
117
|
+
...options,
|
|
118
|
+
shapeDefinition: {
|
|
119
|
+
...shapeDefinition,
|
|
120
|
+
isLoop: true
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
} else {
|
|
124
|
+
const
|
|
125
|
+
{bodyId, local = true, radius = 0, scale = 1, shapeDefinition} = options,
|
|
126
|
+
{b2CreatePolygonShape, b2ComputeHull, b2MakePolygon} = platypus.game.box2d,
|
|
127
|
+
polygons = shape.split(3, 8); // break down polygon to chunks equal to or smaller than 8 vertices and make sure these chunks are convex.
|
|
128
|
+
|
|
129
|
+
return polygons.map(({points}) => b2CreatePolygonShape(bodyId, formatSD(shapeDefinition), b2MakePolygon(b2ComputeHull(points.map((point) => createPoint(point, {local, scale})), points.length), radius)));
|
|
130
|
+
}
|
|
131
|
+
},
|
|
132
|
+
createPolyline = ({points}, {bodyId, local = true, scale = 1, shapeDefinition}) => {
|
|
133
|
+
const
|
|
134
|
+
{b2CreateChain} = platypus.game.box2d;
|
|
135
|
+
|
|
136
|
+
return b2CreateChain(bodyId, formatChainSD({
|
|
137
|
+
...shapeDefinition,
|
|
138
|
+
points: points.map((point) => createPoint(point, {local, scale}))
|
|
139
|
+
}));
|
|
140
|
+
},
|
|
141
|
+
castFrom = {
|
|
142
|
+
capsule: createCapsule,
|
|
143
|
+
circle: (shape, options) => {
|
|
144
|
+
const
|
|
145
|
+
{radius} = shape,
|
|
146
|
+
{bodyId, scale = 1, shapeDefinition} = options,
|
|
147
|
+
{b2Circle, b2CreateCircleShape} = platypus.game.box2d,
|
|
148
|
+
{x, y} = adjustedXY(shape, options),
|
|
149
|
+
circle = new b2Circle();
|
|
150
|
+
|
|
151
|
+
circle.radius = radius * scale;
|
|
152
|
+
circle.center.Set(x, y);
|
|
153
|
+
|
|
154
|
+
return b2CreateCircleShape(bodyId, formatSD(shapeDefinition), circle);
|
|
155
|
+
},
|
|
156
|
+
ellipse: (shape, ...args) => {
|
|
157
|
+
return createCapsule(shape.toCapsule(), ...args);
|
|
158
|
+
},
|
|
159
|
+
point: createPoint,
|
|
160
|
+
polygon: createPolygon,
|
|
161
|
+
polyline: createPolyline,
|
|
162
|
+
rectangle: createPolygon,
|
|
163
|
+
roundedRectangle: createPolygon,
|
|
164
|
+
segment: ({a, b}, options) => {
|
|
165
|
+
const
|
|
166
|
+
s = new platypus.game.box2d.b2Segment(),
|
|
167
|
+
{x: ax, y: ay} = adjustedXY(a, options),
|
|
168
|
+
{x: bx, y: by} = adjustedXY(b, options);
|
|
169
|
+
|
|
170
|
+
s.point1.x = ax;
|
|
171
|
+
s.point1.y = ay;
|
|
172
|
+
s.point2.x = bx;
|
|
173
|
+
s.point2.y = by;
|
|
174
|
+
|
|
175
|
+
return s;
|
|
176
|
+
}
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
export default function castToBox2D (shape, options = {}) {
|
|
180
|
+
const
|
|
181
|
+
{type} = shape,
|
|
182
|
+
cast = castFrom[type];
|
|
183
|
+
|
|
184
|
+
if (cast) {
|
|
185
|
+
return cast(shape, options);
|
|
186
|
+
} else {
|
|
187
|
+
platypus.debug.warn(`Unable to cast shape of type "${type}" to Box2D.`, shape);
|
|
188
|
+
return null;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/* global platypus */
|
|
2
|
+
import {Graphics} from 'pixi.js';
|
|
3
|
+
import adjustedXY from "./adjustedXY";
|
|
4
|
+
|
|
5
|
+
const
|
|
6
|
+
finish = (gfx, {fill, stroke}) => {
|
|
7
|
+
if (typeof fill === 'number') {
|
|
8
|
+
gfx.fill(fill);
|
|
9
|
+
}
|
|
10
|
+
if (typeof stroke === 'number') {
|
|
11
|
+
gfx.stroke(stroke);
|
|
12
|
+
}
|
|
13
|
+
return gfx;
|
|
14
|
+
},
|
|
15
|
+
getGraphics = ({graphics}) => graphics ?? new Graphics(),
|
|
16
|
+
castFrom = {
|
|
17
|
+
circle: (shape, options) => {
|
|
18
|
+
const
|
|
19
|
+
gfx = getGraphics(options),
|
|
20
|
+
{radius} = shape,
|
|
21
|
+
{scale = 1} = options,
|
|
22
|
+
{x, y} = adjustedXY(shape, options);
|
|
23
|
+
|
|
24
|
+
gfx.circle(x, y, radius * scale);
|
|
25
|
+
|
|
26
|
+
return finish(gfx, options);
|
|
27
|
+
},
|
|
28
|
+
ellipse: (shape, options) => {
|
|
29
|
+
const
|
|
30
|
+
gfx = getGraphics(options),
|
|
31
|
+
{halfHeight, halfWidth} = shape,
|
|
32
|
+
{scale = 1} = options,
|
|
33
|
+
{x, y} = adjustedXY(shape, options);
|
|
34
|
+
|
|
35
|
+
gfx.ellipse(x, y, halfWidth * scale, halfHeight * scale);
|
|
36
|
+
|
|
37
|
+
return finish(gfx, options);
|
|
38
|
+
},
|
|
39
|
+
point: (shape, options) => {
|
|
40
|
+
const
|
|
41
|
+
gfx = getGraphics(options),
|
|
42
|
+
{scale = 1} = options,
|
|
43
|
+
{x, y} = adjustedXY(shape, options);
|
|
44
|
+
|
|
45
|
+
gfx.circle(x, y, scale);
|
|
46
|
+
|
|
47
|
+
return finish(gfx, options);
|
|
48
|
+
},
|
|
49
|
+
polygon: (shape, options) => {
|
|
50
|
+
const
|
|
51
|
+
gfx = getGraphics(options);
|
|
52
|
+
|
|
53
|
+
gfx.poly(shape.points.map((point) => adjustedXY(point, options)), true);
|
|
54
|
+
|
|
55
|
+
return finish(gfx, options);
|
|
56
|
+
},
|
|
57
|
+
polyline: (shape, options) => {
|
|
58
|
+
const
|
|
59
|
+
gfx = getGraphics(options);
|
|
60
|
+
|
|
61
|
+
gfx.poly(shape.points.map((point) => adjustedXY(point, options)), false);
|
|
62
|
+
|
|
63
|
+
return finish(gfx, options);
|
|
64
|
+
},
|
|
65
|
+
rectangle: (shape, options) => {
|
|
66
|
+
const
|
|
67
|
+
gfx = getGraphics(options),
|
|
68
|
+
{height, width} = shape,
|
|
69
|
+
{scale = 1} = options,
|
|
70
|
+
{x, y} = adjustedXY(shape, options);
|
|
71
|
+
|
|
72
|
+
gfx.rect(x, y, width * scale, height * scale);
|
|
73
|
+
|
|
74
|
+
return finish(gfx, options);
|
|
75
|
+
},
|
|
76
|
+
roundedRectangle: (shape, options) => {
|
|
77
|
+
const
|
|
78
|
+
gfx = getGraphics(options),
|
|
79
|
+
{height, radius, width} = shape,
|
|
80
|
+
{scale = 1} = options,
|
|
81
|
+
{x, y} = adjustedXY(shape, options);
|
|
82
|
+
|
|
83
|
+
gfx.filletRect(x, y, width * scale, height * scale, -radius * scale);
|
|
84
|
+
|
|
85
|
+
return finish(gfx, options);
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
export default function castToPixiGraphics (shape, options = {}) {
|
|
90
|
+
const
|
|
91
|
+
{type} = shape,
|
|
92
|
+
cast = castFrom[type];
|
|
93
|
+
|
|
94
|
+
if (cast) {
|
|
95
|
+
return cast(shape, options);
|
|
96
|
+
} else {
|
|
97
|
+
platypus.debug.warn(`Unable to cast shape of type "${type}" to Pixi Graphics.`, shape);
|
|
98
|
+
return null;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/* global platypus */
|
|
2
|
+
import {Circle, Ellipse, Point, Polygon, Rectangle, RoundedRectangle} from 'pixi.js';
|
|
3
|
+
import adjustedXY from "./adjustedXY";
|
|
4
|
+
|
|
5
|
+
const
|
|
6
|
+
castFrom = {
|
|
7
|
+
circle: (shape, options) => {
|
|
8
|
+
const
|
|
9
|
+
{radius} = shape,
|
|
10
|
+
{scale = 1} = options,
|
|
11
|
+
{x, y} = adjustedXY(shape, options);
|
|
12
|
+
|
|
13
|
+
return new Circle(x, y, radius * scale);
|
|
14
|
+
},
|
|
15
|
+
ellipse: (shape, options) => {
|
|
16
|
+
const
|
|
17
|
+
{halfHeight, halfWidth} = shape,
|
|
18
|
+
{scale = 1} = options,
|
|
19
|
+
{x, y} = adjustedXY(shape, options);
|
|
20
|
+
|
|
21
|
+
return new Ellipse(x, y, halfWidth * scale, halfHeight * scale);
|
|
22
|
+
},
|
|
23
|
+
point: (shape, options) => {
|
|
24
|
+
const
|
|
25
|
+
{x, y} = adjustedXY(shape, options);
|
|
26
|
+
|
|
27
|
+
return new Point(x, y);
|
|
28
|
+
},
|
|
29
|
+
polygon: (shape, {local = true, scale = 1}) => {
|
|
30
|
+
return new Polygon(shape.toArray1D(local).map((c) => c * scale));
|
|
31
|
+
},
|
|
32
|
+
rectangle: (shape, options) => {
|
|
33
|
+
const
|
|
34
|
+
{height, width} = shape,
|
|
35
|
+
{scale = 1} = options,
|
|
36
|
+
{x, y} = adjustedXY(shape, options);
|
|
37
|
+
|
|
38
|
+
return new Rectangle(x, y, width * scale, height * scale);
|
|
39
|
+
},
|
|
40
|
+
roundedRectangle: (shape, options) => {
|
|
41
|
+
const
|
|
42
|
+
{height, radius, width} = shape,
|
|
43
|
+
{scale = 1} = options,
|
|
44
|
+
{x, y} = adjustedXY(shape, options);
|
|
45
|
+
|
|
46
|
+
return new RoundedRectangle(x, y, width * scale, height * scale, radius * scale);
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
export default function castToPixiShape (shape, options = {}) {
|
|
51
|
+
const
|
|
52
|
+
{type} = shape,
|
|
53
|
+
cast = castFrom[type];
|
|
54
|
+
|
|
55
|
+
if (cast) {
|
|
56
|
+
return cast(shape, options);
|
|
57
|
+
} else {
|
|
58
|
+
platypus.debug.warn(`Unable to cast shape of type "${type}" to Pixi Shape.`, shape);
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
}
|