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: + * + * Feel free to attempt any of the above and submit a Pull Request with your code! Be sure + * to include test cases proving they work. + * @see http://phaser.io/docs/2.6.2/Phaser.Physics.Ninja.html */ @js.native -class Ninja extends js.Object { +@JSName("Phaser.Physics.Ninja") +class Ninja(var game: Phaser.Game) extends js.Object { + + ///////////////////////////////////////////////////////////////////////////////// + // Properties + ///////////////////////////////////////////////////////////////////////////////// + + /** + * The bounds inside of which the physics world exists. Defaults to match the world bounds. + */ + var bounds: Phaser.Rectangle = js.native + + /** + * The World gravity setting. + */ + var gravity: Double = js.native + + /** + * Used by the QuadTree to set the maximum number of iteration levels. + */ + var maxLevels: Int = js.native + + /** + * Used by the QuadTree to set the maximum number of objects per quad. + */ + var maxObjects: Int = js.native + + /** + * The world QuadTree. + */ + var quadTree: Phaser.QuadTree = js.native + + /** + * Local reference to game.time. + */ + var time: Phaser.Time = js.native + + ///////////////////////////////////////////////////////////////////////////////// + // Methods + ///////////////////////////////////////////////////////////////////////////////// + + /** + * + * @param map + * @param layer + */ + def clearTilemapLayerBodies(map: Phaser.Tilemap, layer: Double | String | Phaser.TilemapLayer): Unit = js.native } diff --git a/browser/phaser/src/main/scala/io/scalajs/dom/html/phaser/physics/P2.scala b/browser/phaser/src/main/scala/io/scalajs/dom/html/phaser/physics/P2.scala index f69b152dc..aa7e07918 100644 --- a/browser/phaser/src/main/scala/io/scalajs/dom/html/phaser/physics/P2.scala +++ b/browser/phaser/src/main/scala/io/scalajs/dom/html/phaser/physics/P2.scala @@ -1,7 +1,7 @@ -package io.scalajs.dom.html.phaser.physics +package io.scalajs.dom.html.phaser +package physics import io.scalajs.RawOptions -import io.scalajs.dom.html.phaser.{Game, Sprite} import scala.scalajs.js import scala.scalajs.js.annotation.JSName @@ -14,12 +14,12 @@ import scala.scalajs.js.annotation.JSName */ @js.native @JSName("Phaser.Physics.P2") -class P2(val game: Game, val config: RawOptions = js.native) extends js.Object { +class P2(var game: Phaser.Game, val config: RawOptions = js.native) extends js.Object { /** * Enable to automatically apply body damping each step. */ - var applyDamping : Boolean = js.native + var applyDamping: Boolean = js.native /** * TODO @@ -110,12 +110,12 @@ object P2 extends js.Object { * @param mass The default mass of this Body (0 = static). */ @js.native - class Body(val game: Game, + class Body(var game: Phaser.Game, val sprite: Sprite, val x: Int = js.native, val y: Int = js.native, val mass: Int = js.native) - extends js.Object + extends js.Object @js.native object Body extends js.Object { @@ -149,7 +149,7 @@ object P2 extends js.Object { * @param settings Settings object. */ @js.native - class BodyDebug(val game: Game, val body: /*Phaser.Physics.*/ P2.Body, val settings: js.Any) extends js.Object + class BodyDebug(var game: Phaser.Game, val body: /*Phaser.Physics.*/ P2.Body, val settings: js.Any) extends js.Object // Phaser.Group(game, ) diff --git a/browser/phaser/src/main/scala/io/scalajs/dom/html/phaser/physics/arcade/Body.scala b/browser/phaser/src/main/scala/io/scalajs/dom/html/phaser/physics/arcade/Body.scala index a2b013879..0cbd0db93 100644 --- a/browser/phaser/src/main/scala/io/scalajs/dom/html/phaser/physics/arcade/Body.scala +++ b/browser/phaser/src/main/scala/io/scalajs/dom/html/phaser/physics/arcade/Body.scala @@ -99,4 +99,341 @@ class Body(val sprite: Phaser.Sprite) extends js.Object { */ var customSeparateY: Boolean = js.native + /** + * The Sprite position is updated based on the delta x/y values. You can set a cap on those (both +-) using deltaMax. + */ + var deltaMax: Phaser.Point = js.native + + /** + * If this Body in a preUpdate (true) or postUpdate (false) state? + */ + var dirty: Boolean = js.native + + /** + * The drag applied to the motion of the Body. + */ + var drag: Phaser.Point = js.native + + /** + * If a body is overlapping with another body, but neither of them are moving (maybe they spawned on-top of each other?) + * this is set to true. Body embed value. + */ + var embedded: Boolean = js.native + + /** + * A disabled body won't be checked for any form of collision or overlap or have its pre/post updates run. + */ + var enable: Boolean = js.native + + /** + * A const reference to the direction the Body is traveling or facing. + */ + var facing: Int = js.native + + /** + * The amount of movement that will occur if another object 'rides' this one. + */ + var friction: Phaser.Point = js.native + + /** + * Local reference to game. + */ + var game: Phaser.Game = js.native + + /** + * A local gravity applied to this Body. If non-zero this over rides any world gravity, + * unless Body.allowGravity is set to false. + */ + var gravity: Phaser.Point = js.native + + /** + * The calculated height / 2 of the physics body. + */ + def halfHeight: Double = js.native + + /** + * The calculated width / 2 of the physics body. + */ + def halfWidth: Double = js.native + + /** + * The calculated height of the physics body. + */ + def height: Double = js.native + + /** + * An immovable Body will not receive any impacts from other bodies. + */ + def immovable: Boolean = js.native + + /** + * If true this Body is using circular collision detection. If false it is using rectangular. + * Use Body.setCircle to control the collision shape this Body uses. + */ + def isCircle: Boolean = js.native + + /** + * Set by the moveTo and moveFrom methods. + */ + var isMoving: Boolean = js.native + + /** + * The x position of the Body. The same as `Body.x`. + */ + var left: Double = js.native + + /** + * The mass of the Body. When two bodies collide their mass is used in the calculation to determine + * the exchange of velocity (default: 1). + */ + var mass: Double = js.native + + /** + * The maximum angular velocity in degrees per second that the Body can reach. + */ + var maxAngular: Double = js.native + + /** + * The maximum velocity in pixels per second sq. that the Body can reach. + */ + var maxVelocity: Phaser.Point = js.native + + /** + * Optional callback. If set, invoked during the running of `moveTo` or `moveFrom` events. + */ + var movementCallback: js.Function = js.native + + /** + * Context in which to call the movementCallback. + */ + var movementCallbackContext: js.Object = js.native + + /** + * If you have a Body that is being moved around the world via a tween or a Group motion, but its local x/y position never + * actually changes, then you should set Body.moves = false. Otherwise it will most likely fly off the screen. + * + * If you want the physics system to move the body around, then set moves to true. Set to true to allow the + * Physics system to move this Body, otherwise false to move it manually. + */ + var moves: Boolean = js.native + + /** + * The new velocity. Calculated during the Body.preUpdate and applied to its position. + */ + def newVelocity: Phaser.Point = js.native + + /** + * The offset of the Physics Body from the Sprite x/y position. + */ + var offset: Phaser.Point = js.native + + /** + * A Signal that is dispatched when this Body collides with another Body. + * * + * You still need to call game.physics.arcade.collide in your update method in order + * for this signal to be dispatched. + * * + * Usually you'd pass a callback to the collide method, but this signal provides for + * a different level of notification. + * * + * Due to the potentially high volume of signals this could create it is disabled by default. + * * + * To use this feature set this property to a Phaser.Signal: + * {{{ + * sprite.body.onCollide = new Phaser.Signal() + * }}} + * and it will be called when a collision happens, passing two arguments: the sprites which collided. + * The first sprite in the argument is always the owner of this Body. + * * + * If two Bodies with this Signal set collide, both will dispatch the Signal. + */ + var onCollide: Phaser.Signal = js.native + + /** + * Listen for the completion of `moveTo` or `moveFrom` events. + */ + var onMoveComplete: Phaser.Signal = js.native + + /** + * A Signal that is dispatched when this Body overlaps with another Body. + * + * You still need to call game.physics.arcade.overlap in your update method in order + * for this signal to be dispatched. + * + * Usually you'd pass a callback to the overlap method, but this signal provides for + * a different level of notification. + * + * Due to the potentially high volume of signals this could create it is disabled by default. + * + * To use this feature set this property to a Phaser.Signal: sprite.body.onOverlap = new Phaser.Signal() + * and it will be called when a collision happens, passing two arguments: the sprites which collided. + * The first sprite in the argument is always the owner of this Body. + * + * If two Bodies with this Signal set collide, both will dispatch the Signal. + */ + var onOverlap: Phaser.Signal = js.native + + /** + * A Signal that is dispatched when this Body collides with the world bounds. + * Due to the potentially high volume of signals this could create it is disabled by default. + * To use this feature set this property to a Phaser.Signal: + * {{{ + * sprite.body.onWorldBounds = new Phaser.Signal() + * }}} + * and it will be called when a collision happens, passing five arguments: + * {{{ + * onWorldBounds(sprite, up, down, left, right) + * }}} + * where the Sprite is a reference to the Sprite that owns this Body, and the other arguments are booleans + * indicating on which side of the world the Body collided. + */ + var onWorldBounds: Phaser.Signal = js.native + + /** + * If `Body.isCircle` is true, and this body collides with another circular body, the amount of overlap is stored here. + * The amount of overlap during the collision. + */ + var overlapR: Double = js.native + + /** + * When this body collides with another, the amount of overlap is stored here. + * The amount of horizontal overlap during the collision. + */ + var overlapX: Double = js.native + + /** + * When this body collides with another, the amount of overlap is stored here. + * The amount of vertical overlap during the collision. + */ + var overlapY: Double = js.native + + /** + * The position of the physics body. + */ + def position: Phaser.Point = js.native + + /** + * The previous rotation of the physics body. + */ + def preRotation: Double = js.native + + /** + * The previous position of the physics body. + */ + def prev: Phaser.Point = js.native + + /** + * The radius of the circular collision shape this Body is using if Body.setCircle has been enabled. + * If you wish to change the radius then call setCircle again with the new value. + * If you wish to stop the Body using a circle then call setCircle with a radius of zero (or undefined). + */ + def radius: Double = js.native + + /** + * The right value of this Body (same as Body.x + Body.width) + */ + def right: Double = js.native + + /** + * The Body's rotation in degrees, as calculated by its angularVelocity and angularAcceleration. + * Please understand that the collision Body + * + * itself never rotates, it is always axis-aligned. However these values are passed up to the + * parent Sprite and updates its rotation. + */ + def rotation: Double = js.native + + /** + * If true and you collide this Sprite against a Group, + * it will disable the collision check from using a QuadTree. + */ + var skipQuadTree: Boolean = js.native + + /** + * The un-scaled original size. + */ + def sourceHeight: Double = js.native + + /** + * The un-scaled original size. + */ + def sourceWidth: Double = js.native + + /** + * The speed of the Body as calculated by its velocity. + */ + def speed: Double = js.native + + /** + * Set by the moveTo and moveFrom methods. + */ + var stopVelocityOnCollide: Boolean = js.native + + /** + * If true the Body will check itself against the Sprite.getBounds() dimensions and adjust its width and height accordingly. + * If false it will compare its dimensions against the Sprite scale instead, and adjust its width height if the scale has changed. + * Typically you would need to enable syncBounds if your sprite is the child of a responsive display object such as a FlexLayer, + * or in any situation where the Sprite scale doesn't change, but its parents scale is effecting the dimensions regardless. + */ + var syncBounds: Boolean = js.native + + /** + * If this is an especially small or fast moving object then it can sometimes skip over tilemap collisions + * if it moves through a tile in a step. + * + * Set this padding value to add extra padding to its bounds. tilePadding.x applied to its width, y to its + * height. Extra padding to be added to this sprite's dimensions when checking for tile collision. + */ + var tilePadding: Phaser.Point = js.native + + /** + * The y position of the Body. The same as Body.y. + */ + var top: Double = js.native + + /** + * This object is populated with boolean values when the Body collides with another. + *touching.up = true means the collision happened to the top of this Body for example. + * An object containing touching results. + */ + var touching: js.Object = js.native + + /** + * The type of physics system this body belongs to. + */ + var `type`: Int = js.native + + /** + * The velocity, or rate of change in speed of the Body. Measured in pixels per second. + */ + var velocity: Point = js.native + + /** + * This object is populated with previous touching values from the bodies previous collision. + * An object containing previous touching results. + */ + var wasTouching: js.Object = js.native + + /** + * The calculated width of the physics body. + */ + def width: Double = js.native + + /** + * The elasticity of the Body when colliding with the World bounds. + * By default this property is null, in which case Body.bounce is used instead. Set this property + * to a Phaser.Point object in order to enable a World bounds specific bounce value. + */ + var worldBounce: Phaser.Point = js.native + + /** + * The x position. + */ + var x: Double = js.native + + /** + * The y position. + */ + var y: Double = js.native + } diff --git a/browser/phaser/src/main/scala/io/scalajs/dom/html/phaser/physics/ninja/AABB.scala b/browser/phaser/src/main/scala/io/scalajs/dom/html/phaser/physics/ninja/AABB.scala new file mode 100644 index 000000000..02ca33b37 --- /dev/null +++ b/browser/phaser/src/main/scala/io/scalajs/dom/html/phaser/physics/ninja/AABB.scala @@ -0,0 +1,25 @@ +package io.scalajs.dom.html.phaser +package physics.ninja + +import scala.scalajs.js +import scala.scalajs.js.annotation.JSName + +/** + * Ninja Physics AABB constructor. + * Note: This class could be massively optimised and reduced in size. I leave that challenge up to you. + * @param body The body that owns this shape. + * @param x The x coordinate to create this shape at. + * @param y The y coordinate to create this shape at. + * @param width The width of this AABB. + * @param height The height of this AABB. + */ +@js.native +@JSName("Phaser.Physics.Ninja.AABB") +class AABB(var body: Phaser.Physics.Ninja.Body, + 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/physics/ninja/Body.scala b/browser/phaser/src/main/scala/io/scalajs/dom/html/phaser/physics/ninja/Body.scala new file mode 100644 index 000000000..8298dc943 --- /dev/null +++ b/browser/phaser/src/main/scala/io/scalajs/dom/html/phaser/physics/ninja/Body.scala @@ -0,0 +1,75 @@ +package io.scalajs.dom.html.phaser.physics.ninja + +import io.scalajs.dom.html.phaser.Phaser + +import scala.scalajs.js +import scala.scalajs.js.annotation.JSName + +/** + * The Physics Body is linked to a single Sprite. All physics operations should be performed + * against the body rather than the Sprite itself. For example you can set the velocity, + * bounce values etc all on the Body. + * @param system The physics system this Body belongs to. + * @param sprite The Sprite object this physics body belongs to. + * @param `type` The type of Ninja shape to create. 1 = AABB, 2 = Circle or 3 = Tile. + * @param id If this body is using a Tile shape, you can set the Tile id here, + * i.e. Phaser.Physics.Ninja.Tile.SLOPE_45DEGpn, Phaser.Physics.Ninja.Tile.CONVEXpp, etc. + * @param radius If this body is using a Circle shape this controls the radius. + * @param x The x coordinate of this Body. This is only used if a sprite is not provided. + * @param y The y coordinate of this Body. This is only used if a sprite is not provided. + * @param width The width of this Body. This is only used if a sprite is not provided. + * @param height The height of this Body. This is only used if a sprite is not provided. + * @see http://phaser.io/docs/2.6.2/Phaser.Physics.Ninja.Body.html + */ +@js.native +@JSName("Phaser.Physics.Ninja.Body") +class Body(var system: Phaser.Physics.Ninja, + var sprite: Phaser.Sprite, + var `type`: Int = js.native, + var id: Int = js.native, + var radius: Double = js.native, + var x: Double = js.native, + var y: Double = js.native, + var width: Double = js.native, + var height: Double = js.native) + extends js.Object { + + ///////////////////////////////////////////////////////////////////////////////// + // Properties + ///////////////////////////////////////////////////////////////////////////////// + + /** + * The AABB object this body is using for collision. + */ + var aabb: Phaser.Physics.Ninja.AABB = js.native + + /** + * The angle of this Body + */ + def angle: Double = js.native + + /** + * The bottom value of this Body (same as Body.y + Body.height) + */ + var bottom: Double = js.native + + /** + * The bounciness of this object when it collides. A value between 0 and 1. + * We recommend setting it to 0.999 to avoid jittering. + */ + var bounce: Double = js.native + + /** + * Set the checkCollision properties to control which directions collision is processed for this Body. + * For example checkCollision.up = false means it won't collide when the collision happened while moving up. + * An object containing allowed collision. + */ + var checkCollision: js.Object = js.native + + ///////////////////////////////////////////////////////////////////////////////// + // Methods + ///////////////////////////////////////////////////////////////////////////////// + + + +} diff --git a/browser/pixijs/src/main/scala/io/scalajs/dom/html/pixijs/Container.scala b/browser/pixijs/src/main/scala/io/scalajs/dom/html/pixijs/Container.scala index 01f4494b5..429e54dda 100644 --- a/browser/pixijs/src/main/scala/io/scalajs/dom/html/pixijs/Container.scala +++ b/browser/pixijs/src/main/scala/io/scalajs/dom/html/pixijs/Container.scala @@ -112,8 +112,8 @@ class Container extends DisplayObject { /** * Destroys the container - * @param destroyChildren if set to true, all the children will have their destroy method called as well + * @param destroyChildren optional: if set to true, all the children will have their destroy method called as well */ - def destroy(destroyChildren: Boolean = false): Unit = js.native + def destroy(destroyChildren: Boolean): Unit = js.native } diff --git a/browser/pixijs/src/main/scala/io/scalajs/dom/html/pixijs/DisplayObject.scala b/browser/pixijs/src/main/scala/io/scalajs/dom/html/pixijs/DisplayObject.scala index 3e49390a1..382c217a2 100644 --- a/browser/pixijs/src/main/scala/io/scalajs/dom/html/pixijs/DisplayObject.scala +++ b/browser/pixijs/src/main/scala/io/scalajs/dom/html/pixijs/DisplayObject.scala @@ -20,6 +20,9 @@ trait DisplayObject extends js.Object { */ var alpha: Alpha = js.native + /** + * + */ var anchor: Point = js.native /** @@ -37,6 +40,9 @@ trait DisplayObject extends js.Object { */ var cacheAsBitmap: Boolean = js.native + /** + * + */ var visible: Boolean = js.native /** @@ -54,14 +60,14 @@ trait DisplayObject extends js.Object { */ def x: Double = js.native - def x_=(x : Double): Unit = js.native + def x_=(x: Double): Unit = js.native /** * The position of the displayObject 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 ///////////////////////////////////////////////////////////////////////////////// // Methods diff --git a/browser/pixijs/src/main/scala/io/scalajs/dom/html/pixijs/DisplayObjectContainer.scala b/browser/pixijs/src/main/scala/io/scalajs/dom/html/pixijs/DisplayObjectContainer.scala index f38a51863..b7495294b 100644 --- a/browser/pixijs/src/main/scala/io/scalajs/dom/html/pixijs/DisplayObjectContainer.scala +++ b/browser/pixijs/src/main/scala/io/scalajs/dom/html/pixijs/DisplayObjectContainer.scala @@ -1,6 +1,141 @@ package io.scalajs.dom.html.pixijs import scala.scalajs.js +import scala.scalajs.js.| +/** + * A DisplayObjectContainer represents a collection of display objects. + * It is the base class of all display objects that act as a container for other objects. + * @see http://phaser.io/docs/2.6.2/PIXI.DisplayObjectContainer.html + */ @js.native -trait DisplayObjectContainer extends DisplayObject +trait DisplayObjectContainer extends DisplayObject { + + ///////////////////////////////////////////////////////////////////////////////// + // Properties + ///////////////////////////////////////////////////////////////////////////////// + + /** + * Returns the array of children of this container. + * @return the array of children of this container. + */ + def children: js.Array[DisplayObject] = js.native + + /** + * The height of the displayObjectContainer, setting this will actually modify + * the scale to achieve the value set + */ + var height: Double = js.native + + /** + * If ignoreChildInput is false it will allow this objects children to be considered + * as valid for Input events. + * + * If this property is true then the children will not be considered as valid for Input events. + * + * Note that this property isn't recursive: only immediate children are influenced, + * it doesn't scan further down. + */ + var ignoreChildInput: Boolean = js.native + + /** + * The width of the displayObjectContainer, setting this will actually modify the + * scale to achieve the value set + */ + var width: Double = js.native + + ///////////////////////////////////////////////////////////////////////////////// + // Methods + ///////////////////////////////////////////////////////////////////////////////// + + /** + * Adds a child to the container. + * @param child The DisplayObject to add to the container + * @return The child that was added. + */ + def addChild(child: DisplayObject): DisplayObject = js.native + + /** + * Adds a child to the container at a specified index. If the index is out of bounds an error will be thrown + * @param child The child to add + * @param index The index to place the child in + * @return The child that was added. + */ + def addChildAt(child: DisplayObject, index: Int): DisplayObject = js.native + + /** + * Determines whether the specified display object is a child of the DisplayObjectContainer + * instance or the instance itself. + * @param child the child to check the existence of + * @return true if this container contains the given child + */ + def contains(child: DisplayObject): Boolean = js.native + + /** + * Retrieves the global bounds of the displayObjectContainer as a rectangle. + * The bounds calculation takes all visible children into consideration. + * @param targetCoordinateSpace Returns a rectangle that defines the area of the + * display object relative to the coordinate system + * of the targetCoordinateSpace object. + * @return The rectangular bounding area + */ + def getBounds(targetCoordinateSpace: PIXI.DisplayObject | PIXI.Matrix = js.native): Rectangle = js.native + + /** + * Returns the child at the specified index + * @param index the specified index + * @return The child at the given index, if any. + */ + def getChildAt(index: Int): DisplayObject = js.native + + /** + * Returns the index position of a child DisplayObject instance + * @param child The DisplayObject instance to identify + * @return The index position of the child display object to identify + */ + def getChildIndex(child: DisplayObject): Int = js.native + + /** + * Retrieves the non-global local bounds of the displayObjectContainer as a rectangle + * without any transformations. The calculation takes all visible children into consideration. + * @return The rectangular bounding area + */ + def getLocalBounds(): Rectangle = js.native + + /** + * Removes a child from the container. + * @param child The DisplayObject to remove + * @return The child that was removed. + */ + def removeChild(child: DisplayObject): DisplayObject = js.native + + /** + * Removes a child from the specified index position. + * @param index The index to get the child from + * @return The child that was removed. + */ + def removeChildAt(index: Int): DisplayObject = js.native + + /** + * Removes all children from this container that are within the begin and end indexes. + * @param beginIndex The beginning position. Default value is 0. + * @param endIndex The ending position. Default value is size of the container. + */ + def removeChildren(beginIndex: Int, endIndex: Int): Unit = js.native + + /** + * Changes the position of an existing child in the display object container + * @param child The child DisplayObject instance for which you want to change the index number + * @param index The resulting index number for the child display object + */ + def setChildIndex(child: DisplayObject, index: Int): Unit = js.native + + /** + * Swaps the position of 2 Display Objects within this container. + * @param child child 1 of 2 + * @param child2 child 2 of 2 + */ + def swapChildren(child: DisplayObject, child2: DisplayObject): Unit = js.native + + +} diff --git a/browser/pixijs/src/main/scala/io/scalajs/dom/html/pixijs/Matrix.scala b/browser/pixijs/src/main/scala/io/scalajs/dom/html/pixijs/Matrix.scala index 48b7b2e2c..d6032813a 100644 --- a/browser/pixijs/src/main/scala/io/scalajs/dom/html/pixijs/Matrix.scala +++ b/browser/pixijs/src/main/scala/io/scalajs/dom/html/pixijs/Matrix.scala @@ -12,6 +12,7 @@ import scala.scalajs.js.annotation.JSName * +---+---+---+ * | 0 | 0 | 1 | * }}} + * @see https://phaser.io/docs/2.2.2/PIXI.Matrix.html */ @js.native @JSName("Matrix") diff --git a/browser/pixijs/src/main/scala/io/scalajs/dom/html/pixijs/PIXI.scala b/browser/pixijs/src/main/scala/io/scalajs/dom/html/pixijs/PIXI.scala index e207fe67c..d2b5b93f9 100644 --- a/browser/pixijs/src/main/scala/io/scalajs/dom/html/pixijs/PIXI.scala +++ b/browser/pixijs/src/main/scala/io/scalajs/dom/html/pixijs/PIXI.scala @@ -1,4 +1,5 @@ -package io.scalajs.dom.html.pixijs +package io.scalajs.dom.html +package pixijs import io.scalajs.RawOptions import io.scalajs.dom.html.canvas.HTMLCanvasElement @@ -57,6 +58,14 @@ object PIXI extends js.Object { */ val VERSION: String = js.native + ///////////////////////////////////////////////////////////////////////////////// + // Class References + ///////////////////////////////////////////////////////////////////////////////// + + type DisplayObject = pixijs.DisplayObject + type DisplayObjectContainer = pixijs.DisplayObjectContainer + type Matrix = pixijs.Matrix + ///////////////////////////////////////////////////////////////////////////////// // Methods ///////////////////////////////////////////////////////////////////////////////// @@ -87,23 +96,23 @@ object PIXI extends js.Object { @js.native @JSName("BLEND_MODES") object BLEND_MODES extends js.Object { - val NORMAL: BlendMode = js.native - val ADD: BlendMode = js.native - val MULTIPLY: BlendMode = js.native - val SCREEN: BlendMode = js.native - val OVERLAY: BlendMode = js.native - val DARKEN: BlendMode = js.native - val LIGHTEN: BlendMode = js.native + val NORMAL: BlendMode = js.native + val ADD: BlendMode = js.native + val MULTIPLY: BlendMode = js.native + val SCREEN: BlendMode = js.native + val OVERLAY: BlendMode = js.native + val DARKEN: BlendMode = js.native + val LIGHTEN: BlendMode = js.native val COLOR_DODGE: BlendMode = js.native - val COLOR_BURN: BlendMode = js.native - val HARD_LIGHT: BlendMode = js.native - val SOFT_LIGHT: BlendMode = js.native - val DIFFERENCE: BlendMode = js.native - val EXCLUSION: BlendMode = js.native - val HUE: BlendMode = js.native - val SATURATION: BlendMode = js.native - val COLOR: BlendMode = js.native - val LUMINOSITY: BlendMode = js.native + val COLOR_BURN: BlendMode = js.native + val HARD_LIGHT: BlendMode = js.native + val SOFT_LIGHT: BlendMode = js.native + val DIFFERENCE: BlendMode = js.native + val EXCLUSION: BlendMode = js.native + val HUE: BlendMode = js.native + val SATURATION: BlendMode = js.native + val COLOR: BlendMode = js.native + val LUMINOSITY: BlendMode = js.native } /** @@ -113,15 +122,15 @@ object PIXI extends js.Object { @js.native @JSName("DEFAULT_RENDER_OPTIONS") object DEFAULT_RENDER_OPTIONS extends js.Object { - var view: HTMLCanvasElement = js.native - var transparent: Boolean = js.native - var antialias: Boolean = js.native - var forceFXAA: Boolean = js.native + var view: HTMLCanvasElement = js.native + var transparent: Boolean = js.native + var antialias: Boolean = js.native + var forceFXAA: Boolean = js.native var preserveDrawingBuffer: Boolean = js.native - var resolution: Resolution = js.native - var backgroundColor: Color = js.native - var clearBeforeRender: Boolean = js.native - var autoResize: Boolean = js.native + var resolution: Resolution = js.native + var backgroundColor: Color = js.native + var clearBeforeRender: Boolean = js.native + var autoResize: Boolean = js.native } /** @@ -130,13 +139,13 @@ object PIXI extends js.Object { @js.native @JSName("DRAW_MODES") object DRAW_MODES extends js.Object { - var POINTS: Int = js.native - var LINES: Int = js.native - var LINE_LOOP: Int = js.native - var LINE_STRIP: Int = js.native - var TRIANGLES: Int = js.native + var POINTS: Int = js.native + var LINES: Int = js.native + var LINE_LOOP: Int = js.native + var LINE_STRIP: Int = js.native + var TRIANGLES: Int = js.native var TRIANGLE_STRIP: Int = js.native - var TRIANGLE_FAN: Int = js.native + var TRIANGLE_FAN: Int = js.native } /** @@ -221,9 +230,9 @@ object PIXI extends js.Object { @js.native @JSName("RENDERER_TYPE") object RENDERER_TYPE extends js.Object { - val CANVAS: Int = js.native + val CANVAS: Int = js.native val UNKNOWN: Int = js.native - val WEBGL: Int = js.native + val WEBGL: Int = js.native } /** diff --git a/build.sbt b/build.sbt index 3c99e6a77..b3979419e 100644 --- a/build.sbt +++ b/build.sbt @@ -6,8 +6,8 @@ import sbt._ import scala.language.postfixOps -val apiVersion = "0.3.0.2" -val _scalaVersion = "2.12.1" +val apiVersion = "0.3.0.3" +val scalaJsVersion = "2.12.1" organization := "io.scalajs" @@ -15,14 +15,14 @@ homepage := Some(url("https://github.com/ldaniels528/scalajs.io")) val commonSettings = Seq( version := apiVersion, - scalaVersion := _scalaVersion, + scalaVersion := scalaJsVersion, scalacOptions ++= Seq("-deprecation", "-unchecked", "-feature", "-language:implicitConversions", "-Xlint"), scalacOptions in(Compile, doc) ++= Seq("-no-link-warnings"), autoCompilerPlugins := true, scalaJSModuleKind := ModuleKind.CommonJSModule, addCompilerPlugin("org.scalamacros" % "paradise" % "2.1.0" cross CrossVersion.full), libraryDependencies ++= Seq( - "org.scala-lang" % "scala-reflect" % _scalaVersion, + "org.scala-lang" % "scala-reflect" % scalaJsVersion, "org.scalatest" %%% "scalatest" % "3.0.1" % "test" ))