Skip to content

Commit

Permalink
Readme updated
Browse files Browse the repository at this point in the history
  • Loading branch information
robashton committed Mar 27, 2012
1 parent 1a86a2e commit de6a588
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 11 deletions.
75 changes: 65 additions & 10 deletions README.md
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Swallow is an asset packager for facilliating the loading process in browser bas


- You have a large number of assets (textures, sounds, models, shaders) which are needed for the game to run - You have a large number of assets (textures, sounds, models, shaders) which are needed for the game to run
- You want to know when they're all loaded so the game can start - You want to know when they're all loaded so the game can start
- Doing 500 HTTP requests on start-up seems a bit excessive
- You don't want to load most things on demand, but working out what you need is a bit of a bother - You don't want to load most things on demand, but working out what you need is a bit of a bother
- You want to package all of those assets into single deployable files as JSON and load them out the other side without changing too much code - You want to package all of those assets into single deployable files as JSON and load them out the other side without changing too much code
- You want to be able to create a package which can be played offline - You want to be able to create a package which can be played offline
Expand Down Expand Up @@ -36,21 +37,75 @@ Given a directory of assets, and an appropriate structure within:
- etc - etc
``` ```


And a command as follows And some code like so:


swallow -i ./assets


A file (assets.json) will be generated containing all the data in the specified directory. ```
swallow.build({
in: './assets',
out: './assets.json'
});
```

A file (assets.json) will be generated containing all the data in the specified directory.

This can be downloaded and consumed in one go like thus:

```
$.getJSON('/assets.json', function(data) {
var audioData = data['assets/sound/explosion.wav'];
var audio = new Audio();
audio.href = "data:image/png;base64," + audioData;
// etc
});
```


Roadmap You'll more likely want to enumerate the package when it is down and pre-load the assets, there is code on the way to do that as it needs extracting from the project that this library was pulled from in the first place.

Adding extensions
----- -----


- Dependencies between assets There are some convenience methods supplied to help with this process, the following will suffice for most scenarios:
- per-level/world-area/ asset file generation (taking into account the dependencies)
- pluggable handlers on the server side for generating output / specifying additional dependencies ```
- client code for loading assets (promises and asynchronous load notifications) var swallow = require('swallow'),
handlers = swallow.handlers;
swallow.build({
in: './in/assets',
out: './out/assets.json',
extraHandlers: [
handlers.byExtension('.shader', handlers.text),
handlers.byExtension('.model', handlers.json),
handlers.byExtension('.crazy', handlers.binary)
]
});
```

In the above example, we use the built in handlers, which match by file extension and can deal with the obvious content types.

A handler is just an object with two methods,

```
valid: function(filename, callback) {
callback(true);
}
```

Given a filename, the callback should be invoked with either 'true' or 'false' depending on whether the handler is valid for the file passed in.


```
handle: function(filename, callback) {
callback(err, data);
}
```

Given a filename, callback should be involved with something that is serializable into JSON, or an error if one occurs.


Scope
----- -----


Probably the above, try looking at the other libraries I run for other functionalities. - Dependencies between assets
- per-level/world-area/ asset file generation (taking into account the dependencies)
- client code for loading assets (already written, needs extracting from project)
- transparent client code for loading assets from either file or server if not in file
1 change: 0 additions & 1 deletion src/handlers.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -38,4 +38,3 @@ module.exports = (function(require) {
}; };
}).call(this, require); }).call(this, require);



0 comments on commit de6a588

Please sign in to comment.