NBT: TAG_List now accepts item assignment using slices.
e.g. `list_tag[:] = [nbt.TAG_Double(3), nbt.TAG_Double(5)]` Also, changed the names of a few method args to be more consistent between implementations.
This commit is contained in:
parent
30cfb1d380
commit
3e4a9b8ef6
22
_nbt.pyx
22
_nbt.pyx
@ -273,12 +273,16 @@ cdef class _TAG_List(TAG_Value):
|
|||||||
raise TypeError("Invalid type %s for TAG_List(%s)" % (value.__class__, tag_classes[self.list_type]))
|
raise TypeError("Invalid type %s for TAG_List(%s)" % (value.__class__, tag_classes[self.list_type]))
|
||||||
|
|
||||||
# --- collection methods ---
|
# --- collection methods ---
|
||||||
def __getitem__(self, key):
|
def __getitem__(self, index):
|
||||||
return self.value[key]
|
return self.value[index]
|
||||||
|
|
||||||
def __setitem__(self, key, val):
|
def __setitem__(self, index, value):
|
||||||
self.check_tag(val)
|
if isinstance(index, slice):
|
||||||
self.value[key] = val
|
for tag in value:
|
||||||
|
self.check_tag(tag)
|
||||||
|
else:
|
||||||
|
self.check_tag(value)
|
||||||
|
self.value[index] = value
|
||||||
|
|
||||||
def __iter__(self):
|
def __iter__(self):
|
||||||
return iter(self.value)
|
return iter(self.value)
|
||||||
@ -286,13 +290,13 @@ cdef class _TAG_List(TAG_Value):
|
|||||||
def __len__(self):
|
def __len__(self):
|
||||||
return len(self.value)
|
return len(self.value)
|
||||||
|
|
||||||
def insert(self, idx, val):
|
def insert(self, index, tag):
|
||||||
if len(self.value) == 0:
|
if len(self.value) == 0:
|
||||||
self.list_type = val.tagID
|
self.list_type = tag.tagID
|
||||||
else:
|
else:
|
||||||
self.check_tag(val)
|
self.check_tag(tag)
|
||||||
|
|
||||||
self.value.insert(idx, val)
|
self.value.insert(index, tag)
|
||||||
|
|
||||||
def __delitem__(self, key):
|
def __delitem__(self, key):
|
||||||
del self.value[key]
|
del self.value[key]
|
||||||
|
18
nbt.py
18
nbt.py
@ -456,22 +456,26 @@ class TAG_List(TAG_Value, collections.MutableSequence):
|
|||||||
def __iter__(self):
|
def __iter__(self):
|
||||||
return iter(self.value)
|
return iter(self.value)
|
||||||
|
|
||||||
def __contains__(self, key):
|
def __contains__(self, tag):
|
||||||
return key in self.value
|
return tag in self.value
|
||||||
|
|
||||||
def __getitem__(self, i):
|
def __getitem__(self, index):
|
||||||
return self.value[i]
|
return self.value[index]
|
||||||
|
|
||||||
def __len__(self):
|
def __len__(self):
|
||||||
return len(self.value)
|
return len(self.value)
|
||||||
|
|
||||||
def __setitem__(self, index, value):
|
def __setitem__(self, index, value):
|
||||||
|
if isinstance(index, slice):
|
||||||
|
for tag in value:
|
||||||
|
self.check_tag(tag)
|
||||||
|
else:
|
||||||
self.check_tag(value)
|
self.check_tag(value)
|
||||||
value.name = ""
|
|
||||||
self.value[index] = value
|
self.value[index] = value
|
||||||
|
|
||||||
def __delitem__(self, i):
|
def __delitem__(self, index):
|
||||||
del self.value[i]
|
del self.value[index]
|
||||||
|
|
||||||
def insert(self, index, value):
|
def insert(self, index, value):
|
||||||
if len(self) == 0:
|
if len(self) == 0:
|
||||||
|
Reference in New Issue
Block a user