Skip to content
This repository has been archived by the owner on Apr 15, 2022. It is now read-only.

Commit

Permalink
Merge branch 'dev' of https://github.com/PBS-KIDS/Platypus into dev
Browse files Browse the repository at this point in the history
Conflicts:
	lib/platypus.combined.js
	lib/platypus.min.js
  • Loading branch information
Todd Lewis committed Dec 18, 2015
2 parents fc72a3b + 8829fda commit 3d4d5c2
Show file tree
Hide file tree
Showing 9 changed files with 712 additions and 470 deletions.
1 change: 1 addition & 0 deletions build/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"../src/Scene.js",
"../src/Vector.js",
"../src/AABB.js",
"../src/ActionState.js",
"../src/CollisionDataContainer.js",
"../src/CollisionShape.js",
"../src/Entity.js",
Expand Down
587 changes: 355 additions & 232 deletions lib/platypus.combined.js

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions lib/platypus.min.js

Large diffs are not rendered by default.

169 changes: 169 additions & 0 deletions src/ActionState.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
/**
* This class defines an action state based on one or more inputs. This is used by [EntityController](platypus.components.EntityController.html) to produce event messages listing whether a particular action is "triggered", "pressed", and/or "released".
*
* @namespace platypus
* @class ActionState
* @constructor
* @param event {String} The name of the event to trigger on the Entity.
* @param states {Object} A list of key/value pairs describing what states should be `true` or `false` on the Entity for this action to be triggered.
* @param trigger {Function} The function to be called if one or more inputs are active and the current state of the Entity is valid.
* @return {ActionState} Returns the new ActionState object.
* @since 0.6.8
*/
/*global platypus */
platypus.ActionState = (function () {
"use strict";

var ActionState = function (event, states, trigger) {
/**
* The name of the event to trigger on the Entity.
*
* @property event
* @type String
*/
this.event = event;

/**
* The function to call if the ActionState is active.
*
* @property trigger
* @type Function
*/
this.trigger = trigger;

/**
* Whether any of the ActionState's inputs are active.
*
* @property active
* @type Boolean
*/
this.active = false;

/**
* Whether any of the ActionState's inputs were active last update.
*
* @property wasActive
* @type Boolean
*/
this.wasActive = false;

/**
* Whether the Entity's state is valid for this ActionState.
*
* @property valid
* @type Boolean
*/
this.valid = true;

/**
* Whether the Entity's state was valid for this ActionState last update.
*
* @property wasValid
* @type Boolean
*/
this.wasValid = true;

/**
* The state of the Entity that is valid for this ActionState.
*
* @property states
* @type Object
*/
this.states = states || {};

/**
* The list of input toggles to track control input.
*
* @property inputs
* @type Array
*/
this.inputs = [];

/**
* The message that is passed to the Entity if the ActionState is active.
*
* @property stateSummary
* @type Object
*/
this.stateSummary = {
pressed: false,
released: false,
triggered: false
};
},
orArray = function (element) {
return element;
},
proto = ActionState.prototype;

/**
* Updates the state of the action by checking the state of the Entity and whether any inputs are active.
*
* @method update
* @param state {Object} The Entity's `state` property to compare against the ActionState's valid state.
* @return {Boolean} Whether the ActionState is triggered, pressed, or released.
*/
proto.update = function (state) {
var ss = this.stateSummary;

this.valid = this.isStateValid(state);
this.active = this.inputs.some(orArray);

ss.pressed = this.valid && this.active;
ss.released = this.wasActive && ((!this.valid && this.wasValid) || (this.valid && !this.active));
ss.triggered = this.valid && this.active && !this.wasActive;

this.wasValid = this.valid;
this.wasActive = this.active;

return ss.pressed || ss.released || ss.triggered;
};

/**
* Triggers events on the Entity related to the ActionState's state. This is necessarily separate from the `update` method since triggered events could affect entity state. The messages have the following form and are only triggered if one of the values is `true`:
*
* {
* "triggered": true,
* "pressed": true,
* "released": false
* }
*
* Here is a mapping of the various event messages depending on the ActionState's state.
*
* ActionState State:
* wasValid: 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1
* valid: 0 0 0 0 1 1 1 1 0 0 0 0 1 1 1 1
* wasActive: 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1
* active: 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1
* Events:
* triggered: 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0
* pressed: 0 0 0 0 0 1 0 1 0 0 0 0 0 1 0 1
* released: 0 0 0 0 0 0 1 0 0 0 1 1 0 0 1 0
*
* @method resolve
*/
proto.resolve = function () {
this.trigger(this.event, this.stateSummary);
};

/**
* Determines whether the ActionState is valid for the Entity's current state.
*
* @method isStateValid
* @return {Boolean} Whether the current Entity state is valid for this ActionState.
*/
proto.isStateValid = function (ownerState) {
var key = '',
states = this.states;

for (key in states) {
if (states.hasOwnProperty(key) && ownerState.hasOwnProperty(key) && (states[key] !== ownerState[key])) {
return false;
}
}

return true;
};

return ActionState;
}());
19 changes: 2 additions & 17 deletions src/Scene.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ platypus.Scene = (function () {
}
messages.length = 0;

this.time = new Date().getTime();
this.time = Date.now();
this.timeElapsed = {
name: '',
time: 0
Expand All @@ -109,32 +109,17 @@ platypus.Scene = (function () {
* @param {*} event This is a message object or other value to pass along to component functions.
**/
proto.trigger = function (eventId, event) {
var i = 0,
time = 0;
var i = 0;

if (this.storedMessages) {
this.storedMessages.push({
message: eventId,
value: event
});
} else {
if (eventId === 'tick') {
time = new Date().getTime();
this.timeElapsed.name = 'Non-Engine';
this.timeElapsed.time = time - this.time;
this.trigger('time-elapsed', this.timeElapsed);
this.time = time;
}
for (i = 0; i < this.layers.length; i++) {
this.layers[i].trigger(eventId, event);
}
if (eventId === 'tick') {
time = new Date().getTime();
this.timeElapsed.name = 'Engine Total';
this.timeElapsed.time = time - this.time;
this.trigger('time-elapsed', this.timeElapsed);
this.time = time;
}
}
};

Expand Down
48 changes: 36 additions & 12 deletions src/components/Camera.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@
* @class Camera
* @uses platypus.Component
*/
/*global console, createjs, PIXI, platypus, springroll */
/*global console, createjs, PIXI, platypus, include */
/*jslint plusplus:true */
(function () {
"use strict";

var Application = include("springroll.Application");

return platypus.createComponentClass({
id: 'Camera',
properties: {
Expand Down Expand Up @@ -157,7 +159,8 @@
viewport: new platypus.AABB(),
scaleX: 0,
scaleY: 0,
orientation: 0
orientation: 0,
stationary: false
};

//Whether the map has finished loading.
Expand Down Expand Up @@ -215,7 +218,7 @@
if (this.owner.container) {
this.parentContainer = this.owner.container;
} else if (this.owner.stage) {
this.canvas = this.canvas || springroll.Application.instance.display.canvas; //TODO: Probably need to find a better way to handle resizing - DDD 10/4/2015
this.canvas = this.canvas || Application.instance.display.canvas; //TODO: Probably need to find a better way to handle resizing - DDD 10/4/2015
this.parentContainer = this.owner.stage;
this.owner.width = this.canvas.width;
this.owner.height = this.canvas.height;
Expand Down Expand Up @@ -275,6 +278,21 @@
}
},

/**
* Triggers "camera-update" on newly changed entities.
*
* @method 'child-entity-updated'
* @param entity {platypus.Entity} Expects an entity as the message object to determine whether to trigger `camera-update` on it.
* @since 0.6.8
**/
"child-entity-updated": function (entity) {
this.viewportUpdate = true;

if (this.worldIsLoaded) {
entity.triggerEvent('camera-update', this.message);
}
},

/**
* On receiving this message, the camera updates its world location and size as necessary. An example of this message is triggered by the [TiledLoader](platypus.components.TiledLoader.html) component.
*
Expand Down Expand Up @@ -334,6 +352,7 @@
if (this.viewportUpdate) {
this.viewportUpdate = false;
this.stationary = false;
msg.stationary = false;

viewport.set(this.worldCamera.viewport);

Expand Down Expand Up @@ -374,31 +393,36 @@
*
* @event 'camera-update'
* @param message {Object}
* @param message.orientation {number} Number describing the orientation of the camera.
* @param message.scaleX {number} Number of window pixels that comprise a single world coordinate on the x-axis.
* @param message.scaleY {number} Number of window pixels that comprise a single world coordinate on the y-axis.
* @param message.orientation {Number} Number describing the orientation of the camera.
* @param message.scaleX {Number} Number of window pixels that comprise a single world coordinate on the x-axis.
* @param message.scaleY {Number} Number of window pixels that comprise a single world coordinate on the y-axis.
* @param message.viewport {platypus.AABB} An AABB describing the world viewport area.
* @param message.stationary {Boolean} Whether the camera is moving.
**/
this.owner.trigger('camera-update', msg);

if (this.owner.triggerEventOnChildren) {
this.owner.triggerEventOnChildren('camera-update', msg);
}

} else if (!this.stationary) {
this.stationary = true;
msg.stationary = true;

this.owner.trigger('camera-update', msg);
if (this.owner.triggerEventOnChildren) {
this.owner.triggerEventOnChildren('camera-update', msg);
}

/**
* This component triggers "camera-stationary" on the entity when the camera stops moving.
*
* @event 'camera-stationary'
* @deprecated since 0.6.8 - Listen for "camera-update" instead, with a `stationary` property of `true`.
**/
this.owner.trigger('camera-stationary', msg);
this.stationary = true;

}

if (this.lastFollow.begin) {
if (this.lastFollow.begin < new Date().getTime()) {
if (this.lastFollow.begin < Date.now()) {
this.follow(this.lastFollow);
}
}
Expand Down Expand Up @@ -522,7 +546,7 @@
this.lastFollow.offsetX = this.offsetX;
this.lastFollow.offsetY = this.offsetY;
}
this.lastFollow.begin = new Date().getTime() + def.time;
this.lastFollow.begin = Date.now() + def.time;
} else {
if (this.lastFollow.begin) {
this.lastFollow.begin = 0;
Expand Down
Loading

0 comments on commit 3d4d5c2

Please sign in to comment.