Socket
Socket
Sign inDemoInstall

chem

Package Overview
Dependencies
Maintainers
2
Versions
38
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

chem - npm Package Compare versions

Comparing version 0.4.1 to 0.4.2

49

lib/engine.js

@@ -35,2 +35,3 @@ var vec2d = require('vec2d');

this.setMinFps(20);
this.buttonCaptureExceptions = {};
}

@@ -47,2 +48,3 @@

};
Engine.prototype.start = function(){

@@ -52,2 +54,3 @@ this.attachListeners();

};
Engine.prototype.stop = function(){

@@ -57,8 +60,15 @@ this.stopMainLoop();

};
Engine.prototype.buttonState = function(button){
return !!this.buttonStates[button];
};
Engine.prototype.buttonJustPressed = function(button){
return !!this.btnJustPressed[button];
};
Engine.prototype.buttonJustReleased = function(button){
return !!this.btnJustReleased[button];
};
Engine.prototype.draw = function(batch){

@@ -107,2 +117,3 @@ for (var i = 0; i < batch.sprites.length; ++i) {

self.btnJustPressed = {};
self.btnJustReleased = {};
self.emit('draw', self.context);

@@ -121,4 +132,6 @@ var fps = 1 / delta;

this.btnJustPressed = {};
this.btnJustReleased = {};
// disable right click context menu
addListener(this.canvas, 'contextmenu', function(event){
if (self.buttonCaptureExceptions[button.MouseRight]) return true;
event.preventDefault();

@@ -135,4 +148,3 @@ });

addListener(this.canvas, 'mousedown', function(event){
var buttonId;
buttonId = MOUSE_OFFSET + event.which;
var buttonId = MOUSE_OFFSET + event.which;
self.buttonStates[buttonId] = true;

@@ -146,2 +158,3 @@ self.btnJustPressed[buttonId] = true;

self.buttonStates[buttonId] = false;
self.btnJustReleased[buttonId] = true;
self.emit('buttonup', buttonId);

@@ -151,17 +164,14 @@ });

addListener(this.canvas, 'keydown', function(event){
var buttonId;
buttonId = KEY_OFFSET + event.which;
var buttonId = KEY_OFFSET + event.which;
self.btnJustPressed[buttonId] = !self.buttonStates[buttonId];
self.buttonStates[buttonId] = true;
self.emit('buttondown', buttonId);
event.preventDefault();
return false;
return self.bubbleEvent(event);
});
addListener(this.canvas, 'keyup', function(event){
var buttonId;
buttonId = KEY_OFFSET + event.which;
var buttonId = KEY_OFFSET + event.which;
self.btnJustReleased[buttonId] = self.buttonStates[buttonId];
self.buttonStates[buttonId] = false;
self.emit('buttonup', buttonId);
event.preventDefault();
return false;
return self.bubbleEvent(event);
});

@@ -173,2 +183,21 @@ function addListener(element, eventName, listener){

};
Engine.prototype.bubbleEvent = function(event) {
// we need to figure out whether to bubble this key event up.
// if the button is an exception, bubble it up.
// also if any other exceptions are pressed, bubble it up.
// this allows ctrl+(anything) to work.
var buttonId = KEY_OFFSET + event.which;
if (this.buttonCaptureExceptions[buttonId] ||
(event.ctrlKey && this.buttonCaptureExceptions[button.KeyCtrl]) ||
(event.altKey && this.buttonCaptureExceptions[button.KeyAlt]) ||
(event.shiftKey && this.buttonCaptureExceptions[button.KeyShift]))
{
return true;
} else {
event.preventDefault();
return false;
}
}
Engine.prototype.removeListeners = function(){

@@ -175,0 +204,0 @@ this.listeners.forEach(function(listener) {

@@ -5,3 +5,3 @@ {

"author": "Andrew Kelley <superjoe30@gmail.com>",
"version": "0.4.1",
"version": "0.4.2",
"main": "index.js",

@@ -8,0 +8,0 @@ "license": "MIT",

@@ -6,3 +6,3 @@ chem - html5 game engine optimized for rapid development

# install chem
# install chem command line interface
sudo apt-get install libcairo2-dev

@@ -20,2 +20,4 @@ sudo npm install -g chem-cli

chem
See [chem-cli](http://github.com/superjoe30/chem-cli) for more information.

@@ -243,2 +245,3 @@ ## Synopsis

* `Engine::buttonJustPressed`
* `Engine::buttonJustReleased`
* `Engine:: 'buttondown' event (button)`

@@ -289,8 +292,14 @@ * `Engine:: 'buttonup' event (button)`

Call from the `update` event. It returns true if `button` is pressed,
but then returns false for subsequent calls until `button` is released
and pressed again.
Call from the `update` event. It returns `true` for the 1 frame
after the button was pressed.
See also `button`.
`Engine::buttonJustReleased(button)`
Call from the `update` event. It returns `true` for the 1 frame
after the button was released.
See also `button`.
`Engine::draw(batch)`

@@ -327,3 +336,14 @@

`Engine::buttonCaptureExceptions`
Read/write. This is an object which is initially empty and contains
buttons which the game should bubble up instead of capturing.
Example:
```js
// now you can press Ctrl+R, etc
engine.buttonCaptureExceptions[chem.button.KeyCtrl] = true;
```
##### events

@@ -586,2 +606,4 @@

See also [chem-cli](http://github.com/superjoe30/chem-cli)
# set up dev environment for chem itself:

@@ -593,2 +615,7 @@ sudo apt-get install libcairo2-dev

### 0.4.2
* support `buttonJustReleased`
* ability to add button capture exceptions
### 0.4.1

@@ -595,0 +622,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc