Socket
Socket
Sign inDemoInstall

chem

Package Overview
Dependencies
1
Maintainers
2
Versions
38
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 3.1.0 to 3.2.0

17

doc/api.md

@@ -186,4 +186,21 @@ **Table of Contents** *generated with [DocToc](http://doctoc.herokuapp.com/)*

#### prefix
Path to prefix asset urls with.
### methods
#### url(relativePath)
Returns the correct resource url, taking into account prefix, based on a
relative asset path.
#### fetchTextFile(relativePath, callback)
`callback(err, textFileContents)`
#### fetchImage(relativePath, callback)
`callback(err, image)`
### events

@@ -190,0 +207,0 @@

4

doc/history.md
# History
## 3.2.0
* ability to build with an asset prefix to make deployment easier
## 3.1.0

@@ -4,0 +8,0 @@

77

lib/resources.js

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

this.useSpritesheet = true;
this.prefix = "";
}

@@ -27,6 +28,42 @@

// fetch a resource from the server
ResourceLoader.prototype.fetchTextFile = fetchTextFile;
ResourceLoader.prototype.fetchImage = fetchImage;
ResourceLoader.prototype.url = function(relativeUrl) {
if (this.prefix) {
var lastChar = this.prefix[this.prefix.length - 1];
if (lastChar === '/') {
return this.prefix + relativeUrl;
} else {
return this.prefix + '/' + relativeUrl;
}
} else {
return relativeUrl;
}
};
ResourceLoader.prototype.fetchTextFile = function(path, cb) {
var request = new XMLHttpRequest();
request.onreadystatechange = onReadyStateChange;
request.open("GET", this.url(path), true);
try {
request.send();
} catch (err) {
cb(err);
}
function onReadyStateChange() {
if (request.readyState !== 4) return;
if (Math.floor(request.status / 100) === 2) {
cb(null, request.responseText);
return;
}
cb(new Error(request.status + ": " + request.statusText));
}
}
ResourceLoader.prototype.fetchImage = function (path, cb) {
var img = new Image();
img.src = this.url(path);
img.onload = function(){
cb(null, img);
};
}
function bootstrap(self) {

@@ -69,3 +106,3 @@ var batch = new Batch();

function loadAnimationsJson(cb) {
fetchImage("spritesheet.png", function(err, img) {
self.fetchImage("spritesheet.png", function(err, img) {
if (err) return cb(err);

@@ -78,3 +115,3 @@ self.spritesheet = img;

function loadSpritesheet(cb) {
fetchTextFile("animations.json", function(err, text) {
self.fetchTextFile("animations.json", function(err, text) {
if (err) return cb(err);

@@ -93,3 +130,3 @@

return function(cb) {
fetchTextFile(path, function(err, contents) {
self.fetchTextFile(path, function(err, contents) {
if (err) return cb(err);

@@ -105,3 +142,3 @@ self.text[name] = contents;

return function(cb) {
fetchImage(path, function(err, img) {
self.fetchImage(path, function(err, img) {
if (err) return cb(err);

@@ -115,29 +152,3 @@ self.images[name] = img;

function fetchImage(path, cb) {
var img = new Image();
img.src = path;
img.onload = function(){
cb(null, img);
};
}
function fetchTextFile(path, cb) {
var request = new XMLHttpRequest();
request.onreadystatechange = onReadyStateChange;
request.open("GET", path, true);
try {
request.send();
} catch (err) {
cb(err);
}
function onReadyStateChange() {
if (request.readyState !== 4) return;
if (Math.floor(request.status / 100) === 2) {
cb(null, request.responseText);
return;
}
cb(new Error(request.status + ": " + request.statusText));
}
}
module.exports = new ResourceLoader();
var EventEmitter = require('events').EventEmitter;
var util = require('util');
var resources = require('./resources');

@@ -10,3 +11,4 @@ module.exports = Sound;

this.currentSrc = src;
this.audioPool = [new Audio(src)];
this.resolvedSrc = resources.url(src);
this.audioPool = [new Audio(this.resolvedSrc)];
this.maxPoolSize = 10;

@@ -40,3 +42,3 @@ this.volume = 1;

if (this.audioPool.length < this.maxPoolSize) {
var newAudio = new Audio(this.currentSrc);
var newAudio = new Audio(this.resolvedSrc);
applySettingsToAudio(this, newAudio);

@@ -43,0 +45,0 @@ newAudio.play();

{
"name": "chem",
"description": "html5 canvas game engine optimized for rapid development - runtime",
"description": "html5 canvas 2D game engine optimized for rapid development - runtime",
"author": "Andrew Kelley <superjoe30@gmail.com>",
"version": "3.1.0",
"version": "3.2.0",
"main": "index.js",

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

@@ -5,4 +5,2 @@ ![chem](http://i.imgur.com/LZPbMwb.png)

Inspired by [pyglet](http://www.pyglet.org/).
## Features

@@ -24,5 +22,9 @@

* API for keyboard and mouse input.
* Bootstraps the resource loading process and optionally provides a basic
loading progress bar.
## Featured Game Demos
[![Face the Music](https://s3.amazonaws.com/superjoe/blog-files/face-the-music-title-small.png)](http://s3.amazonaws.com/superjoe/temp/face-the-music/index.html "Rock your way out of being trampled by a mob of screaming fans. This game was made in 48 hours.")
[![Purgatory: Lost Doorways](https://s3.amazonaws.com/superjoe/blog-files/purgatory-title-small.png)](http://s3.amazonaws.com/superjoe/temp/purgatory/index.html "Escape from the circles of hell. This game was made in 7 hours.")
[![Pillagers!](https://s3.amazonaws.com/superjoe/blog-files/pillagers-title-small.png)](http://s3.amazonaws.com/superjoe/temp/pillagers/index.html "Real-time strategy game with space physics. This game was made in 7 days.")
## Usage

@@ -32,2 +34,3 @@

# install dependencies in ubuntu
# for other OSes see https://github.com/LearnBoost/node-canvas/wiki/
sudo apt-get install libcairo2-dev

@@ -39,2 +42,7 @@

# use npm init to create a package.json file so that we can install
# dependencies locally instead of globally.
# feel free to mash enter through the series of questions.
npm init
# init the project with chem-cli

@@ -46,3 +54,2 @@ npm install chem-cli

# recompile your code, generate your spritesheets, and serve your assets.
# after running `init` above, simply:
npm run dev

@@ -178,12 +185,15 @@

## Demo Projects Using Chem
## More Demo Projects Using Chem
* [Pillagers](https://github.com/superjoe30/pillagers) - real time strategy with space physics
* [Meteor Attack](https://github.com/superjoe30/meteor-attack) - dodge meteors in space
* [Disinfecticide](https://github.com/superjoe30/disinfecticide) - use extreme measures to control a deadly disease outbreak.
* [Lemming](https://s3.amazonaws.com/superjoe/temp/lemming/index.html) -
Use your own dead bodies to beat side-scrolling platformer levels.
Made in 7 days.
* [Meteor Attack](https://github.com/superjoe30/meteor-attack) -
dodge meteors in space
* [Disinfecticide](https://github.com/superjoe30/disinfecticide) -
use extreme measures to control a deadly disease outbreak.
* [holocaust](https://github.com/superjoe30/holocaust/) -
rebuild society after a nuclear holocaust ravages the world
* [Dr. Chemical's Lab](https://github.com/superjoe30/dr-chemicals-lab/tree/master/javascript) -
PyWeek #14 entry, ported to chem
* [vapor](https://github.com/thejoshwolfe/vapor) - vaporware game. Not cool yet.
puzzle game that should have been an action game.

@@ -284,11 +294,1 @@ ## Developing With Chem

## Developing chem
See also [chem-cli](http://github.com/superjoe30/chem-cli)
```bash
# set up dev environment for chem itself:
sudo apt-get install libcairo2-dev
sudo npm link
```
SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc