Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: blixt/js-starbound-world
base: 9768f54747
...
head fork: blixt/js-starbound-world
compare: d97025da46
Checking mergeability… Don't worry, you can still create the pull request.
  • 2 commits
  • 3 files changed
  • 0 commit comments
  • 1 contributor
Commits on Mar 02, 2014
Blixt Measure calls fad7b47
Blixt Preliminary object rendering d97025d
Showing with 82 additions and 6 deletions.
  1. +80 −4 lib/regionrenderer.js
  2. +1 −1  lib/worldmanager.js
  3. +1 −1  package.json
View
84 lib/regionrenderer.js
@@ -21,6 +21,50 @@ function getInt16(region, offset) {
if (region && region.view) return region.view.getInt16(offset);
}
+function getOrientation(orientations, index) {
+ var curIndex = 0, image, direction;
+
+ // This is a tremendous amount of logic for deciding which image to use...
+ for (var i = 0; i < orientations.length; i++) {
+ var o = orientations[i];
+ if (curIndex == index) {
+ if (o.imageLayers) {
+ // TODO: Support multiple layers.
+ image = o.imageLayers[0].image;
+ } else {
+ image = o.image || o.leftImage || o.dualImage;
+ }
+ direction = o.direction || 'left';
+ if (!image) throw new Error('Could not get image for orientation');
+ break;
+ }
+
+ curIndex++;
+
+ if (o.dualImage || o.rightImage) {
+ if (curIndex == index) {
+ image = o.rightImage || o.dualImage;
+ direction = 'right';
+ break;
+ }
+
+ curIndex++;
+ }
+ }
+
+ if (!image) {
+ console.error(index, orientations);
+ throw new Error('Could not get orientation');
+ }
+
+ return {
+ image: image,
+ direction: direction,
+ flip: o.flipImages || !!(o.dualImage && direction == 'left'),
+ info: o
+ };
+}
+
function getUint8(region, offset) {
if (region && region.view) return region.view.getUint8(offset);
}
@@ -143,12 +187,44 @@ RegionRenderer.prototype._renderNPC = function (renderer, entity) {
RegionRenderer.prototype._renderObject = function (renderer, entity) {
var objects = renderer.objects.index;
- if (!objects) {
- this.dirty = true;
- return;
+ if (!objects) return;
+
+ var assets = renderer.assets;
+ var def = objects[entity.name];
+
+ if (def.animation) {
+ var animationPath = assets.getResourcePath(def, def.animation);
+ // TODO: assets.getAnimation(animationPath);
}
- // TODO: Render object.
+ var orientation = getOrientation(def.orientations, entity.orientationIndex);
+
+ var pathAndFrame = orientation.image.split(':');
+ var imagePath = assets.getResourcePath(def, pathAndFrame[0]);
+ var frames = assets.getFrames(imagePath);
+
+ // Flip all the frames horizontally if the sprite is using a dual image.
+ if (orientation.flip) {
+ if (!frames) return;
+ imagePath += '?flipgridx=' + frames.frameGrid.size[0];
+ }
+
+ var image = assets.getImage(imagePath);
+ if (!frames || !image) return;
+
+ // TODO: Get the correct frame in the frame grid.
+
+ var sprite = {
+ image: image,
+ x: entity.tilePosition[0] + orientation.info.imagePosition[0] / TILE_WIDTH,
+ y: entity.tilePosition[1] + orientation.info.imagePosition[1] / TILE_HEIGHT,
+ sx: 0,
+ sy: 0,
+ width: frames.frameGrid.size[0],
+ height: frames.frameGrid.size[1]
+ };
+
+ return [sprite];
};
RegionRenderer.prototype._renderPlant = function (renderer, entity) {
View
2  lib/worldmanager.js
@@ -20,7 +20,7 @@ function WorldManager(opt_options) {
this.metadata = null;
var worker = new Worker(options.workerPath);
- this.api = workerproxy(worker);
+ this.api = workerproxy(worker, {timeCalls: true});
}
util.inherits(WorldManager, EventEmitter);
View
2  package.json
@@ -15,7 +15,7 @@
"dependencies": {
"merge": "~1.1.2",
"starbound-files": "~0.7.0",
- "workerproxy": "~0.1.3"
+ "workerproxy": "~0.1.5"
},
"peerDependencies": {
"starbound-assets": "~0.7.0"

No commit comments for this range

Something went wrong with that request. Please try again.