Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Readme updated

  • Loading branch information...
commit de6a5882ecfea5416bfe1b39038a812f100a34e6 1 parent 1a86a2e
@robashton authored
Showing with 65 additions and 11 deletions.
  1. +65 −10 README.md
  2. +0 −1  src/handlers.js
View
75 README.md
@@ -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 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 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
@@ -36,21 +37,75 @@ Given a directory of assets, and an appropriate structure within:
- 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
-- 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)
+There are some convenience methods supplied to help with this process, the following will suffice for most scenarios:
+
+```
+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
View
1  src/handlers.js
@@ -38,4 +38,3 @@ module.exports = (function(require) {
};
}).call(this, require);
-
Please sign in to comment.
Something went wrong with that request. Please try again.