Browse Source

Tidy up layout handling, fix new layout not working

master
Chris Smith 12 years ago
parent
commit
04e404e80c
1 changed files with 7 additions and 4 deletions
  1. 7
    4
      res/js/viewer.js

+ 7
- 4
res/js/viewer.js View File

@@ -1,5 +1,6 @@
1 1
 $(function() {
2 2
  var thisLevel;
3
+ var layout;
3 4
 
4 5
  function updateDefenseUnits() {
5 6
   var used = 0;
@@ -136,7 +137,9 @@ $(function() {
136 137
 
137 138
  function clearLayout() {
138 139
   $('#mapcontainer .tower').remove();
139
-  layout.towers = [];
140
+  if (layout) {
141
+   layout.towers = [];
142
+  }
140 143
  }
141 144
 
142 145
  $.each(levels, function(key) {
@@ -144,9 +147,7 @@ $(function() {
144 147
    .append($('<img>').attr('src', this.image))
145 148
    .append($('<p>').text(this.name))
146 149
    .click(function() {
147
-    clearLayout();
148
-    layout = {level: key + 1, towers:[]};
149
-    updateLayout();
150
+    updateLayout({level: key + 1, towers:[]});
150 151
     closePicker();
151 152
    })
152 153
    .appendTo($('#layoutpicker'));
@@ -164,6 +165,8 @@ $(function() {
164 165
  $('#layoutmask').click(closePicker);
165 166
 
166 167
  function updateLayout(data) {
168
+  clearLayout();
169
+
167 170
   layout = data;
168 171
   thisLevel = levels[layout.level - 1];
169 172
   $('#mapcontainer').css('background-image', 'url("' + thisLevel.minimap + '")');

Loading…
Cancel
Save