|
1 | 1 | # -*- coding: utf-8 -*-
|
2 | 2 | from __future__ import absolute_import
|
3 | 3 |
|
| 4 | +from sc2reader.data import Unit |
4 | 5 | from sc2reader.events.base import Event
|
5 | 6 | from sc2reader.log_utils import loggable
|
6 | 7 |
|
@@ -174,21 +175,21 @@ def load_context(self, replay):
|
174 | 175 | if not replay.datapack:
|
175 | 176 | return
|
176 | 177 |
|
177 |
| - uid = (self.target_id, self.target_type) |
178 |
| - if uid in replay.objects: |
179 |
| - self.target = replay.objects[uid] |
| 178 | + if self.target_id in replay.objects: |
| 179 | + self.target = replay.objects[self.target_id] |
| 180 | + if not self.target.is_type(self.target_type): |
| 181 | + replay.datapack.change_type(self.target, self.target_type, self.frame) |
180 | 182 |
|
181 | 183 | else:
|
182 | 184 | if self.target_type not in replay.datapack.units:
|
183 | 185 | self.logger.error("{0}\t{1}\tMissing unit {2} from {3}".format(self.frame, self.player.name, hex(self.target_type), replay.datapack.id))
|
184 | 186 | unit = Unit(self.target_id, 0x00)
|
185 | 187 |
|
186 | 188 | else:
|
187 |
| - unit_class = replay.datapack.units[self.target_type] |
188 |
| - unit = unit_class(self.target_id, 0x00) |
| 189 | + unit = replay.datapack.create_unit(self.target_id, self.target_type, 0x00, self.frame) |
189 | 190 |
|
190 | 191 | self.target = unit
|
191 |
| - replay.objects[uid] = unit |
| 192 | + replay.objects[self.target_id] = unit |
192 | 193 |
|
193 | 194 | def __str__(self):
|
194 | 195 | if self.target:
|
|
0 commit comments