WotLK M2 files parser
Project description
m2lk
WotLK M2 files parser
from m2lk import M2FileReader, M2, M2Skin
with M2FileReader(filename) as reader:
m2 = M2()
m2.load(reader)
with M2FileReader(skin_filename) as reader:
skin = M2Skin()
skin.load(reader)
And then m2
can be used as a structure.
M2Field
Feild's value can be obtained with value
property. For example:
m2.value
m2.name.value
The value is a JSON-srializable data.
M2ArrayField
M2ArrayField is a subclass of M2Field. Its item can be obtained by index. For example:
if len(m2.sequences) > 0:
sequence_0_field = m2.sequences[0] # M2Field instance
sequence_0_field.movespeed.value # float
M2Struct
M2Struct is a subclass of M2Field.
fields
property is a dict {field_name: field}
.
For example M2 structure fields can be obtained with list(m2.fields)
.
Structure field can be obtained by attribute: getattr(obj, field_name)
. For example:
sequences_field = m2.sequences # M2ArrayField
Structure field's value can be obtained by name: obj[field_name]
.
For example JSON-serializable value of sequences
field:
sequences_value = m2['sequences'] # The same as m2.sequences.value
Note: M2
and M2Skin
are subclasses of M2Struct
.
JSON
A m2 value can be saved to a json file:
import json
m2_json = json.dumps(m2.value)
And then loaded to a M2 structure:
m2 = M2()
m2.from_json(json.loads(m2_json))
The same is for M2Skin:
import json
skin_json = json.dumps(skin.value)
skin_new = M2Skin()
skin_new.from_json(json.loads(skin_json))
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.