Skip to content

Commit

Permalink
Rename
Browse files Browse the repository at this point in the history
  • Loading branch information
rexrainbow committed Nov 11, 2024
1 parent d18fa52 commit 311ddc9
Show file tree
Hide file tree
Showing 19 changed files with 64 additions and 59 deletions.
5 changes: 0 additions & 5 deletions examples/curve/line-type.bat

This file was deleted.

5 changes: 5 additions & 0 deletions examples/lineshape/line-type.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@echo off
set main=./examples/lineshape/line-type.js
cd ..
cd ..
npm run dev
13 changes: 9 additions & 4 deletions examples/curve/line-type.js → examples/lineshape/line-type.js
Original file line number Diff line number Diff line change
@@ -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() {
Expand Down Expand Up @@ -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()
Expand Down
23 changes: 0 additions & 23 deletions plugins/curveshape-plugin.js

This file was deleted.

2 changes: 0 additions & 2 deletions plugins/curveshape.js

This file was deleted.

File renamed without changes.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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);

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
};
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down Expand Up @@ -90,8 +90,8 @@ const CURVETYPE_MAP = {
}

Object.assign(
Path.prototype,
Line.prototype,
ShapesUpdateMethods,
)

export default Path;
export default Line;
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var DrawBezierCurve = function (curve) {
var DrawBezierCurve = function (line) {
var points = this.points;
var startPoint = points[0];
var startX = startPoint.x;
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var DrawQuadraticBezierCurve = function (curve) {
var DrawQuadraticBezierCurve = function (line) {
var points = this.points;

var startPoint = points[0];
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var DrawSpinleCurve = function (curve) {
var DrawSpinleCurve = function (line) {
var points = this.points;
var startPoint = points[0];
var startX = startPoint.x;
Expand All @@ -11,7 +11,7 @@ var DrawSpinleCurve = function (curve) {
splinePoints.push(point.y - startY);
}

curve
line
.startAt(0, 0)
.catmullRomTo(...splinePoints)
.end();
Expand Down
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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);

}
}
23 changes: 23 additions & 0 deletions plugins/lineshape-plugin.js
Original file line number Diff line number Diff line change
@@ -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;
2 changes: 2 additions & 0 deletions plugins/lineshape.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import Line from './gameobjects/shape/line/Line.js';
export default Line;

0 comments on commit 311ddc9

Please sign in to comment.