Permalink
Browse files

Some terminlogy changes, mostly 'tile' => 'slice', to differentiate m…

…eanings
  • Loading branch information...
1 parent ef8a023 commit 1d7b0217a494251e007b9fad35a250875781978f @ELLIOTTCABLE committed Oct 28, 2008
View
@@ -39,89 +39,89 @@ function writeMap(map) {
var xTranslate;
var yTranslate;
- var rows = map.length;
- for (var row = rows - 1; row >= 0; row--) {
+ var numRows = map.length;
+ for (var rowId = numRows - 1; rowId >= 0; rowId--) {
- var yTranslate = -(-( parseFloat(rows) / 2 ) + parseFloat(row) + 1);
- var cols = map[row].length;
- for (var col = cols - 1; col >= 0; col--) {
-
- var xTranslate = -(-( parseFloat(cols) / 2 ) + parseFloat(col) + 1);
- var tiles = map[row][col].length;
- for (var tile = tiles - 1; tile >= 0; tile--) {
- console.group('writing tile '+map[row][col][tile]+' at '+xTranslate+', '+yTranslate);
- addTile(map[row][col][tile], xTranslate, yTranslate);
+ var yTranslate = -(-( parseFloat(numRows) / 2 ) + parseFloat(rowId) + 1);
+ var numTiles = map[rowId].length;
+ for (var tileId = numTiles - 1; tileId >= 0; tileId--) {
+
+ var xTranslate = -(-( parseFloat(numTiles) / 2 ) + parseFloat(tileId) + 1);
+ var numSlices = map[rowId][tileId].length;
+ for (var sliceId = numSlices - 1; sliceId >= 0; sliceId--) {
+ console.group('writing slice '+map[rowId][tileId][sliceId]+' at '+xTranslate+', '+yTranslate);
+ addSlice(map[rowId][tileId][sliceId], xTranslate, yTranslate);
console.groupEnd();
};
};
};
console.groupEnd();
}
-// Adds a new tile to the grid. Gets the tile from the server, and prints
+// Adds a new slice to the grid. Gets the slice from the server, and prints
// anything necessary to display it to the page.
-function addTile(id, x, y) {
- var tileId = parseInt(id)
+function addSlice(sliceId_opt, x, y) {
+ var sliceId = parseInt(sliceId_opt)
- queueHookForTile(tileId, function(tile){
+ queueHookForSlice(sliceId, function(slice){
var gNode = gridNode(x, y);
- addSVGClass(gNode, tile['name']);
- writeSVG( unescape(tile['svg']), gNode );
+ addSVGClass(gNode, slice['name']);
+ writeSVG( unescape(slice['svg']), gNode );
});
}
-// Once loaded, all a tile's hook queue entries will be run, and any hook
+// Once loaded, all a slice's hook queue entries will be run, and any hook
// passed to this after that point will be run directly. The first hook passed
-// to this causes the tile to be requested for loading.
+// to this causes the slice to be requested for loading.
//
-// Returnes the tile if it's already cached, true if it's already been queued,
+// Returnes the slice if it's already cached, true if it's already been queued,
// and false if this is the first time it's been requested.
// TODO: Figure out why this particular function runs so slow!
-var queuedTiles = new Array();
-function queueHookForTile(id, hook) {
- var tileId = parseInt(id)
- // If we've already got the tile, just run the hook on it now.
- var cachedTile = cachedTiles[tileId];
- if(cachedTile != 'undefined' && cachedTile != null) {
- hook(cachedTile);
- return cachedTile;
+var queuedSlices = new Array();
+var cachedSlices = new Array();
+function queueHookForSlice(sliceId_opt, hook) {
+ var sliceId = parseInt(sliceId_opt)
+ // If we've already got the slice, just run the hook on it now.
+ var cachedSlice = cachedSlices[sliceId];
+ if(cachedSlice != 'undefined' && cachedSlice != null) {
+ hook(cachedSlice);
+ return cachedSlice;
}
// If it's not retreived yet, but it's been queued, add our hook to the
// queue
- var tileQueue = queuedTiles[tileId];
- if(tileQueue != 'undefined' && tileQueue != null) {
- tileQueue.push(hook);
+ var sliceQueue = queuedSlices[sliceId];
+ if(sliceQueue != 'undefined' && sliceQueue != null) {
+ sliceQueue.push(hook);
return true;
}
// If it's not been queued, we'll queue it now, and actually request the
- // tile.
- queuedTiles[tileId] = new Array();
- queuedTiles[tileId].push(hook);
- retrieveTile( tileId, function(tile) {
- runHooksForTile(tileId, tile);
+ // slice.
+ queuedSlices[sliceId] = new Array();
+ queuedSlices[sliceId].push(hook);
+ retrieveSlice( sliceId, function(slice) {
+ runHooksForSlice(sliceId, slice);
});
return false;
}
-function runHooksForTile(tileId, tile) {
- for (var i = queuedTiles[tileId].length - 1; i >= 0; i--){
- queuedTiles[tileId][i](tile);
+function runHooksForSlice(sliceId, slice) {
+ for (var i = queuedSlices[sliceId].length - 1; i >= 0; i--){
+ queuedSlices[sliceId][i](slice);
};
}
-// This will retrieve a tile as JSON, caching all previously requested
-// tiles to save JHR requests. Due to the async nature of XHR and thus
-// JHR, we can't return the tile itself - you have to pass a function
-// to retrieveTile() documenting how you want to deal with the tile.
-var cachedTiles = new Array();
-function retrieveTile(id, onRetrieve) {
- JSONHttpRequest(API_URI + '/tile/' + id, function(tile) {
- cachedTiles[ parseInt(tile['id']) ] = tile;
- if(tile['css']){ writeCSS( unescape(tile['css']) ) };
- onRetrieve(tile);
+// This will retrieve a slice as JSON, caching all previously requested
+// slices to save JHR requests. Due to the async nature of XHR and thus
+// JHR, we can't return the slice itself - you have to pass a function
+// to retrieveSlice() documenting how you want to deal with the slice.
+function retrieveSlice(id, onRetrieve) {
+ JSONHttpRequest(API_URI + '/slice/' + id, function(slice) {
+ cachedSlices[ parseInt(slice['id']) ] = slice;
+ if(slice['css']){ writeCSS( unescape(slice['css']) ) };
+ onRetrieve(slice);
});
}
@@ -140,7 +140,7 @@ function writeSVG(svgSource, parentNode) {
}
// Returns the <g> object representing one 'grid tile', so actual graphical
-// tiles can be added to it. Creates said tile if necessary.
+// slices can be added to it. Creates said tile if necessary.
function gridNode(x, y) {
var gNode = findGridNode(x, y);
if(!gNode) {
File renamed without changes.
File renamed without changes.
@@ -1,16 +1,16 @@
class Api < Halcyon::Controller
- def tile
+ def slice
unless params[:id].nil?
- return not_found unless tile = Tile[params[:id].to_i]
- ok tile.to_h
+ return not_found unless slice = Slice[params[:id].to_i]
+ ok slice.to_h
else
not_found
end
end
# Maps are three dismensional, literally - however, the Z dimensional array
- # is just an array of tiles that are 'stacked', i.e., rendered in the same
+ # is just an array of slices that are 'stacked', i.e., rendered in the same
# position (given by the position in the two parent arrays).
def map
unless params[:id].nil?
@@ -5,20 +5,20 @@ def self.[] id
Maps[id]
end
- attr_accessor :tiles
+ attr_accessor :slices
- def initialize tiles = [[]], opts = {}
- @tiles = opts[:tiles] || tiles
+ def initialize slices = [[]], opts = {}
+ @slices = opts[:slices] || slices
yield self if block_given?
Maps << self
end
- alias_method :to_a, :tiles
+ alias_method :to_a, :slices
end
-Map.new [[0, 0], [0, 0]] # Map of ID 0 should always be an empty 2x2 map of 'null' tiles.
+Map.new [[0, 0], [0, 0]] # Map of ID 0 should always be an empty 2x2 map of 'null' slices.
Map.new( Array.new(10){|| Array.new(10, [1]) } ) # Empty test map, 10x10
Map.new( Array.new(10){|| Array.new(10, [2]) } ) # Empty grass map, 10x10
Map.new( Array.new(25){|| Array.new(25, [2]) } ) # Empty grass map, 25x25
@@ -1,15 +1,15 @@
-class Tile
- TileBackground = "<rect x='0' y='0' width='100' height='100' class='background'/>"
+class Slice
+ SliceBackground = "<rect x='0' y='0' width='100' height='100' class='background'/>"
- Tiles = []
+ Slices = []
def self.[] id
# if id.respond_to? :to_int # Symbols respond to to_int. WTF!
if id.is_a? Numeric
- Tiles[id]
+ Slices[id]
# elsif id.respond_to? :to_str # Unfortunately, Symbol being stupid again.
elsif id.respond_to? :to_s
- Tiles.select{|i| i.name == id }.first
+ Slices.select{|i| i.name == id }.first
else
nil
end
@@ -49,27 +49,27 @@ def svg= svg
def initialize name, opts = {}
@name = name
self.css = opts[:css] || nil
- self.svg = opts[:svg] || TileBackground
+ self.svg = opts[:svg] || SliceBackground
yield self if block_given?
- Tiles << self
+ Slices << self
end
def to_h
{
- :id => Tiles.index(self),
+ :id => Slices.index(self),
:name => @name,
:css => @css,
:svg => @svg
}
end
end
-Tile.new :null # Tile of ID 0 should always be an empty tile named 'null'
-Tile.new :test do |tile|
- tile.css = ".background { fill: #FF0000; } .background:hover { fill: #00FF00; }"
+Slice.new :null # Slice of ID 0 should always be an empty slice named 'null'
+Slice.new :test do |slice|
+ slice.css = ".background { fill: #FF0000; } .background:hover { fill: #00FF00; }"
end
-Tile.new :grass do |tile|
- tile.css = ".background { fill: #009900; }"
+Slice.new :grass do |slice|
+ slice.css = ".background { fill: #009900; }"
end
@@ -1,6 +1,6 @@
%w[rubygems halcyon hpricot css_parser].each {|dep| require dep }
-require 'lib/tile'
+require 'lib/slice'
require 'lib/map'
require 'app/config'

0 comments on commit 1d7b021

Please sign in to comment.