1. Greg Taylor
  2. hexmap

Commits

Greg Taylor  committed 82c1624

Prepping unit store.

  • Participants
  • Parent commits 31a1210
  • Branches master

Comments (0)

Files changed (6)

File lib/src/netcomm/netcomm.dart

  • Ignore whitespace
-library netcomm;
-
-import "package:hexmap/wamp_client/wamp_client.dart";
-
-class ChatClient extends WampClientProtocol {
-  ChatClient(socket) : super(socket);
-
-  onOpenSession() {
-    subscribe('http://hexmap.com/unit/events/detected');
-    subscribe('http://hexmap.com/unit/events/destroyed');
-    subscribe('http://hexmap.com/unit/events/stale-removal');
-    subscribe('http://hexmap.com/unit/events/hit-landed');
-    subscribe('http://hexmap.com/unit/events/shot-missed');
-    subscribe('http://hexmap.com/unit/events/state-changed');
-
-    call("http://hexmap.com/unit-store#get", [])
-      .then((response) => print("Response: ${response}"));
-  }
-
-  onEvent(topicUri, event) {
-    print("Event received");
-  }
-}
-

File lib/src/unit_store/bs_client.dart

View file
  • Ignore whitespace
+part of unit_store;
+
+
+class BattleSnakeClient extends WampClientProtocol {
+  UnitStore unitStore;
+
+  BattleSnakeClient(socket, UnitStore this.unitStore) : super(socket) {
+
+  }
+
+  onOpenSession() {
+    subscribe('http://hexmap.com/unit/events/detected');
+    subscribe('http://hexmap.com/unit/events/destroyed');
+    subscribe('http://hexmap.com/unit/events/stale-removal');
+    subscribe('http://hexmap.com/unit/events/hit-landed');
+    subscribe('http://hexmap.com/unit/events/shot-missed');
+    subscribe('http://hexmap.com/unit/events/state-changed');
+
+    call("http://hexmap.com/unit-store#get", [])
+      .then((response) => print("Response: ${response}"));
+  }
+
+  onEvent(topicUri, event) {
+    print("Event received");
+  }
+}
+

File lib/src/unit_store/store.dart

View file
  • Ignore whitespace
+part of unit_store;
+
+class UnitStore {
+  Map<String,Unit> _units;
+
+  UnitStore() {
+    _units = new Map<String,Unit>();
+  }
+}
+
+class Unit {
+
+}

File lib/src/unit_store/unit_store.dart

View file
  • Ignore whitespace
+library unit_store;
+
+import 'dart:html';
+import "package:hexmap/wamp_client/wamp_client.dart";
+
+part 'bs_client.dart';
+part 'store.dart';

File lib/wamp_client/wamp_client.dart

View file
  • Ignore whitespace
   Map<String, String> prefixes = new Map();
   Map<String, Completer> callCompleters = new Map();
 
-  WampClientProtocol(this._socket) {
+  WampClientProtocol(WebSocket this._socket) {
     _socket.onMessage.listen((e) => onMessage(JSON.decode(e.data)));
   }
 

File web/hexmap.dart

View file
  • Ignore whitespace
 import 'dart:html' as html;
 import 'dart:async' as async;
 import 'package:stagexl/stagexl.dart';
-import "package:hexmap/src/netcomm/netcomm.dart";
+import "package:hexmap/src/unit_store/unit_store.dart";
 import "package:hexmap/src/map_widget/map_widget.dart";
 
 html.Element stageElement = html.querySelector('#stage');
   RenderLoop renderLoop = new RenderLoop()
     ..addStage(stage);
 
+  UnitStore unitStore = new UnitStore();
   var socket = new html.WebSocket('ws://127.0.0.1:9000', ["wamp"]);
-  socket.onError.listen((error) => print("Error received: ${error.toString()}"));
-  socket.onMessage.listen((html.MessageEvent e) {
-    print('Received message: ${e.data}');
-  });
-  var client = new ChatClient(socket);
+  var client = new BattleSnakeClient(socket, unitStore);
 
   MapContainer mapContainer = new MapContainer(stage);
   mapContainer.setup()