Permalink
Browse files

Correctly render potential move on stacked locations

  • Loading branch information...
1 parent 14db86e commit c049602ff448e5a06b446c179bbb46a3a5fdbe8a @chellmuth committed Jan 12, 2014
Showing with 19 additions and 7 deletions.
  1. +15 −6 lib/view.dart
  2. +4 −1 web/hive.dart
View
@@ -1,20 +1,24 @@
library view;
import 'dart:html';
-import 'dart:math' show PI;
+import 'dart:math' show PI, max;
import 'assets.dart';
import 'gamemodel.dart';
import 'gamestate.dart';
part 'bench.dart';
+
abstract class HexView {
static final num width = 80 * 2;
static final num height = 90 * 2;
static final num pointHeight = .25;
+ static final num xStackOffset = 6;
+ static final num yStackOffset = 10;
+
int get row;
int get col;
int get stackHeight => 1;
@@ -24,12 +28,17 @@ abstract class HexView {
num get xOffset {
var xOffset = col * width;
if (row % 2 == 1) { xOffset += .5 * width; }
+
+ xOffset += (stackHeight - 1) * xStackOffset;
+
xOffset += 1;
return xOffset;
}
num get yOffset {
var yOffset = row * height * .75;
+ yOffset -= (stackHeight - 1) * yStackOffset;
+
yOffset += 1;
return yOffset;
}
@@ -54,7 +63,11 @@ abstract class HexView {
class MoveView extends HexView {
Coordinate location;
- MoveView(this.location);
+ int stackHeight;
+ MoveView(this.location, stackHeight) {
+ print(stackHeight);
+ this.stackHeight = max(1, stackHeight);
+ }
int get row => location.row;
int get col => location.col;
@@ -82,10 +95,6 @@ class TileView extends HexView {
context.save();
- var xStackOffset = 6, yStackOffset = 10;
- var xOffset = this.xOffset + (tile.height - 1) * xStackOffset;
- var yOffset = this.yOffset - (tile.height - 1) * yStackOffset;
-
ImageElement asset = AssetLibrary.imageForPiece(tile.piece);
context.drawImageScaledFromSource(asset, 0, 0, asset.naturalWidth, asset.naturalHeight, xOffset - 6, yOffset - 4, asset.naturalWidth, asset.naturalHeight);
View
@@ -188,7 +188,10 @@ void render(GameState gamestate, { List<Move> moves : null }) {
List<TileView> tileViews = gamestate.toList().map((tile) => new TileView(tile, gamestate.piecesCoveredByTile(tile))).toList();
if (moves == null) { moves = []; }
- List<MoveView> moveViews = moves.map((move) => new MoveView(move.targetLocation)).toList();
+ List<MoveView> moveViews = moves.map((move) => new MoveView(
+ move.targetLocation,
+ gamestate.stackAt(move.targetLocation).length)
+ ).toList();
List<HexView> hexViews = [];
hexViews.addAll(tileViews);

0 comments on commit c049602

Please sign in to comment.