Commits

Greg Taylor committed 6116df5

Got a test unit rendering.

Comments (0)

Files changed (9)

assets/raw/units/Anubis.gif

Added
New image

lib/src/map_widget/map_container.dart

 
   ResourceManager resourceManager;
   Stage stage;
+  UnitStore unitStore;
 
   HexMapKeyboardInputHandler keyboardInputHandler;
   HexMapMouseInputHandler mouseInputHandler;
   TerrainLayerSprite terrainLayer;
+  UnitLayerSprite unitLayer;
   HexMapDataManager dataManager;
 
-  MapContainer(Stage this.stage) {
+  MapContainer(Stage this.stage, UnitStore this.unitStore) {
     // Retrieves and sets the hexElevations/hexTerrain and other instance
     // attribs that rely on remote data.
     dataManager = new HexMapDataManager(this);
     // Renders and manages the terrain layer.
     terrainLayer = new TerrainLayerSprite(this);
+    // Renders and manages units on the map.
+    unitLayer = new UnitLayerSprite(this, unitStore);
   }
 
   /**
         y = pivotY = stage.contentRectangle.height / 2.0;
         keyboardInputHandler = new HexMapKeyboardInputHandler(this);
         mouseInputHandler = new HexMapMouseInputHandler(this);
+        unitLayer.renderTestUnit();
         completer.complete();
       });
 
   async.Future _loadResourceManager() {
     resourceManager = new ResourceManager()
       ..addTextureAtlas(
-          'hexTextures', 'img/hex_textures.json', TextureAtlasFormat.JSONARRAY);
+          'hexTextures', 'img/hex_textures.json', TextureAtlasFormat.JSONARRAY)
+      ..addTextureAtlas(
+          'unitTextures', 'img/unit_textures.json', TextureAtlasFormat.JSONARRAY);
     return resourceManager.load();
   }
 

lib/src/map_widget/map_widget.dart

 import 'dart:convert' as convert;
 import 'package:stagexl/stagexl.dart';
 import "package:hexmap/src/javelin/javelin.dart";
+import "package:hexmap/src/unit_store/unit_store.dart";
 
 part 'map_container.dart';
 part 'input_handling.dart';
 part 'terrain_layer.dart';
-part 'data_manager.dart';
+part 'data_manager.dart';
+part 'unit_layer.dart';

lib/src/map_widget/unit_layer.dart

+part of map_widget;
+
+class UnitLayerSprite extends Sprite {
+  MapContainer mapContainer;
+  TextureAtlas _textureAtlas;
+  UnitStore unitStore;
+
+  UnitLayerSprite(MapContainer this.mapContainer, UnitStore this.unitStore) {
+    x = 0.0;
+    y = 0.0;
+    this.addTo(mapContainer);
+  }
+
+  void renderTestUnit() {
+    _textureAtlas = mapContainer.resourceManager.getTextureAtlas('unitTextures');
+    var bitmapData = _textureAtlas.getBitmapData('Anubis');
+    var bitmap = new Bitmap(bitmapData)
+    ..x = 0.0
+    ..y = 0.0
+    // Adds the hex to the region Sprite.
+    ..addTo(this);
+  }
+}

lib/src/unit_store/bs_client.dart

     "http://hexmap.com/unit/events/detected": {
       'handler': BSClientPubSubHandler.handleUnitDetected,
     },
-    "http://hexmap.com/unit/events/destroyedd": {
+    "http://hexmap.com/unit/events/destroyed": {
       'handler': BSClientPubSubHandler.handleUnitDestroyed,
     },
     "http://hexmap.com/unit/events/stale-removal": {
   var socket = new html.WebSocket('ws://127.0.0.1:9000', ["wamp"]);
   var client = new BattleSnakeClient(socket, unitStore);
 
-  MapContainer mapContainer = new MapContainer(stage);
+  MapContainer mapContainer = new MapContainer(stage, unitStore);
   mapContainer.setup()
     .then((resourceManager) {
       stage.addChild(mapContainer);

web/img/unit_textures.json

+{"frames": [
+
+{
+	"filename": "Anubis",
+	"frame": {"x":2,"y":2,"w":84,"h":72},
+	"rotated": false,
+	"trimmed": false,
+	"spriteSourceSize": {"x":0,"y":0,"w":84,"h":72},
+	"sourceSize": {"w":84,"h":72}
+}],
+"meta": {
+	"app": "http://www.codeandweb.com/texturepacker ",
+	"version": "1.0",
+	"image": "unit_textures.png",
+	"format": "RGBA8888",
+	"size": {"w":128,"h":128},
+	"scale": "1",
+	"smartupdate": "$TexturePacker:SmartUpdate:14efb9f6acc2d23ef02ad9ad1985b3f0:83b2daf7d1939087fba9b283546a2e14:c4f5c692408455beadb5cfcba4b95211$"
+}
+}

web/img/unit_textures.png

Added
New image

web/img/unit_textures.tps

+<?xml version="1.0" encoding="UTF-8"?>
+<data version="1.0">
+    <struct type="Settings">
+        <key>fileFormatVersion</key>
+        <int>3</int>
+        <key>texturePackerVersion</key>
+        <string>3.2.1</string>
+        <key>autoSDSettings</key>
+        <array>
+            <struct type="AutoSDSettings">
+                <key>scale</key>
+                <double>1</double>
+                <key>extension</key>
+                <string></string>
+                <key>spriteFilter</key>
+                <string></string>
+                <key>acceptFractionalValues</key>
+                <false/>
+                <key>maxTextureSize</key>
+                <QSize>
+                    <key>width</key>
+                    <int>-1</int>
+                    <key>height</key>
+                    <int>-1</int>
+                </QSize>
+            </struct>
+        </array>
+        <key>allowRotation</key>
+        <true/>
+        <key>premultiplyAlpha</key>
+        <false/>
+        <key>shapeDebug</key>
+        <false/>
+        <key>dpi</key>
+        <uint>72</uint>
+        <key>dataFormat</key>
+        <string>json-array</string>
+        <key>textureFileName</key>
+        <filename>unit_textures.png</filename>
+        <key>flipPVR</key>
+        <false/>
+        <key>ditherType</key>
+        <enum type="SettingsBase::DitherType">NearestNeighbour</enum>
+        <key>backgroundColor</key>
+        <uint>0</uint>
+        <key>libGdx</key>
+        <struct type="LibGDX">
+            <key>filtering</key>
+            <struct type="LibGDXFiltering">
+                <key>x</key>
+                <enum type="LibGDXFiltering::Filtering">Linear</enum>
+                <key>y</key>
+                <enum type="LibGDXFiltering::Filtering">Linear</enum>
+            </struct>
+        </struct>
+        <key>shapePadding</key>
+        <uint>2</uint>
+        <key>jpgQuality</key>
+        <uint>80</uint>
+        <key>pngOptimizationLevel</key>
+        <uint>0</uint>
+        <key>textureSubPath</key>
+        <string></string>
+        <key>textureFormat</key>
+        <enum type="SettingsBase::TextureFormat">png</enum>
+        <key>borderPadding</key>
+        <uint>2</uint>
+        <key>maxTextureSize</key>
+        <QSize>
+            <key>width</key>
+            <int>2048</int>
+            <key>height</key>
+            <int>2048</int>
+        </QSize>
+        <key>fixedTextureSize</key>
+        <QSize>
+            <key>width</key>
+            <int>-1</int>
+            <key>height</key>
+            <int>-1</int>
+        </QSize>
+        <key>reduceBorderArtifacts</key>
+        <false/>
+        <key>algorithmSettings</key>
+        <struct type="AlgorithmSettings">
+            <key>algorithm</key>
+            <enum type="AlgorithmSettings::AlgorithmId">Basic</enum>
+            <key>freeSizeMode</key>
+            <enum type="AlgorithmSettings::AlgorithmFreeSizeMode">Best</enum>
+            <key>sizeConstraints</key>
+            <enum type="AlgorithmSettings::SizeConstraints">POT</enum>
+            <key>forceSquared</key>
+            <false/>
+            <key>forceWordAligned</key>
+            <false/>
+            <key>maxRects</key>
+            <struct type="AlgorithmMaxRectsSettings">
+                <key>heuristic</key>
+                <enum type="AlgorithmMaxRectsSettings::Heuristic">Best</enum>
+            </struct>
+            <key>basic</key>
+            <struct type="AlgorithmBasicSettings">
+                <key>sortBy</key>
+                <enum type="AlgorithmBasicSettings::SortBy">Best</enum>
+                <key>order</key>
+                <enum type="AlgorithmBasicSettings::Order">Ascending</enum>
+            </struct>
+        </struct>
+        <key>andEngine</key>
+        <struct type="AndEngine">
+            <key>minFilter</key>
+            <enum type="AndEngine::MinFilter">Linear</enum>
+            <key>packageName</key>
+            <string>Texture</string>
+            <key>wrap</key>
+            <struct type="AndEngineWrap">
+                <key>s</key>
+                <enum type="AndEngineWrap::Wrap">Clamp</enum>
+                <key>t</key>
+                <enum type="AndEngineWrap::Wrap">Clamp</enum>
+            </struct>
+            <key>magFilter</key>
+            <enum type="AndEngine::MagFilter">MagLinear</enum>
+        </struct>
+        <key>dataFileNames</key>
+        <map type="GFileNameMap">
+            <key>data</key>
+            <struct type="DataFile">
+                <key>name</key>
+                <filename>unit_textures.json</filename>
+            </struct>
+        </map>
+        <key>multiPack</key>
+        <false/>
+        <key>forceIdenticalLayout</key>
+        <false/>
+        <key>outputFormat</key>
+        <enum type="SettingsBase::OutputFormat">RGBA8888</enum>
+        <key>contentProtection</key>
+        <struct type="ContentProtection">
+            <key>key</key>
+            <string></string>
+        </struct>
+        <key>autoAliasEnabled</key>
+        <true/>
+        <key>trimSpriteNames</key>
+        <true/>
+        <key>cleanTransparentPixels</key>
+        <true/>
+        <key>globalSpriteSettings</key>
+        <struct type="SpriteSettings">
+            <key>scale</key>
+            <double>1</double>
+            <key>scaleMode</key>
+            <enum type="ScaleMode">Smooth</enum>
+            <key>innerPadding</key>
+            <uint>0</uint>
+            <key>extrude</key>
+            <uint>0</uint>
+            <key>trimThreshold</key>
+            <uint>1</uint>
+            <key>trimMode</key>
+            <enum type="SpriteSettings::TrimMode">None</enum>
+            <key>heuristicMask</key>
+            <false/>
+        </struct>
+        <key>fileList</key>
+        <array>
+            <filename>../../assets/raw/units/Anubis.gif</filename>
+        </array>
+        <key>ignoreFileList</key>
+        <array/>
+        <key>replaceList</key>
+        <array/>
+        <key>ignoredWarnings</key>
+        <array/>
+        <key>commonDivisorX</key>
+        <uint>1</uint>
+        <key>commonDivisorY</key>
+        <uint>1</uint>
+    </struct>
+</data>