diff --git a/README.md b/README.md index 8ac5c4f1c..71fea38d8 100644 --- a/README.md +++ b/README.md @@ -75,8 +75,8 @@ The following applications were developed using ScalaJs.io: | Application | Frontend | Backend | Scalajs.io version | Description | |------------------------------------------------------------------------|-----------------------|--------------------|--------------------|------------------------------------------| -| [Scalajs-Invaders](https://github.com/ldaniels528/scalajs-invaders) | Scala.js + DOM | Scala + NodeJS | 0.3.0.0 | Port of Phaser Invaders. | -| [Socialize](https://github.com/ldaniels528/scalajs-nodejs-socialized) | Scala.js + AngularJS | Scala.js + NodeJS | 0.2.3.1 | A Facebook-inspired Social networking web application. | +| [Scalajs-Invaders](https://github.com/ldaniels528/scalajs-invaders) | Scala.js + DOM | Scala + NodeJS | 0.3.0.1 | Port of Phaser Invaders. | +| [Socialize](https://github.com/ldaniels528/scalajs-nodejs-socialized) | Scala.js + AngularJS | Scala.js + NodeJS | 0.3.0.3 | A Facebook-inspired Social networking web application. | | [Todo MVC](https://github.com/ldaniels528/scalajs-nodejs-todomvc) | Scala.js + AngularJS | Scala.js + NodeJS | 0.2.3.1 | A simple Todo example application. | | [Trifecta](https://github.com/ldaniels528/trifecta) | Scala.js + AngularJS | Scala + Play 2.4.x | 0.3.0.0 | Trifecta is a web-based and CLI tool that simplifies inspecting Kafka messages and Zookeeper data. | diff --git a/browser/dom/src/main/scala/io/scalajs/dom/ws/ErrorEvent.scala b/browser/dom/src/main/scala/io/scalajs/dom/ws/ErrorEvent.scala index af47d0526..a5cd26170 100644 --- a/browser/dom/src/main/scala/io/scalajs/dom/ws/ErrorEvent.scala +++ b/browser/dom/src/main/scala/io/scalajs/dom/ws/ErrorEvent.scala @@ -9,4 +9,8 @@ import scala.scalajs.js * being a WebSocket or a WebRTC RTCDataChannel. */ @js.native -class ErrorEvent() extends Event {} +class ErrorEvent() extends Event { + + def message: String = js.native + +} diff --git a/browser/phaser/src/main/scala/io/scalajs/dom/html/phaser/ArcadePhysics.scala b/browser/phaser/src/main/scala/io/scalajs/dom/html/phaser/ArcadePhysics.scala deleted file mode 100644 index 636cfb6ed..000000000 --- a/browser/phaser/src/main/scala/io/scalajs/dom/html/phaser/ArcadePhysics.scala +++ /dev/null @@ -1,30 +0,0 @@ -package io.scalajs.dom.html.phaser - -import io.scalajs.dom.html.pixijs.DisplayObject - -import scala.scalajs.js -import scala.scalajs.js.annotation.JSName -import scala.scalajs.js.| - -@js.native -@JSName("Phaser.ArcadePhysics") -class ArcadePhysics extends js.Object { - - ///////////////////////////////////////////////////////////////////////////////// - // Properties - ///////////////////////////////////////////////////////////////////////////////// - - - ///////////////////////////////////////////////////////////////////////////////// - // Methods - ///////////////////////////////////////////////////////////////////////////////// - - def moveToObject(displayObject: DisplayObject, destination: Any, speed: Int = 60, maxTime: Long = 0): Double = js.native - - def overlap(object1: Sprite | Group[_] | js.Array[_], - object2: Sprite | Group[_] | js.Array[_], - overlapCallback: js.Function2[_, _, _], - processCallback: Option[js.Function2[_, _, Boolean]], - callbackContext: js.Any = js.native): Unit = js.native - -} diff --git a/browser/phaser/src/main/scala/io/scalajs/dom/html/phaser/AudioSprite.scala b/browser/phaser/src/main/scala/io/scalajs/dom/html/phaser/AudioSprite.scala index 609593cf4..cc6d7dce7 100644 --- a/browser/phaser/src/main/scala/io/scalajs/dom/html/phaser/AudioSprite.scala +++ b/browser/phaser/src/main/scala/io/scalajs/dom/html/phaser/AudioSprite.scala @@ -11,7 +11,7 @@ import scala.scalajs.js.annotation.JSName */ @js.native @JSName("Phaser.AudioSprite") -class AudioSprite(val game: Game, val key: String) extends js.Object { +class AudioSprite(var game: Phaser.Game, var key: String) extends js.Object { ///////////////////////////////////////////////////////////////////////////////// // Properties diff --git a/browser/phaser/src/main/scala/io/scalajs/dom/html/phaser/BitmapText.scala b/browser/phaser/src/main/scala/io/scalajs/dom/html/phaser/BitmapText.scala index 36a2ddcb2..313983e7b 100644 --- a/browser/phaser/src/main/scala/io/scalajs/dom/html/phaser/BitmapText.scala +++ b/browser/phaser/src/main/scala/io/scalajs/dom/html/phaser/BitmapText.scala @@ -29,7 +29,7 @@ import scala.scalajs.js.annotation.JSName */ @js.native @JSName("Phaser.BitmapText") -class BitmapText(val game: Game, +class BitmapText(var game: Phaser.Game, override var x: Double, override var y: Double, val font: String, @@ -62,4 +62,14 @@ class BitmapText(val game: Game, */ override var angle: Double = js.native + /** + * Base destroy method for generic display objects. + */ + override def destroy(): Unit = js.native + + /** + * Base destroy method for generic display objects. + */ + override def destroy(destroyChildren: Boolean): Unit = js.native + } \ No newline at end of file diff --git a/browser/phaser/src/main/scala/io/scalajs/dom/html/phaser/Cache.scala b/browser/phaser/src/main/scala/io/scalajs/dom/html/phaser/Cache.scala index 0e1892c37..cf26a57b2 100644 --- a/browser/phaser/src/main/scala/io/scalajs/dom/html/phaser/Cache.scala +++ b/browser/phaser/src/main/scala/io/scalajs/dom/html/phaser/Cache.scala @@ -30,7 +30,7 @@ import scala.scalajs.js.annotation.JSName */ @js.native @JSName("Phaser.Cache") -class Cache(val game: Game) extends js.Object {} +class Cache(var game: Phaser.Game) extends js.Object {} @js.native @JSName("Phaser.Cache") diff --git a/browser/phaser/src/main/scala/io/scalajs/dom/html/phaser/Camera.scala b/browser/phaser/src/main/scala/io/scalajs/dom/html/phaser/Camera.scala index d20ee9624..c63de12fb 100644 --- a/browser/phaser/src/main/scala/io/scalajs/dom/html/phaser/Camera.scala +++ b/browser/phaser/src/main/scala/io/scalajs/dom/html/phaser/Camera.scala @@ -15,7 +15,7 @@ import scala.scalajs.js.annotation.JSName */ @js.native @JSName("Phaser.Camera") -class Camera(val game: Game, val id: Int = 0, var x: Double, var y: Double, var width: Double, var height: Double) +class Camera(var game: Phaser.Game, val id: Int = 0, var x: Double, var y: Double, var width: Double, var height: Double) extends js.Object { /** diff --git a/browser/phaser/src/main/scala/io/scalajs/dom/html/phaser/GameObjectCreator.scala b/browser/phaser/src/main/scala/io/scalajs/dom/html/phaser/GameObjectCreator.scala index dcfae5592..d941b72c8 100644 --- a/browser/phaser/src/main/scala/io/scalajs/dom/html/phaser/GameObjectCreator.scala +++ b/browser/phaser/src/main/scala/io/scalajs/dom/html/phaser/GameObjectCreator.scala @@ -13,7 +13,7 @@ import scala.scalajs.js.annotation.JSName */ @js.native @JSName("Phaser.GameObjectCreator") -class GameObjectCreator(val game: Game) extends js.Object { +class GameObjectCreator(var game: Phaser.Game) extends js.Object { ///////////////////////////////////////////////////////////////////////////////// // Properties diff --git a/browser/phaser/src/main/scala/io/scalajs/dom/html/phaser/Gamepad.scala b/browser/phaser/src/main/scala/io/scalajs/dom/html/phaser/Gamepad.scala new file mode 100644 index 000000000..8944a9077 --- /dev/null +++ b/browser/phaser/src/main/scala/io/scalajs/dom/html/phaser/Gamepad.scala @@ -0,0 +1,171 @@ +package io.scalajs.dom.html.phaser + +import io.scalajs.RawOptions + +import scala.scalajs.js +import scala.scalajs.js.annotation.{JSName, ScalaJSDefined} + +/** + * The Gamepad class handles gamepad input and dispatches gamepad events. + * + * Remember to call gamepad.start(). + * + * HTML5 GAMEPAD API SUPPORT IS AT AN EXPERIMENTAL STAGE! + * At moment of writing this (end of 2013) only Chrome supports parts of it out of the box. Firefox supports it + * via prefs flags (about:config, search gamepad). The browsers map the same controllers differently. + * This class has constants for Windows 7 Chrome mapping of XBOX 360 controller. + * @see http://phaser.io/docs/2.6.2/Phaser.Gamepad.html + */ +@js.native +@JSName("Phaser.Gamepad") +class Gamepad(var game: Phaser.Game) extends js.Object { + + ///////////////////////////////////////////////////////////////////////////////// + // Properties + ///////////////////////////////////////////////////////////////////////////////// + + /** + * If the gamepad input is active or not - if not active it should not be updated from Input.js + */ + def active: Boolean = js.native + + /** + * The context under which the callbacks are run. + */ + var callbackContext: js.Object = js.native + + /** + * Gamepad input will only be processed if enabled (default: true). + */ + var enabled: Boolean = js.native + + /** + * This callback is invoked every time any gamepad axis is changed. + */ + var onAxisCallback: js.Function = js.native + + /** + * This callback is invoked every time any gamepad is disconnected + */ + var onConnectCallback: js.Function = js.native + + /** + * This callback is invoked every time any gamepad button is pressed down. + */ + var onDownCallback: js.Function = js.native + + /** + * This callback is invoked every time any gamepad button is changed to a value where value > 0 and value < 1. + */ + var onFloatCallback: js.Function = js.native + + /** + * This callback is invoked every time any gamepad button is released. + */ + var onUpCallback: js.Function = js.native + + /** + * Gamepad #1 + */ + def pad1: Phaser.SinglePad = js.native + + /** + * Gamepad #2 + */ + def pad2: Phaser.SinglePad = js.native + + /** + * Gamepad #3 + */ + def pad3: Phaser.SinglePad = js.native + + /** + * Gamepad #4 + */ + def pad4: Phaser.SinglePad = js.native + + /** + * How many live gamepads are currently connected. + */ + def padsConnected: Int = js.native + + /** + * Whether or not gamepads are supported in current browser. + */ + def supported: Boolean = js.native + + ///////////////////////////////////////////////////////////////////////////////// + // Methods + ///////////////////////////////////////////////////////////////////////////////// + + /** + * Add callbacks to the main Gamepad handler to handle connect/disconnect/button down/button + * up/axis change/float value buttons. + * @param context The context under which the callbacks are run. + * @param callbacks Object that takes six different callback methods: + * onConnectCallback, onDisconnectCallback, onDownCallback, onUpCallback, + * onAxisCallback, onFloatCallback + */ + def addCallbacks(context: RawOptions, callbacks: Callbacks): Unit = js.native + + /** + * Destroys this object and the associated event listeners. + */ + def destroy(): Unit = js.native + + /** + * Returns true if the button is currently pressed down, on ANY gamepad. + * @param buttonCode The buttonCode of the button to check for. + * @return True if a button is currently down. + */ + def isDown(buttonCode: ButtonCode): Boolean = js.native + + /** + * Returns the "just released" state of a button from ANY gamepad connected. + * Just released is considered as being true if the button was released within + * the duration given (default 250ms). + * @param buttonCode The buttonCode of the button to check for. + * @param duration The duration below which the button is considered as being just released. + * @return True if the button is just released otherwise false. + */ + def justPressed(buttonCode: ButtonCode, duration: Double = js.native): Boolean = js.native + + /** + * Reset all buttons/axes of all gamepads + */ + def reset(): Unit = js.native + + /** + * Sets the deadZone variable for all four gamepads + */ + def setDeadZones(): Unit = js.native + + /** + * Starts the Gamepad event handling. + * This MUST be called manually before Phaser will start polling the Gamepad API. + */ + def start(): Unit = js.native + + /** + * Stops the Gamepad event handling. + */ + def stop(): Unit = js.native + +} + +/** + * Callbacks Object + * @param onConnectCallback + * @param onDisconnectCallback + * @param onDownCallback + * @param onUpCallback + * @param onAxisCallback + * @param onFloatCallback + */ +@ScalaJSDefined +class Callbacks(var onConnectCallback: js.UndefOr[js.Function] = js.undefined, + var onDisconnectCallback: js.UndefOr[js.Function] = js.undefined, + var onDownCallback: js.UndefOr[js.Function] = js.undefined, + var onUpCallback: js.UndefOr[js.Function] = js.undefined, + var onAxisCallback: js.UndefOr[js.Function] = js.undefined, + var onFloatCallback: js.UndefOr[js.Function] = js.undefined) extends js.Object \ No newline at end of file diff --git a/browser/phaser/src/main/scala/io/scalajs/dom/html/phaser/Graphics.scala b/browser/phaser/src/main/scala/io/scalajs/dom/html/phaser/Graphics.scala index a3cbdb30b..195c2cb79 100644 --- a/browser/phaser/src/main/scala/io/scalajs/dom/html/phaser/Graphics.scala +++ b/browser/phaser/src/main/scala/io/scalajs/dom/html/phaser/Graphics.scala @@ -16,7 +16,7 @@ import scala.scalajs.js.annotation.JSName */ @js.native @JSName("Phaser.Graphics") -class Graphics(val game: Phaser.Game, +class Graphics(var game: Phaser.Game, override var x: Double, override var y: Double) extends pixijs.Graphics @@ -32,6 +32,27 @@ class Graphics(val game: Phaser.Game, with Phaser.Component.PhysicsBody with Phaser.Component.Reset { + /** + * The angle property is the rotation of the Game Object in degrees from its original orientation. + * + * Values from 0 to 180 represent clockwise rotation; values from 0 to -180 represent counterclockwise rotation. + * + * Values outside this range are added to or subtracted from 360 to obtain a value within the range. + * For example, the statement player.angle = 450 is the same as player.angle = 90. + * + * If you wish to work in radians instead of degrees you can use the property rotation instead. + * Working in radians is slightly faster as it doesn't have to perform any calculations. + */ override var angle: Double = js.native + /** + * Base destroy method for generic display objects. + */ + override def destroy(): Unit = js.native + + /** + * Base destroy method for generic display objects. + */ + override def destroy(destroyChildren: Boolean): Unit = js.native + } \ No newline at end of file diff --git a/browser/phaser/src/main/scala/io/scalajs/dom/html/phaser/Group.scala b/browser/phaser/src/main/scala/io/scalajs/dom/html/phaser/Group.scala index 9c2bb4e50..25a20e65c 100644 --- a/browser/phaser/src/main/scala/io/scalajs/dom/html/phaser/Group.scala +++ b/browser/phaser/src/main/scala/io/scalajs/dom/html/phaser/Group.scala @@ -1,6 +1,6 @@ package io.scalajs.dom.html.phaser -import io.scalajs.dom.html.pixijs.{DisplayObject, DisplayObjectContainer} +import io.scalajs.dom.html.pixijs.{DisplayObject, PIXI} import scala.scalajs.js import scala.scalajs.js.annotation.JSName @@ -24,47 +24,343 @@ import scala.scalajs.js.| * them. Change the body type with #physicsBodyType. * @param physicsBodyType The physics body type to use when physics bodies are automatically added. * See #physicsBodyType for values. + * @see http://phaser.io/docs/2.6.2/Phaser.Group.html */ @js.native @JSName("Phaser.Group") -class Group[T](var game: Game, +class Group[T](var game: Phaser.Game, var parent: DisplayObject, - var name: String, - var addToStage: Boolean, - var enableBody: Boolean, - var physicsBodyType: Int) - extends DisplayObjectContainer { + var name: String = js.native, + var addToStage: Boolean = js.native, + var enableBody: Boolean = js.native, + var physicsBodyType: Int = js.native) + extends PIXI.DisplayObjectContainer { ///////////////////////////////////////////////////////////////////////////////// // Properties ///////////////////////////////////////////////////////////////////////////////// /** - * The alive property is useful for Groups that are children of other Groups and need to be included/excluded in - * checks like forEachAlive. + * The alive property is useful for Groups that are children of other Groups and + * need to be included/excluded inchecks like forEachAlive. */ var alive: Boolean = js.native + /** + * The bottom coordinate of this Group. + * It is derived by calling `getBounds`, calculating the Groups dimensions based on its + * visible children. + */ + var bottom: Double = js.native + + /** + * If this object is fixedToCamera then this stores the x/y position offset relative + * to the top-left of the camera view. + * + * If the parent of this Group is also fixedToCamera then the offset here is in addition + * to that and should typically be disabled. + */ + var cameraOffset: Phaser.Point = js.native + + /** + * The center x coordinate of this Group. + * It is derived by calling getBounds, calculating the Groups dimensions based on its + * visible children. + */ + var centerX: Double = js.native + + /** + * The center y coordinate of this Group. + * It is derived by calling getBounds, calculating the Groups dimensions based on its + * visible children. + */ + var centerY: Double = js.native + + /** + * The type of objects that will be created when using create or createMultiple. + * Any object may be used but it should extend either Sprite or Image and accept + * the same constructor arguments: + * when a new object is created it is passed the following parameters to its + * constructor: `(game, x, y, key, frame)`. + */ + var classType: js.Object = js.native + + /** + * The current display object that the group cursor is pointing to, if any. (Can be set manually.) + * The cursor is a way to iterate through the children in a Group using next and previous. + */ + var cursor: DisplayObject = js.native + + /** + * The current index of the Group cursor. Advance it with Group.next. + */ + def cursorIndex: Int = js.native + + /** + * If true when a physics body is created (via enableBody) it will create a physics debug object as well. + * This only works for P2 bodies. + */ + var enableBodyDebug: Boolean = js.native + + /** + * If exists is true the group is updated, otherwise it is skipped. + */ + var exists: Boolean = js.native + + /** + * A Group that is fixed to the camera uses its x/y coordinates as + * offsets from the top left of the camera. These are stored in Group.cameraOffset. + * + * Note that the cameraOffset values are in addition to any parent in the display list. + * So if this Group was in a Group that has x: 200, then this will be added to the cameraOffset.x + */ + var fixedToCamera: Boolean = js.native + + /** + * The hash array is an array belonging to this Group into which you can add any of its children + * via `Group.addToHash` and `Group.removeFromHash`. + * + * Only children of this Group can be added to and removed from the hash. + * + * This hash is used automatically by Phaser Arcade Physics in order to perform non z-index + * based destructive sorting. + * + * However if you don't use Arcade Physics, or this isn't a physics enabled Group, then you + * can use the hash to perform your own sorting and filtering of Group + */ + var hash: js.Array[_] = js.native + + /** + * A group with `ignoreDestroy` set to `true` ignores all calls to its `destroy` method. + */ + var ignoreDestroy: Boolean = js.native + + /** + * A Group with inputEnableChildren set to true will automatically call inputEnabled = true + * on any children added to, or created by, this Group. + * + * If there are children already in the Group at the time you set this property, they are not changed. + */ + var inputEnableChildren: Boolean = js.native + + /** + * The left coordinate of this Group. + * It is derived by calling `getBounds`, calculating the Groups dimensions based on its + * visible children. + */ + var left: Double = js.native + + /** + * Total number of children in this group, regardless of exists/alive status. + */ + def length: Int = js.native + + /** + * This Signal is dispatched whenever a child of this Group emits an onInputDown signal as a result + * of having been interacted with by a Pointer. You can bind functions to this Signal instead of to + * every child Sprite. + * + * This Signal is sent 2 arguments: A reference to the Sprite that triggered the signal, and + * a reference to the Pointer that caused it. + */ + var onChildInputDown: Phaser.Signal = js.native + + /** + * This Signal is dispatched whenever a child of this Group emits an onInputOut signal as a result + * of having been interacted with by a Pointer. You can bind functions to this Signal instead of to + * every child Sprite. + * + * This Signal is sent 2 arguments: A reference to the Sprite that triggered the signal, and + * a reference to the Pointer that caused it. + */ + var onChildInputOut: Phaser.Signal = js.native + + /** + * This Signal is dispatched whenever a child of this Group emits an onInputOver signal as a result + * of having been interacted with by a Pointer. You can bind functions to this Signal instead of to + * every child Sprite. + * + * This Signal is sent 2 arguments: A reference to the Sprite that triggered the signal, and + * a reference to the Pointer that caused it. + */ + var onChildInputOver: Phaser.Signal = js.native + + /** + * This Signal is dispatched whenever a child of this Group emits an onInputUp signal as a result + * of having been interacted with by a Pointer. You can bind functions to this Signal instead of to + * every child Sprite. + * + * This Signal is sent 3 arguments: A reference to the Sprite that triggered the signal, + * a reference to the Pointer that caused it, and a boolean value isOver that tells you if the Pointer + * is still over the Sprite or not. + */ + var onChildInputUp: Phaser.Signal = js.native + + /** + * This signal is dispatched when the group is destroyed. + */ + var onDestroy: Phaser.Signal = js.native + + /** + * A Group is that has `pendingDestroy` set to `true` is flagged to have its destroy method + * called on the next logic update. + * You can set it directly to flag the Group to be destroyed on its next update. + * + * This is extremely useful if you wish to destroy a Group from within one of its own callbacks + * or a callback of one of its children. + */ + var pendingDestroy: Boolean = js.native + + /** + * If this Group contains Arcade Physics Sprites you can set a custom sort direction via this property. + * + * It should be set to one of the Phaser.Physics.Arcade sort direction constants: + * + * Phaser.Physics.Arcade.SORT_NONE + * Phaser.Physics.Arcade.LEFT_RIGHT + * Phaser.Physics.Arcade.RIGHT_LEFT + * Phaser.Physics.Arcade.TOP_BOTTOM + * Phaser.Physics.Arcade.BOTTOM_TOP + * + * If set to null the Group will use whatever Phaser.Physics.Arcade.sortDirection + * is set to. This is the default behavior. + */ + var physicsSortDirection: Int = js.native + + /** + * The const physics body type of this object. + */ + def physicsType: Int = js.native + + /** + * The right coordinate of this Group. + * + * It is derived by calling getBounds, calculating the Groups dimensions based on its + * visible children. + */ + var right: Double = js.native + + /** + * The angle of rotation of the group container, in radians. + * + * This will adjust the group container itself by modifying its rotation. + * This will have no impact on the rotation value of its children, but it + * will update their worldTransform and on-screen position. + */ + var rotation: Double = js.native + + /** + * The top coordinate of this Group. + * + * It is derived by calling getBounds, calculating the Groups dimensions based on its + * visible children. + */ + var top: Double = js.native + + /** + * Total number of existing children in the group. + */ + def total: Int = js.native + ///////////////////////////////////////////////////////////////////////////////// // Methods ///////////////////////////////////////////////////////////////////////////////// + /** + * Adds an existing object as the top child in this group. + * The child is automatically added to the top of the group, and is displayed above every previous child. + * Or if the optional index is specified, the child is added at the location specified by the index value, + * this allows you to control child ordering. + * + * If the child was already in this Group, it is simply returned, + * and nothing else happens to it. + * + * If Group.enableBody is set, then a physics body will be created on the object, + * so long as one does not already exist. + * + * If Group.inputEnableChildren is set, then an Input Handler will be created on the object, + * so long as one does not already exist. + * + * Use addAt to control where a child is added. Use create to create and add a new child. + * @param child The display object to add as a child. + * @param silent If true the child will not dispatch the `onAddedToGroup` event. + * @param index The index within the group to insert the child to. + * Where 0 is the bottom of the Group. + * @return The child that was added to the group. + */ + def add(child: DisplayObject, silent: Boolean = js.native, index: Int = js.native): DisplayObject = js.native + + /** + * Adds the amount to the given property on all children in this group. + * `Group.addAll('x', 10)` will add 10 to the child.x value for each child. + * @param property The property to increment, for example 'body.velocity.x' or 'angle'. + * @param amount The amount to increment the property by. If `child.x = 10` then `addAll('x', 40)` + * would make `child.x = 50`. + * @param checkAlive If true the property will only be changed if the child is alive. + * @param checkVisible If true the property will only be changed if the child is visible. + */ + def addAll(property: String, amount: Double, checkAlive: Boolean, checkVisible: Boolean): Unit = js.native + + /** + * + * @return + */ def countLiving(): Int = js.native + /** + * + * @param x + * @param y + * @param key + * @param frame + * @param exists + * @return + */ def create(x: Double, y: Double, key: Any = null, frame: Any = null, exists: Boolean = true): T = js.native + /** + * + * @param quantity + * @param key + * @param frame + * @param exists + */ def createMultiple(quantity: Int, key: String, frame: Any = null, exists: Boolean = false): Unit = js.native + /** + * + * @return + */ def getFirstAlive(): js.UndefOr[T] = js.native + /** + * + * @param createIfNull + * @param x + * @param y + * @param key + * @param frame + * @return + */ def getFirstAlive(createIfNull: Boolean = false, x: Double, y: Double, key: String = null, frame: String | Int = null): js.UndefOr[T] = js.native + /** + * + * @param exists + * @return + */ def getFirstExists(exists: Boolean): js.UndefOr[T] = js.native + /** + * + * @param callback + * @param context + * @param checkExists + */ def forEach(callback: js.Function1[T, Any], context: Any = this, checkExists: Boolean = false): Unit = js.native def forEach(callback: js.Function1[T, Any], context: Any, checkExists: Boolean, args: Any*): Unit = js.native @@ -83,3 +379,43 @@ class Group[T](var game: Game, force: Boolean = false): Unit = js.native } + +/** + * Group Singleton + * @author lawrence.daniels@gmail.com + */ +@js.native +@JSName("Phaser.Group") +object Group extends js.Object { + + /** + * A returnType value, as specified in iterate eg. + */ + val RETURN_ALL: Int = js.native + + /** + * A returnType value, as specified in iterate eg. + */ + val RETURN_CHILD: Int = js.native + + /** + * A returnType value, as specified in iterate eg. + */ + val RETURN_NONE: Int = js.native + + /** + * A returnType value, as specified in iterate eg. + */ + val RETURN_TOTAL: Int = js.native + + /** + * A sort ordering value, as specified in sort eg. + */ + val SORT_ASCENDING: Int = js.native + + /** + * A sort ordering value, as specified in sort eg. + */ + val SORT_DESCENDING: Int = js.native + +} \ No newline at end of file diff --git a/browser/phaser/src/main/scala/io/scalajs/dom/html/phaser/Image.scala b/browser/phaser/src/main/scala/io/scalajs/dom/html/phaser/Image.scala index 6839f39f1..f6fa19475 100644 --- a/browser/phaser/src/main/scala/io/scalajs/dom/html/phaser/Image.scala +++ b/browser/phaser/src/main/scala/io/scalajs/dom/html/phaser/Image.scala @@ -47,8 +47,29 @@ class Image(var game: Phaser.Game, protected def this() = this(js.native, js.native, js.native, js.native, js.native) + /** + * The angle property is the rotation of the Game Object in degrees from its original orientation. + * + * Values from 0 to 180 represent clockwise rotation; values from 0 to -180 represent counterclockwise rotation. + * + * Values outside this range are added to or subtracted from 360 to obtain a value within the range. + * For example, the statement player.angle = 450 is the same as player.angle = 90. + * + * If you wish to work in radians instead of degrees you can use the property rotation instead. + * Working in radians is slightly faster as it doesn't have to perform any calculations. + */ override var angle: Double = js.native + /** + * Base destroy method for generic display objects. + */ + override def destroy(): Unit = js.native + + /** + * Base destroy method for generic display objects. + */ + override def destroy(destroyChildren: Boolean): Unit = js.native + /** * The const type of this object. */ diff --git a/browser/phaser/src/main/scala/io/scalajs/dom/html/phaser/Input.scala b/browser/phaser/src/main/scala/io/scalajs/dom/html/phaser/Input.scala index d135a5316..d8a8eb1c1 100644 --- a/browser/phaser/src/main/scala/io/scalajs/dom/html/phaser/Input.scala +++ b/browser/phaser/src/main/scala/io/scalajs/dom/html/phaser/Input.scala @@ -1,9 +1,81 @@ package io.scalajs.dom.html.phaser import scala.scalajs.js +import scala.scalajs.js.annotation.JSName +/** + * Phaser.Input is the Input Manager for all types of Input across Phaser, + * including mouse, keyboard, touch and MSPointer. + * The Input manager is updated automatically by the core game loop. + * @param game Current game instance. + * @see http://phaser.io/docs/2.6.2/Phaser.Input.html + */ @js.native -trait Input extends js.Object { - val keyboard: Keyboard = js.native - val onTap: Signal = js.native +@JSName("Phaser.Input") +class Input(var game: Phaser.Game) extends js.Object { + + /** + * The most recently active Pointer object. + * When you've limited max pointers to 1 this will accurately be either the first finger touched or mouse. + */ + var activePointer: Phaser.Pointer = js.native + + /** + * A Circle object centered on the x/y screen coordinates of the Input. + * Default size of 44px (Apples recommended "finger tip" size) but can be changed to anything. + */ + var circle: Phaser.Circle = js.native + + /** + * The number of milliseconds between taps of the same Pointer for it to be considered a double tap / click. + * default: 300 + */ + var doubleTapRate: Double = js.native + + /** + * When enabled, input (eg. Keyboard, Mouse, Touch) will be processed - as long as the + * individual sources are enabled themselves. + * + * When not enabled, all input sources are ignored. To disable just one type of input; + * for example, the Mouse, use input.mouse.enabled = false. + */ + var enabled: Boolean = js.native + + /** + * + */ + var gamepad : Phaser.Gamepad = js.native + + /** + * + */ + var keyboard: Keyboard = js.native + + /** + * + */ + var onTap: Signal = js.native + } + +@js.native +@JSName("Phaser.Input") +object Input extends js.Object { + + /** + * The maximum number of pointers that can be added. This excludes the mouse pointer. + */ + var MAX_POINTERS: Int = js.native + + /** + * + */ + var MOUSE_OVERRIDES_TOUCH: Int = js.native + + /** + * + */ + var MOUSE_TOUCH_COMBINE: Int = js.native + + +} \ No newline at end of file diff --git a/browser/phaser/src/main/scala/io/scalajs/dom/html/phaser/Phaser.scala b/browser/phaser/src/main/scala/io/scalajs/dom/html/phaser/Phaser.scala index 8ec5eec78..455617282 100644 --- a/browser/phaser/src/main/scala/io/scalajs/dom/html/phaser/Phaser.scala +++ b/browser/phaser/src/main/scala/io/scalajs/dom/html/phaser/Phaser.scala @@ -53,11 +53,13 @@ object Phaser extends js.Object { type Frame = phaser.Frame type FrameData = phaser.FrameData type Game = phaser.Game + type Gamepad = phaser.Gamepad type GameObjectCreator = phaser.GameObjectCreator type GameObjectFactory = phaser.GameObjectFactory type Graphics = phaser.Graphics type Group[T] = phaser.Group[T] type Image = phaser.Image + type Input = phaser.Input type InputHandler = phaser.InputHandler type Keyboard = phaser.Keyboard type Line = phaser.Line @@ -72,6 +74,7 @@ object Phaser extends js.Object { type Rectangle = phaser.Rectangle type RenderTexture = phaser.RenderTexture type RoundedRectangle = phaser.RoundedRectangle + type SinglePad = phaser.SinglePad type Signal = phaser.Signal type SignalBinding = phaser.SignalBinding type Sound = phaser.Sound @@ -80,6 +83,8 @@ object Phaser extends js.Object { type State = phaser.State type Text = phaser.Text type Texture = phaser.Texture + type Tilemap = phaser.Tilemap + type TilemapLayer = phaser.TilemapLayer type TileSprite = phaser.TileSprite type Time = phaser.Time type Timer = phaser.Timer @@ -134,18 +139,27 @@ object Phaser extends js.Object { type P2 = phaser.physics.P2 @js.native - @JSName("P2") - object P2 extends js.Object { + @JSName("Arcade") + object Arcade extends js.Object { - type Material = phaser.physics.p2.Material + type Body = phaser.physics.arcade.Body } @js.native - @JSName("Arcade") - object Arcade extends js.Object { + @JSName("Ninja") + object Ninja extends js.Object { - type Body = phaser.physics.arcade.Body + type AABB = phaser.physics.ninja.AABB + type Body = phaser.physics.ninja.Body + + } + + @js.native + @JSName("P2") + object P2 extends js.Object { + + type Material = phaser.physics.p2.Material } @@ -155,7 +169,7 @@ object Phaser extends js.Object { * Phaser.Utils class references */ @js.native - @JSName("Phaser.Utils") + @JSName("Utils") object Utils extends js.Object { type ArrayUtils = phaser.utils.ArrayUtils diff --git a/browser/phaser/src/main/scala/io/scalajs/dom/html/phaser/PhysicsBody.scala b/browser/phaser/src/main/scala/io/scalajs/dom/html/phaser/PhysicsBody.scala deleted file mode 100644 index 3ad5bca15..000000000 --- a/browser/phaser/src/main/scala/io/scalajs/dom/html/phaser/PhysicsBody.scala +++ /dev/null @@ -1,14 +0,0 @@ -package io.scalajs.dom.html.phaser - -import io.scalajs.dom.html.pixijs.DisplayObject - -import scala.scalajs.js - -// TODO should this really extend DisplayObject? -@js.native -trait PhysicsBody extends DisplayObject { - //var x: Double = js.native - //var y: Double = js.native - var moves: Boolean = js.native - var velocity: Point = js.native -} diff --git a/browser/phaser/src/main/scala/io/scalajs/dom/html/phaser/Plugin.scala b/browser/phaser/src/main/scala/io/scalajs/dom/html/phaser/Plugin.scala index 2fa772d23..2d93fbe24 100644 --- a/browser/phaser/src/main/scala/io/scalajs/dom/html/phaser/Plugin.scala +++ b/browser/phaser/src/main/scala/io/scalajs/dom/html/phaser/Plugin.scala @@ -9,7 +9,7 @@ import scala.scalajs.js.annotation.JSName */ @js.native @JSName("Phaser.Plugin") -class Plugin(val game: Phaser.Game, val parent: Phaser.PluginManager) extends js.Object { +class Plugin(var game: Phaser.Game, val parent: Phaser.PluginManager) extends js.Object { ///////////////////////////////////////////////////////////////////////////////// // Properties diff --git a/browser/phaser/src/main/scala/io/scalajs/dom/html/phaser/PluginManager.scala b/browser/phaser/src/main/scala/io/scalajs/dom/html/phaser/PluginManager.scala index 391bac239..cb0778318 100644 --- a/browser/phaser/src/main/scala/io/scalajs/dom/html/phaser/PluginManager.scala +++ b/browser/phaser/src/main/scala/io/scalajs/dom/html/phaser/PluginManager.scala @@ -10,7 +10,7 @@ import scala.scalajs.js.annotation.JSName */ @js.native @JSName("Phaser.PluginManager") -class PluginManager(val game: Phaser.Game) extends js.Object { +class PluginManager(var game: Phaser.Game) extends js.Object { ///////////////////////////////////////////////////////////////////////////////// // Properties diff --git a/browser/phaser/src/main/scala/io/scalajs/dom/html/phaser/Point.scala b/browser/phaser/src/main/scala/io/scalajs/dom/html/phaser/Point.scala index 9e04930d5..c3b2393d4 100644 --- a/browser/phaser/src/main/scala/io/scalajs/dom/html/phaser/Point.scala +++ b/browser/phaser/src/main/scala/io/scalajs/dom/html/phaser/Point.scala @@ -7,11 +7,15 @@ import scala.scalajs.js * and y represents the vertical axis. The following code creates a point at (0,0): * {{{ var myPoint = new Phaser.Point(); }}} * You can also use them as 2D Vectors and you'll find different vector related methods in this class. - * @param x The horizontal position of this Point. - * @param y The vertical position of this Point. + * @param x0 The horizontal position of this Point. + * @param y0 The vertical position of this Point. */ @js.native -class Point(var x: Double, var y: Double) extends js.Object { +class Point(x0: Double, y0: Double) extends js.Object { + + var x: Double = js.native + + var y: Double = js.native /** * Adds the coordinates of two points together to create a new point. diff --git a/browser/phaser/src/main/scala/io/scalajs/dom/html/phaser/ScaleManager.scala b/browser/phaser/src/main/scala/io/scalajs/dom/html/phaser/ScaleManager.scala index 764f59962..479d63158 100644 --- a/browser/phaser/src/main/scala/io/scalajs/dom/html/phaser/ScaleManager.scala +++ b/browser/phaser/src/main/scala/io/scalajs/dom/html/phaser/ScaleManager.scala @@ -18,5 +18,5 @@ import scala.scalajs.js.| */ @js.native @JSName("Phaser.ScaleManager") -class ScaleManager(val game: Phaser.Game, val width: JsNumber | String, val height: JsNumber | String) +class ScaleManager(var game: Phaser.Game, val width: JsNumber | String, val height: JsNumber | String) extends js.Object {} diff --git a/browser/phaser/src/main/scala/io/scalajs/dom/html/phaser/SinglePad.scala b/browser/phaser/src/main/scala/io/scalajs/dom/html/phaser/SinglePad.scala new file mode 100644 index 000000000..dd2aa208d --- /dev/null +++ b/browser/phaser/src/main/scala/io/scalajs/dom/html/phaser/SinglePad.scala @@ -0,0 +1,13 @@ +package io.scalajs.dom.html.phaser + +import scala.scalajs.js +import scala.scalajs.js.annotation.JSName + +/** + * Created by ldaniels on 2/3/17. + */ +@js.native +@JSName("Phaser.SinglePad") +class SinglePad extends js.Object { + +} diff --git a/browser/phaser/src/main/scala/io/scalajs/dom/html/phaser/Sound.scala b/browser/phaser/src/main/scala/io/scalajs/dom/html/phaser/Sound.scala index 6b7d342a5..ca3060916 100644 --- a/browser/phaser/src/main/scala/io/scalajs/dom/html/phaser/Sound.scala +++ b/browser/phaser/src/main/scala/io/scalajs/dom/html/phaser/Sound.scala @@ -12,5 +12,5 @@ import scala.scalajs.js.annotation.JSName */ @js.native @JSName("Phaser.Sound") -class Sound(val game: Game, val key: String, val volume: Int = js.native, val loop: Boolean = js.native) +class Sound(var game: Phaser.Game, val key: String, val volume: Int = js.native, val loop: Boolean = js.native) extends js.Object diff --git a/browser/phaser/src/main/scala/io/scalajs/dom/html/phaser/SoundManager.scala b/browser/phaser/src/main/scala/io/scalajs/dom/html/phaser/SoundManager.scala index f1d10e2ce..4634d4557 100644 --- a/browser/phaser/src/main/scala/io/scalajs/dom/html/phaser/SoundManager.scala +++ b/browser/phaser/src/main/scala/io/scalajs/dom/html/phaser/SoundManager.scala @@ -26,7 +26,7 @@ import scala.scalajs.js.| */ @js.native @JSName("Phaser.SoundManager") -class SoundManager(val game: Game) extends js.Object { +class SoundManager(var game: Phaser.Game) extends js.Object { ///////////////////////////////////////////////////////////////////////////////// // Properties diff --git a/browser/phaser/src/main/scala/io/scalajs/dom/html/phaser/Sprite.scala b/browser/phaser/src/main/scala/io/scalajs/dom/html/phaser/Sprite.scala index bf39c4e06..7c41365ed 100644 --- a/browser/phaser/src/main/scala/io/scalajs/dom/html/phaser/Sprite.scala +++ b/browser/phaser/src/main/scala/io/scalajs/dom/html/phaser/Sprite.scala @@ -10,15 +10,17 @@ import scala.scalajs.js.| * Sprites are the lifeblood of your game, used for nearly everything visual. * At its most basic a Sprite consists of a set of coordinates and a texture that is rendered to the canvas. * They also contain additional properties allowing for physics motion (via Sprite.body), input handling (via Sprite.input), - * events (via Sprite.events), animation (via Sprite.animations), camera culling and more. Please see the Examples for use cases. + * events (via Sprite.events), animation (via Sprite.animations), camera culling and more. + * Please see the Examples for use cases. + * @see http://phaser.io/docs/2.6.2/Phaser.Sprite.html */ @js.native @JSName("Phaser.Sprite") -class Sprite(var game: Game, +class Sprite(var game: Phaser.Game, override var x: Double, override var y: Double, var key: String | Phaser.RenderTexture | Phaser.BitmapData | Phaser.Texture, - var frame: String | Double) + var frame: String | Int) extends pixijs.Sprite with Phaser.Component.Core with Phaser.Component.Angle @@ -66,4 +68,14 @@ class Sprite(var game: Game, */ var blendMode: Double = js.native + /** + * Base destroy method for generic display objects. + */ + override def destroy(): Unit = js.native + + /** + * Base destroy method for generic display objects. + */ + override def destroy(destroyChildren: Boolean): Unit = js.native + } diff --git a/browser/phaser/src/main/scala/io/scalajs/dom/html/phaser/Text.scala b/browser/phaser/src/main/scala/io/scalajs/dom/html/phaser/Text.scala index 841cbf9bf..55f72cffb 100644 --- a/browser/phaser/src/main/scala/io/scalajs/dom/html/phaser/Text.scala +++ b/browser/phaser/src/main/scala/io/scalajs/dom/html/phaser/Text.scala @@ -1,6 +1,6 @@ package io.scalajs.dom.html.phaser -import io.scalajs.JsNumber +import io.scalajs.{JsNumber, RawOptions} import scala.scalajs.js import scala.scalajs.js.annotation.{JSName, ScalaJSDefined} @@ -22,8 +22,8 @@ import scala.scalajs.js.| class Text(game: Phaser.Game, x: Double, y: Double, - val text: String, - val style: StyleOptions = js.native) extends Sprite + var text: String, + var style: StyleOptions | RawOptions = js.native) extends Sprite /** * Text Style Options diff --git a/browser/phaser/src/main/scala/io/scalajs/dom/html/phaser/Tilemap.scala b/browser/phaser/src/main/scala/io/scalajs/dom/html/phaser/Tilemap.scala new file mode 100644 index 000000000..a7e6808dd --- /dev/null +++ b/browser/phaser/src/main/scala/io/scalajs/dom/html/phaser/Tilemap.scala @@ -0,0 +1,108 @@ +package io.scalajs.dom.html.phaser + +import scala.scalajs.js +import scala.scalajs.js.annotation.JSName + +/** + * Creates a new Phaser.Tilemap object. The map can either be populated with data from a Tiled JSON file or from a CSV file. + * + * Tiled is a free software package specifically for creating tile maps, and is available from http://www.mapeditor.org + * + * To do this pass the Cache key as the first parameter. When using Tiled data you need only provide the key. + * When using CSV data you must provide the key and the tileWidth and tileHeight parameters. + * If creating a blank tilemap to be populated later, you can either specify no parameters at + * all and then use Tilemap.create or pass the map and tile dimensions here. + * + * Note that all Tilemaps use a base tile size to calculate dimensions from, but that a + * TilemapLayer may have its own unique tile size that overrides it. + * + * A Tile map is rendered to the display using a TilemapLayer. It is not added to the display list directly itself. + * A map may have multiple layers. You can perform operations on the map data such as copying, + * pasting, filling and shuffling the tiles around. + * @param game Game reference to the currently running game. + * @param key The key of the tilemap data as stored in the Cache. If you're creating a blank map + * either leave this parameter out or pass null. + * @param tileWidth The pixel width of a single map tile. If using CSV data you must specify this. + * Not required if using Tiled map data. + * @param tileHeight The pixel height of a single map tile. If using CSV data you must specify this. + * Not required if using Tiled map data. + * @param width The width of the map in tiles. If this map is created from Tiled or CSV data + * you don't need to specify this. + * @param height The height of the map in tiles. If this map is created from Tiled or CSV data + * you don't need to specify this. + * @see http://phaser.io/docs/2.6.2/Phaser.Tilemap.html + */ +@js.native +@JSName("Phaser.Tilemap") +class Tilemap(var game: Phaser.Game, + var key: String = js.native, + var tileWidth: Double = js.native, + var tileHeight: Double = js.native, + var width: Double = js.native, + var height: Double = js.native) extends js.Object { + + /** + * An array of tile indexes that collide. + */ + var collideIndexes: js.Array[Int] = js.native + + /** + * An array of collision data (polylines, etc). + */ + var collision: js.Array[_] = js.native + + /** + * The current layer. + */ + var currentLayer: Int = js.native + + /** + * Map data used for debug values only. + */ + var debugMap: js.Array[_] = js.native + + /** + * If set then console.log is used to dump out useful layer creation debug data. + */ + var enableDebug: Boolean = js.native + +} + +/** + * Tilemap Singleton + */ +@js.native +@JSName("Phaser.Tilemap") +object Tilemap extends js.Object { + + /** + * + */ + val CSV: Int = js.native + + /** + * + */ + val EAST: Int = js.native + + /** + * + */ + val NORTH: Int = js.native + + /** + * + */ + val SOUTH: Int = js.native + + /** + * + */ + val TILED_JSON: Int = js.native + + /** + * + */ + val WEST: Int = js.native + +} \ No newline at end of file diff --git a/browser/phaser/src/main/scala/io/scalajs/dom/html/phaser/TilemapLayer.scala b/browser/phaser/src/main/scala/io/scalajs/dom/html/phaser/TilemapLayer.scala new file mode 100644 index 000000000..662fdeba0 --- /dev/null +++ b/browser/phaser/src/main/scala/io/scalajs/dom/html/phaser/TilemapLayer.scala @@ -0,0 +1,61 @@ +package io.scalajs.dom.html.phaser + +import scala.scalajs.js +import scala.scalajs.js.annotation.{JSName, ScalaJSDefined} +import scala.scalajs.js.| + +/** + * A TilemapLayer is a Phaser.Image/Sprite that renders a specific TileLayer of a Tilemap. + * + * Since a TilemapLayer is a Sprite it can be moved around the display, added to other + * groups or display objects, etc. + * + * By default TilemapLayers have fixedToCamera set to true. Changing this will break + * Camera follow and scrolling behavior. + * @param game Game reference to the currently running game. + * @param tilemap The tilemap to which this layer belongs. + * @param index The index of the TileLayer to render within the Tilemap. + * @param width Width of the renderable area of the layer (in pixels). + * @param height Height of the renderable area of the layer (in pixels). + * @see http://phaser.io/docs/2.6.2/Phaser.TilemapLayer.html + */ +@js.native +@JSName("Phaser.TilemapLayer") +class TilemapLayer(game: Phaser.Game, + var tilemap: Phaser.Tilemap, + var index: Int, + width: Double, + height: Double) extends Phaser.Sprite { + + /** + * Settings used for debugging and diagnostics. + */ + var debugSettings: DebugSettings = js.native + +} + +/** + * Settings used for debugging and diagnostics. + * @param missingImageFill A tile is rendered as a rectangle using the following fill if a valid + * tileset/image cannot be found. A value of null prevents additional + * rendering for tiles without a valid tileset image. This takes effect + * even when debug rendering for the layer is not enabled. + * @param debuggedTileOverfill If a Tile has Tile#debug true then, after normal tile image rendering, + * a rectangle with the following fill is drawn above/over it. This takes + * effect even when debug rendering for the layer is not enabled. + * @param forceFullRedraw When debug rendering (debug is true), and this option is enabled, + * a full redraw is forced and rendering optimization is suppressed. + * @param debugAlpha When debug rendering (debug is true), the tileset is initially rendered + * with this alpha level. This can make the tile edges clearer. + * @param facingEdgeStroke When debug rendering (debug is true), this color/stroke is used to draw + * "face" edges. A value of null disables coloring facing edges. + * @param collidingTileOverfill When debug rendering (debug is true), this fill is used for tiles that are + * collidable. A value of null disables applying the additional overfill. + */ +@ScalaJSDefined +class DebugSettings(var missingImageFill: js.UndefOr[String] = js.undefined, + var debuggedTileOverfill: js.UndefOr[String] = js.undefined, + var forceFullRedraw: js.UndefOr[Boolean] = js.undefined, + var debugAlpha: js.UndefOr[Double | Int] = js.undefined, + var facingEdgeStroke: js.UndefOr[String] = js.undefined, + var collidingTileOverfill: js.UndefOr[String] = js.undefined) extends js.Object \ No newline at end of file diff --git a/browser/phaser/src/main/scala/io/scalajs/dom/html/phaser/Time.scala b/browser/phaser/src/main/scala/io/scalajs/dom/html/phaser/Time.scala index e94271c44..4032735ca 100644 --- a/browser/phaser/src/main/scala/io/scalajs/dom/html/phaser/Time.scala +++ b/browser/phaser/src/main/scala/io/scalajs/dom/html/phaser/Time.scala @@ -15,7 +15,7 @@ import scala.scalajs.js.annotation.JSName */ @js.native @JSName("Phaser.Time") -class Time(val game: Phaser.Game) extends js.Object { +class Time(var game: Phaser.Game) extends js.Object { ///////////////////////////////////////////////////////////////////////////////// // Properties diff --git a/browser/phaser/src/main/scala/io/scalajs/dom/html/phaser/Timer.scala b/browser/phaser/src/main/scala/io/scalajs/dom/html/phaser/Timer.scala index 49e47ddfe..2ac28ac97 100644 --- a/browser/phaser/src/main/scala/io/scalajs/dom/html/phaser/Timer.scala +++ b/browser/phaser/src/main/scala/io/scalajs/dom/html/phaser/Timer.scala @@ -18,7 +18,7 @@ import scala.scalajs.js.annotation.JSName */ @js.native @JSName("Phaser.Timer") -class Timer(val game: Phaser.Game, val autoDestroy: Boolean = js.native) extends js.Object { +class Timer(var game: Phaser.Game, val autoDestroy: Boolean = js.native) extends js.Object { /** * The duration in ms remaining until the next event will occur. diff --git a/browser/phaser/src/main/scala/io/scalajs/dom/html/phaser/Weapon.scala b/browser/phaser/src/main/scala/io/scalajs/dom/html/phaser/Weapon.scala index a83e94aac..feddf5796 100644 --- a/browser/phaser/src/main/scala/io/scalajs/dom/html/phaser/Weapon.scala +++ b/browser/phaser/src/main/scala/io/scalajs/dom/html/phaser/Weapon.scala @@ -26,7 +26,7 @@ import scala.scalajs.js.| */ @js.native @JSName("Phaser.Weapon") -class Weapon(val game: Phaser.Game, val parent: Phaser.PluginManager) extends js.Object { +class Weapon(var game: Phaser.Game, val parent: Phaser.PluginManager) extends js.Object { ///////////////////////////////////////////////////////////////////////////////// // Properties @@ -143,7 +143,7 @@ class Weapon(val game: Phaser.Game, val parent: Phaser.PluginManager) extends js /** * This is the Phaser.Group that contains all of the bullets managed by this plugin. */ - var bullets: Phaser.Group[_] = js.native + var bullets: Phaser.Group[Phaser.Bullet] = js.native /** * The speed at which the bullets are fired. This value is given in pixels per second, and diff --git a/browser/phaser/src/main/scala/io/scalajs/dom/html/phaser/World.scala b/browser/phaser/src/main/scala/io/scalajs/dom/html/phaser/World.scala index ea7d83df2..b8de47005 100644 --- a/browser/phaser/src/main/scala/io/scalajs/dom/html/phaser/World.scala +++ b/browser/phaser/src/main/scala/io/scalajs/dom/html/phaser/World.scala @@ -9,7 +9,7 @@ import scala.scalajs.js * @param game Reference to the current game instance. */ @js.native -class World(val game: Game) extends js.Object { +class World(var game: Phaser.Game) extends js.Object { /** * The alive property is useful for Groups that are children of other Groups and need to be included/excluded in diff --git a/browser/phaser/src/main/scala/io/scalajs/dom/html/phaser/component/Delta.scala b/browser/phaser/src/main/scala/io/scalajs/dom/html/phaser/component/Delta.scala index eddda212a..24eb6e03a 100644 --- a/browser/phaser/src/main/scala/io/scalajs/dom/html/phaser/component/Delta.scala +++ b/browser/phaser/src/main/scala/io/scalajs/dom/html/phaser/component/Delta.scala @@ -1,8 +1,30 @@ package io.scalajs.dom.html.phaser.component import scala.scalajs.js -import scala.scalajs.js.annotation.JSName +/** + * The Delta component provides access to delta values between the Game Objects current and previous position. + * @see http://phaser.io/docs/2.6.2/Phaser.Component.Delta.html + */ @js.native //@JSName("Phaser.Component.Delta") -trait Delta extends js.Object +trait Delta extends js.Object { + + /** + * Returns the delta x value. The difference between world.x now and in the previous frame. + * The value will be positive if the Game Object has moved to the right or negative if to the left. + */ + def deltaX: Double = js.native + + /** + * Returns the delta y value. The difference between world.y now and in the previous frame. + * The value will be positive if the Game Object has moved down or negative if up. + */ + def deltaY: Double = js.native + + /** + * Returns the delta z value. The difference between rotation now and in the previous frame. The delta value. + */ + def deltaZ: Double = js.native + +} diff --git a/browser/phaser/src/main/scala/io/scalajs/dom/html/phaser/component/Destroy.scala b/browser/phaser/src/main/scala/io/scalajs/dom/html/phaser/component/Destroy.scala index 0676583a2..4066a367f 100644 --- a/browser/phaser/src/main/scala/io/scalajs/dom/html/phaser/component/Destroy.scala +++ b/browser/phaser/src/main/scala/io/scalajs/dom/html/phaser/component/Destroy.scala @@ -1,8 +1,44 @@ package io.scalajs.dom.html.phaser.component import scala.scalajs.js -import scala.scalajs.js.annotation.JSName +/** + * The Destroy component is responsible for destroying a Game Object. + * @see http://phaser.io/docs/2.6.2/Phaser.Component.Destroy.html + */ @js.native //@JSName("Phaser.Component.Destroy") -trait Destroy extends js.Object +trait Destroy extends js.Object { + + ///////////////////////////////////////////////////////////////////////////////// + // Properties + ///////////////////////////////////////////////////////////////////////////////// + + /** + * As a Game Object runs through its destroy method this flag is set to true, + * and can be checked in any sub-systems or plugins it is being destr + */ + def destroyPhase: Boolean = js.native + + ///////////////////////////////////////////////////////////////////////////////// + // Methods + ///////////////////////////////////////////////////////////////////////////////// + + /** + * Destroys the Game Object. This removes it from its parent group, destroys the input, event + * and animation handlers if present and nulls its reference to game, freeing it up for garbage collection. + * + * If this Game Object has the Events component it will also dispatch the onDestroy event. + * You can optionally also destroy the BaseTexture this Game Object is using. Be careful if you've + * more than one Game Object sharing the same BaseTexture. + * @param destroyChildren Should every child of this object have its destroy method called as well? + * @param destroyTexture Destroy the BaseTexture this Game Object is using? Note that if another Game + * Object is sharing the same BaseTexture it will invalidate it. + */ + def destroy(destroyChildren: Boolean, destroyTexture: Boolean): Unit = js.native + + def destroy(destroyChildren: Boolean): Unit = js.native + + def destroy(): Unit = js.native + +} diff --git a/browser/phaser/src/main/scala/io/scalajs/dom/html/phaser/component/PhysicsBody.scala b/browser/phaser/src/main/scala/io/scalajs/dom/html/phaser/component/PhysicsBody.scala index 442218258..393544769 100644 --- a/browser/phaser/src/main/scala/io/scalajs/dom/html/phaser/component/PhysicsBody.scala +++ b/browser/phaser/src/main/scala/io/scalajs/dom/html/phaser/component/PhysicsBody.scala @@ -11,6 +11,7 @@ import scala.scalajs.js.annotation.JSName * @see https://phaser.io/docs/2.6.2/Phaser.Component.PhysicsBody.html */ @js.native +//@JSName("Phaser.Component.PhysicsBody") trait PhysicsBody extends js.Object { /** @@ -30,21 +31,21 @@ trait PhysicsBody extends js.Object { * If you need a different result then adjust or re-create the Body shape offsets manually or reset the anchor * after enabling physics. */ - var body: Phaser.Component.PhysicsBody = js.native + var body: Phaser.Physics.Arcade.Body /*| Phaser.Physics.P2.Body | Phaser.Physics.Ninja.Body*/ = js.native /** * The position of the Game Object on the x axis relative to the local coordinates of the parent. */ def x: Double = js.native - def x_=(x : Double): Unit = js.native + def x_=(x: Double): Unit = js.native /** * The position of the Game Object on the y axis relative to the local coordinates of the parent. */ def y: Double = js.native - def y_=(y : Double): Unit = js.native + def y_=(y: Double): Unit = js.native } diff --git a/browser/phaser/src/main/scala/io/scalajs/dom/html/phaser/package.scala b/browser/phaser/src/main/scala/io/scalajs/dom/html/phaser/package.scala index dbe3a8f1f..c118b9952 100644 --- a/browser/phaser/src/main/scala/io/scalajs/dom/html/phaser/package.scala +++ b/browser/phaser/src/main/scala/io/scalajs/dom/html/phaser/package.scala @@ -9,6 +9,8 @@ import scala.scalajs.js.Array */ package object phaser { + type ButtonCode = Int + /** * Group Extensions * @author lawrence.daniels@gmail.com diff --git a/browser/phaser/src/main/scala/io/scalajs/dom/html/phaser/physics/Arcade.scala b/browser/phaser/src/main/scala/io/scalajs/dom/html/phaser/physics/Arcade.scala index 7697c3812..e5b528421 100644 --- a/browser/phaser/src/main/scala/io/scalajs/dom/html/phaser/physics/Arcade.scala +++ b/browser/phaser/src/main/scala/io/scalajs/dom/html/phaser/physics/Arcade.scala @@ -5,17 +5,17 @@ import io.scalajs.dom.html.pixijs.DisplayObject import scala.scalajs.js import scala.scalajs.js.annotation.JSName +import scala.scalajs.js.| /** * The Arcade Physics world. Contains Arcade Physics related collision, overlap and motion methods. * @param game reference to the current game instance. - * @version 2.6.2 * @see http://phaser.io/docs/2.6.2/Phaser.Physics.Arcade.html * @author lawrence.daniels@gmail.com */ @js.native @JSName("Phaser.Physics.Arcade") -class Arcade(val game: Phaser.Game) extends js.Object { +class Arcade(var game: Phaser.Game) extends js.Object { ///////////////////////////////////////////////////////////////////////////////// // Properties @@ -105,6 +105,35 @@ class Arcade(val game: Phaser.Game) extends js.Object { */ def accelerateToObject(displayObject: DisplayObject, destination: js.Any, speed: Double, xSpeedMax: Double, ySpeedMax: Double): Double = js.native + /** + * Sets the acceleration.x/y property on the display object so it will move towards the target + * at the given speed (in pixels per second sq.) + * + * You must give a maximum speed value, beyond which the display object won't go any faster. + * Note: The display object does not continuously track the target. If the target changes location + * during transit the display object will not modify its course. + * + * Note: The display object doesn't stop moving once it reaches the destination coordinates. + * @param displayObject The display object to move. + * @param pointer The pointer to move towards. Defaults to `Phaser.Input.activePointer`. + * @param speed The speed it will accelerate in pixels per second. + * @param xSpeedMax The maximum x velocity the display object can reach. + * @param ySpeedMax The maximum y velocity the display object can reach. + * @return The angle (in radians) that the object should be visually set to in order to match its new trajectory. + */ + def accelerateToPointer(displayObject: DisplayObject, + pointer: Phaser.Pointer = js.native, + speed: Double = js.native, + xSpeedMax: Double = js.native, + ySpeedMax: Double = js.native): Double = js.native + + def moveToObject(displayObject: DisplayObject, destination: Any, speed: Int = 60, maxTime: Long = 0): Double = js.native + + def overlap(object1: Sprite | Group[_] | js.Array[_], + object2: Sprite | Group[_] | js.Array[_], + overlapCallback: js.Function2[_, _, _], + processCallback: Option[js.Function2[_, _, Boolean]], + callbackContext: Any = js.native): Unit = js.native } diff --git a/browser/phaser/src/main/scala/io/scalajs/dom/html/phaser/physics/Ninja.scala b/browser/phaser/src/main/scala/io/scalajs/dom/html/phaser/physics/Ninja.scala index 009e0feb8..9dd7f751f 100644 --- a/browser/phaser/src/main/scala/io/scalajs/dom/html/phaser/physics/Ninja.scala +++ b/browser/phaser/src/main/scala/io/scalajs/dom/html/phaser/physics/Ninja.scala @@ -1,11 +1,80 @@ -package io.scalajs.dom.html.phaser.physics +package io.scalajs.dom.html.phaser +package physics import scala.scalajs.js +import scala.scalajs.js.annotation.JSName +import scala.scalajs.js.| /** - * Ninja + * Ninja Physics. The Ninja Physics system was created in Flash by Metanet Software + * and ported to JavaScript by Richard Davey. + * + * It allows for AABB and Circle to Tile collision. Tiles can be any of 34 different types, + * including slopes, convex and concave shapes. + * * + * It does what it does very well, but is ripe for expansion and optimisation. Here are some + * features that I'd love to see the community add: + *