diff --git a/examples/curve/line-type.bat b/examples/curve/line-type.bat deleted file mode 100644 index 486fb744c1..0000000000 --- a/examples/curve/line-type.bat +++ /dev/null @@ -1,5 +0,0 @@ -@echo off -set main=./examples/curve/line-type.js -cd .. -cd .. -npm run dev \ No newline at end of file diff --git a/examples/lineshape/line-type.bat b/examples/lineshape/line-type.bat new file mode 100644 index 0000000000..c544fe6dc9 --- /dev/null +++ b/examples/lineshape/line-type.bat @@ -0,0 +1,5 @@ +@echo off +set main=./examples/lineshape/line-type.js +cd .. +cd .. +npm run dev \ No newline at end of file diff --git a/examples/curve/line-type.js b/examples/lineshape/line-type.js similarity index 83% rename from examples/curve/line-type.js rename to examples/lineshape/line-type.js index 8f96f47c50..fcd7956f5d 100644 --- a/examples/curve/line-type.js +++ b/examples/lineshape/line-type.js @@ -1,5 +1,5 @@ import phaser from 'phaser/src/phaser.js'; -import CurveShapePlugin from '../../plugins/curveshape-plugin.js'; +import CurveShapePlugin from '../../plugins/lineshape-plugin.js'; class Demo extends Phaser.Scene { constructor() { @@ -32,13 +32,18 @@ var GetPoints = function (offsetX, offsetY) { } var CreateCurve = function (scene, startX, startY, lineType, graphics) { - var curve = scene.add.rexCurveShape({ - points: GetPoints(startX, startY), + var points = GetPoints(startX, startY); + var curve = scene.add.rexLineShape({ + points: points, color: 0xffffff, lineType: lineType }) graphics.lineStyle(2, 0xff0000, 0.5).strokeRectShape(curve.getBounds()); - graphics.fillStyle(0xff0000).fillPoint(startX, startY, 10); + + for (var i = 0, cnt = points.length; i < cnt; i++) { + graphics.fillStyle(0xff0000).fillPoint(points[i].x, points[i].y, 10); + } + curve .setInteractive() diff --git a/plugins/curveshape-plugin.js b/plugins/curveshape-plugin.js deleted file mode 100644 index d06f5339dc..0000000000 --- a/plugins/curveshape-plugin.js +++ /dev/null @@ -1,23 +0,0 @@ -import Factory from './gameobjects/shape/curve/Factory.js'; -import Creator from './gameobjects/shape/curve/Creator.js'; -import Curve from './gameobjects/shape/curve/Curve.js'; -import SetValue from './utils/object/SetValue.js'; - -class CurvePlugin extends Phaser.Plugins.BasePlugin { - - constructor(pluginManager) { - super(pluginManager); - - // Register our new Game Object type - pluginManager.registerGameObject('rexCurveShape', Factory, Creator); - } - - start() { - var eventEmitter = this.game.events; - eventEmitter.on('destroy', this.destroy, this); - } -} - -SetValue(window, 'RexPlugins.GameObjects.CurveShape', Curve); - -export default CurvePlugin; \ No newline at end of file diff --git a/plugins/curveshape.js b/plugins/curveshape.js deleted file mode 100644 index 444bcd57fb..0000000000 --- a/plugins/curveshape.js +++ /dev/null @@ -1,2 +0,0 @@ -import Curve from './gameobjects/shape/curve/Curve.js'; -export default Curve; \ No newline at end of file diff --git a/plugins/gameobjects/shape/curve/Const.js b/plugins/gameobjects/shape/line/Const.js similarity index 100% rename from plugins/gameobjects/shape/curve/Const.js rename to plugins/gameobjects/shape/line/Const.js diff --git a/plugins/gameobjects/shape/curve/Creator.js b/plugins/gameobjects/shape/line/Creator.js similarity index 85% rename from plugins/gameobjects/shape/curve/Creator.js rename to plugins/gameobjects/shape/line/Creator.js index 9420da0612..4327d1ebec 100644 --- a/plugins/gameobjects/shape/curve/Creator.js +++ b/plugins/gameobjects/shape/line/Creator.js @@ -1,4 +1,4 @@ -import Curve from './Curve.js'; +import Line from './Line.js'; const GetAdvancedValue = Phaser.Utils.Objects.GetAdvancedValue; const GetValue = Phaser.Utils.Objects.GetValue; @@ -14,7 +14,7 @@ export default function (config, addToScene) { var color = GetAdvancedValue(config, 'color', 0xffffff); var alpha = GetAdvancedValue(config, 'alpha', 1); var lineType = GetAdvancedValue(config, 'lineType', 0); - var gameObject = new Curve(this.scene, points, lineWidth, color, alpha, lineType); + var gameObject = new Line(this.scene, points, lineWidth, color, alpha, lineType); BuildGameObject(this.scene, gameObject, config); diff --git a/plugins/gameobjects/shape/curve/Factory.js b/plugins/gameobjects/shape/line/Factory.js similarity index 53% rename from plugins/gameobjects/shape/curve/Factory.js rename to plugins/gameobjects/shape/line/Factory.js index eb66671be2..e5596f4290 100644 --- a/plugins/gameobjects/shape/curve/Factory.js +++ b/plugins/gameobjects/shape/line/Factory.js @@ -1,7 +1,7 @@ -import Curve from './Curve.js'; +import Line from './Line.js'; export default function (points, lineWidth, color, alpha, lineType) { - var gameObject = new Curve(this.scene, points, lineWidth, color, alpha, lineType); + var gameObject = new Line(this.scene, points, lineWidth, color, alpha, lineType); this.scene.add.existing(gameObject); return gameObject; }; \ No newline at end of file diff --git a/plugins/gameobjects/shape/curve/Curve.js b/plugins/gameobjects/shape/line/Line.js similarity index 97% rename from plugins/gameobjects/shape/curve/Curve.js rename to plugins/gameobjects/shape/line/Line.js index 576811b2ff..cd5911bc63 100644 --- a/plugins/gameobjects/shape/curve/Curve.js +++ b/plugins/gameobjects/shape/line/Line.js @@ -2,7 +2,7 @@ import BaseShapes from '../shapes/BaseShapes.js'; import ShapesUpdateMethods from './methods/ShapesUpdateMethods.js'; import { BEZIER, SPLINE, POLYLINE, STRAIGHTLINE } from './Const.js'; -class Path extends BaseShapes { +class Line extends BaseShapes { constructor(scene, points, lineWidth, color, alpha, lineType) { if (points !== undefined) { if (typeof (points) === 'number') { @@ -90,8 +90,8 @@ const CURVETYPE_MAP = { } Object.assign( - Path.prototype, + Line.prototype, ShapesUpdateMethods, ) -export default Path; \ No newline at end of file +export default Line; \ No newline at end of file diff --git a/plugins/gameobjects/shape/curve/methods/DrawCubicBezierCurve.js b/plugins/gameobjects/shape/line/methods/DrawCubicBezierCurve.js similarity index 92% rename from plugins/gameobjects/shape/curve/methods/DrawCubicBezierCurve.js rename to plugins/gameobjects/shape/line/methods/DrawCubicBezierCurve.js index 5698100fab..c7edf33aa7 100644 --- a/plugins/gameobjects/shape/curve/methods/DrawCubicBezierCurve.js +++ b/plugins/gameobjects/shape/line/methods/DrawCubicBezierCurve.js @@ -1,4 +1,4 @@ -var DrawBezierCurve = function (curve) { +var DrawBezierCurve = function (line) { var points = this.points; var startPoint = points[0]; var startX = startPoint.x; @@ -16,7 +16,7 @@ var DrawBezierCurve = function (curve) { var endX = endPoint.x - startX; var endY = endPoint.y - startY; - curve + line .startAt(0, 0) .cubicBezierTo(cx0, cy0, cx1, cy1, endX, endY) .end(); diff --git a/plugins/gameobjects/shape/curve/methods/DrawPolyLine.js b/plugins/gameobjects/shape/line/methods/DrawPolyLine.js similarity index 74% rename from plugins/gameobjects/shape/curve/methods/DrawPolyLine.js rename to plugins/gameobjects/shape/line/methods/DrawPolyLine.js index ffe4644206..8722514f76 100644 --- a/plugins/gameobjects/shape/curve/methods/DrawPolyLine.js +++ b/plugins/gameobjects/shape/line/methods/DrawPolyLine.js @@ -1,18 +1,18 @@ -var DrawPolyLine = function (lines) { +var DrawPolyLine = function (line) { var points = this.points; var startPoint = points[0]; var startX = startPoint.x; var startY = startPoint.y; - lines.startAt(0, 0); + line.startAt(0, 0); for (var i = 1, cnt = points.length; i < cnt; i++) { var point = points[i]; var x = point.x - startX; var y = point.y - startY; - lines.lineTo(x, y); + line.lineTo(x, y); } - lines.end(); + line.end(); } export default DrawPolyLine; \ No newline at end of file diff --git a/plugins/gameobjects/shape/curve/methods/DrawQuadraticBezierCurve.js b/plugins/gameobjects/shape/line/methods/DrawQuadraticBezierCurve.js similarity index 88% rename from plugins/gameobjects/shape/curve/methods/DrawQuadraticBezierCurve.js rename to plugins/gameobjects/shape/line/methods/DrawQuadraticBezierCurve.js index 892e70ffa8..5baf4dd4dd 100644 --- a/plugins/gameobjects/shape/curve/methods/DrawQuadraticBezierCurve.js +++ b/plugins/gameobjects/shape/line/methods/DrawQuadraticBezierCurve.js @@ -1,4 +1,4 @@ -var DrawQuadraticBezierCurve = function (curve) { +var DrawQuadraticBezierCurve = function (line) { var points = this.points; var startPoint = points[0]; @@ -13,7 +13,7 @@ var DrawQuadraticBezierCurve = function (curve) { var endX = endPoint.x - startX; var endY = endPoint.y - startY; - curve + line .startAt(0, 0) .quadraticBezierTo(cx, cy, endX, endY) .end(); diff --git a/plugins/gameobjects/shape/curve/methods/DrawSpinleCurve.js b/plugins/gameobjects/shape/line/methods/DrawSpinleCurve.js similarity index 89% rename from plugins/gameobjects/shape/curve/methods/DrawSpinleCurve.js rename to plugins/gameobjects/shape/line/methods/DrawSpinleCurve.js index 38c6b65a92..77a26a9ff6 100644 --- a/plugins/gameobjects/shape/curve/methods/DrawSpinleCurve.js +++ b/plugins/gameobjects/shape/line/methods/DrawSpinleCurve.js @@ -1,4 +1,4 @@ -var DrawSpinleCurve = function (curve) { +var DrawSpinleCurve = function (line) { var points = this.points; var startPoint = points[0]; var startX = startPoint.x; @@ -11,7 +11,7 @@ var DrawSpinleCurve = function (curve) { splinePoints.push(point.y - startY); } - curve + line .startAt(0, 0) .catmullRomTo(...splinePoints) .end(); diff --git a/plugins/gameobjects/shape/curve/methods/DrawStraightLine.js b/plugins/gameobjects/shape/line/methods/DrawStraightLine.js similarity index 100% rename from plugins/gameobjects/shape/curve/methods/DrawStraightLine.js rename to plugins/gameobjects/shape/line/methods/DrawStraightLine.js diff --git a/plugins/gameobjects/shape/curve/methods/GetBounds.js b/plugins/gameobjects/shape/line/methods/GetBounds.js similarity index 100% rename from plugins/gameobjects/shape/curve/methods/GetBounds.js rename to plugins/gameobjects/shape/line/methods/GetBounds.js diff --git a/plugins/gameobjects/shape/curve/methods/SetTransform.js b/plugins/gameobjects/shape/line/methods/SetTransform.js similarity index 100% rename from plugins/gameobjects/shape/curve/methods/SetTransform.js rename to plugins/gameobjects/shape/line/methods/SetTransform.js diff --git a/plugins/gameobjects/shape/curve/methods/ShapesUpdateMethods.js b/plugins/gameobjects/shape/line/methods/ShapesUpdateMethods.js similarity index 71% rename from plugins/gameobjects/shape/curve/methods/ShapesUpdateMethods.js rename to plugins/gameobjects/shape/line/methods/ShapesUpdateMethods.js index ae6c39fa4e..284f0b77dc 100644 --- a/plugins/gameobjects/shape/curve/methods/ShapesUpdateMethods.js +++ b/plugins/gameobjects/shape/line/methods/ShapesUpdateMethods.js @@ -1,4 +1,4 @@ -import { Lines } from '../../shapes/geoms'; +import { Lines } from '../../shapes/geoms/index.js'; import { BEZIER, SPLINE, POLYLINE, STRAIGHTLINE } from '../Const.js'; import DrawQuadraticBezierCurve from './DrawQuadraticBezierCurve.js'; import DrawCubicBezierCurve from './DrawCubicBezierCurve.js'; @@ -15,24 +15,24 @@ export default { updateShapes() { // Set style - var lines = this.getShapes()[0] + var line = this.getShapes()[0] .lineStyle(this.lineWidth, this.strokeColor, this.strokeAlpha) var points = this.points; if ((this.lineType === STRAIGHTLINE) || (points.length == 2)) { - DrawStraightLine.call(this, lines); + DrawStraightLine.call(this, line); } else if ((this.lineType === BEZIER) && (points.length === 3)) { - DrawQuadraticBezierCurve.call(this, lines); + DrawQuadraticBezierCurve.call(this, line); } else if ((this.lineType === BEZIER) && (points.length === 4)) { - DrawCubicBezierCurve.call(this, lines); + DrawCubicBezierCurve.call(this, line); } else if (this.lineType === POLYLINE) { - DrawPolyLine.call(this, lines); + DrawPolyLine.call(this, line); } else { - DrawSpinleCurve.call(this, lines); + DrawSpinleCurve.call(this, line); } - SetTransform.call(this, lines); + SetTransform.call(this, line); } } \ No newline at end of file diff --git a/plugins/lineshape-plugin.js b/plugins/lineshape-plugin.js new file mode 100644 index 0000000000..0fc50d87d0 --- /dev/null +++ b/plugins/lineshape-plugin.js @@ -0,0 +1,23 @@ +import Factory from './gameobjects/shape/line/Factory.js'; +import Creator from './gameobjects/shape/line/Creator.js'; +import Line from './gameobjects/shape/line/Line.js'; +import SetValue from './utils/object/SetValue.js'; + +class LinePlugin extends Phaser.Plugins.BasePlugin { + + constructor(pluginManager) { + super(pluginManager); + + // Register our new Game Object type + pluginManager.registerGameObject('rexLineShape', Factory, Creator); + } + + start() { + var eventEmitter = this.game.events; + eventEmitter.on('destroy', this.destroy, this); + } +} + +SetValue(window, 'RexPlugins.GameObjects.LineShape', Line); + +export default LinePlugin; \ No newline at end of file diff --git a/plugins/lineshape.js b/plugins/lineshape.js new file mode 100644 index 0000000000..b16ca5a7b2 --- /dev/null +++ b/plugins/lineshape.js @@ -0,0 +1,2 @@ +import Line from './gameobjects/shape/line/Line.js'; +export default Line; \ No newline at end of file