Skip to content

Commit cbe6628

Browse files
committed
Add native unit comparison/sorting.
1 parent 0205722 commit cbe6628

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

sc2reader/data/__init__.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,15 +269,28 @@ def __init__(self, build_id, units, abilities):
269269

270270
class Unit(object):
271271
name = 'Unknown Unit'
272+
type = 0
272273

273274
def __init__(self, unit_id, flags):
274275
self.id = unit_id
275276
self.flags = flags
276277
self.hallucinated = (flags & 2 == 2)
278+
self._cmp_val = (self.id << 16) | self.type
277279

278280
def __str__(self):
279281
return "{} [{:X}]".format(self.name, self.id)
280282

283+
def __cmp__(self, other):
284+
if self._cmp_val == other._cmp_val:
285+
return 0
286+
elif self._cmp_val > other._cmp_val:
287+
return 1
288+
else:
289+
return -1
290+
291+
def __hash__(self):
292+
return hash(self._cmp_val)
293+
281294
def __repr__(self):
282295
return str(self)
283296

0 commit comments

Comments
 (0)