-
Notifications
You must be signed in to change notification settings - Fork 263
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e2ed3cd
commit 08dd37f
Showing
12 changed files
with
184 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import Line from './Line'; | ||
|
||
export default Creator; | ||
|
||
declare namespace Creator { | ||
interface IConfig extends Phaser.Types.GameObjects.GameObjectConfig { } | ||
} | ||
|
||
declare function Creator( | ||
config?: Creator.IConfig, | ||
addToScene?: boolean, | ||
): Line; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import Line from './Line'; | ||
|
||
export default function ( | ||
config?: Line.IConfig | ||
): Line; | ||
|
||
export default function ( | ||
points?: Line.PointType[], | ||
lineWidth?: number, | ||
color?: number, | ||
alpha?: number, | ||
lineType?: Line.LineType | ||
): Line; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import BaseShapes from '../shapes/BaseShapes'; | ||
|
||
// import * as Phaser from 'phaser'; | ||
export default Line; | ||
|
||
declare namespace Line { | ||
type PointType = { x: number, y: number }; | ||
type LineType = 0 | 'bezier' | 1 | 'spline' | 2 | 'polyline' | 'poly' | 3 | 'straightline' | 'straight'; | ||
|
||
interface IConfig { | ||
points?: PointType[], | ||
lineWidth?: number, | ||
color?: number, | ||
alpha?: number, | ||
lineType?: LineType, | ||
pointRadius?: number, | ||
} | ||
} | ||
|
||
declare class Line extends BaseShapes { | ||
constructor( | ||
scene: Phaser.Scene, | ||
config?: Line.IConfig | ||
); | ||
|
||
constructor( | ||
scene: Phaser.Scene, | ||
points?: Line.PointType[], | ||
lineWidth?: number, | ||
color?: number, | ||
alpha?: number, | ||
lineType?: Line.LineType | ||
); | ||
|
||
setLine( | ||
points: Line.PointType[], | ||
lineType?: Line.LineType | ||
): this; | ||
|
||
setLineType(lineType: Line.LineType): this; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import ShapesUpdateMethods from './ShapesUpdateMethods.js'; | ||
import SetInteractiveMethods from './SetInteractiveMethods.js'; | ||
|
||
var Methods = {}; | ||
|
||
Object.assign( | ||
Methods, | ||
ShapesUpdateMethods, | ||
SetInteractiveMethods | ||
) | ||
|
||
export default Methods; |
40 changes: 40 additions & 0 deletions
40
plugins/gameobjects/shape/line/methods/SetInteractiveMethods.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import LinesToCircle from '../../../../utils/geom/intersects/LinesToCircle.js'; | ||
|
||
const Rectangle = Phaser.Geom.Rectangle; | ||
const RectangleContains = Phaser.Geom.Rectangle.Contains; | ||
const SetInteractiveBase = Phaser.GameObjects.GameObject.prototype.setInteractive; | ||
|
||
const GlobPoint = new Phaser.Geom.Circle(); | ||
|
||
var HitAreaCallback = function (shape, x, y, gameObject) { | ||
if (!RectangleContains(shape, x, y)) { | ||
return false; | ||
} | ||
|
||
GlobPoint.setTo(x, y, gameObject.pointRadius); | ||
|
||
var line = gameObject.getShapes()[0]; | ||
var points = line.pathData; | ||
|
||
return LinesToCircle(points, GlobPoint); | ||
} | ||
|
||
export default { | ||
setPointRadius(radius) { | ||
this.pointRadius = radius; | ||
return this; | ||
}, | ||
|
||
setInteractive(config) { | ||
if (config === undefined) { | ||
config = {}; | ||
} | ||
|
||
config.hitArea = new Rectangle(0, 0, this.width, this.height); | ||
config.hitAreaCallback = HitAreaCallback; | ||
|
||
SetInteractiveBase.call(this, config); | ||
|
||
return this; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,18 @@ | ||
import GetBounds from './GetBounds.js'; | ||
|
||
var SetTransform = function (line) { | ||
// Size | ||
var bounds = GetBounds.call(this, line.pathData, true); | ||
var width = Math.max(bounds.width, this.lineWidth); | ||
var height = Math.max(bounds.height, this.lineWidth); | ||
var SetTransform = function (line, bounds) { | ||
// Size | ||
var bounds = this.bounds; | ||
var radius = this.pointRadius; | ||
var x = bounds.x - radius; | ||
var y = bounds.y - radius; | ||
var width = bounds.width + (radius * 2); | ||
var height = bounds.height + (radius * 2); | ||
this.setSize(width, height); | ||
// Origin | ||
this.setOrigin(-bounds.x / width, -bounds.y / height); | ||
this.setOrigin(-x / width, -y / height); | ||
// Position | ||
var point = this.points[0]; | ||
this.setPosition(point.x, point.y); | ||
line.offset(-bounds.x, -bounds.y); | ||
line.offset(-x, -y); | ||
} | ||
|
||
export default SetTransform; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import Factory from './gameobjects/shape/line/Factory'; | ||
import Creator from './gameobjects/shape/line/Creator'; | ||
|
||
export default class extends Phaser.Plugins.BasePlugin { } | ||
|
||
declare module 'phaser' { | ||
namespace GameObjects { | ||
interface GameObjectFactory { | ||
rexLineShape: typeof Factory, | ||
} | ||
|
||
interface GameObjectCreator { | ||
rexLineShape: typeof Creator, | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
import Line from './gameobjects/shape/line/Line'; | ||
export default Line; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
const LineToCircle = Phaser.Geom.Intersects.LineToCircle; | ||
|
||
const tmpLine = new Phaser.Geom.Line(); | ||
|
||
var LinesToCircle = function (points, circle) { | ||
tmpLine.x1 = points[0]; | ||
tmpLine.y1 = points[1]; | ||
for (var i = 2, cnt = points.length; i < cnt; i += 2) { | ||
tmpLine.x2 = points[i]; | ||
tmpLine.y2 = points[i + 1]; | ||
|
||
if (LineToCircle(tmpLine, circle)) { | ||
return true; | ||
} | ||
|
||
tmpLine.x1 = tmpLine.x2; | ||
tmpLine.y1 = tmpLine.y2; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
export default LinesToCircle; |