Skip to content

Commit

Permalink
convert: Load nyan API.
Browse files Browse the repository at this point in the history
  • Loading branch information
heinezen committed Sep 6, 2019
1 parent 94e9296 commit 3037668
Show file tree
Hide file tree
Showing 6 changed files with 203 additions and 62 deletions.
8 changes: 4 additions & 4 deletions doc/nyan/api_reference/reference_aux.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ Reference documentation of the `engine.aux` module of the openage modding API.

```python
Accuracy(Entity):
accuracy : float
accuracy_dispersion : float
dispersion_dropoff : DropOffType
target_types : set(GameEntityType)
accuracy : float
accuracy_dispersion : float
dispersion_dropoff : DropOffType
target_types : set(GameEntityType)
blacklisted_entities : set(GameEntity)
```

Expand Down
37 changes: 37 additions & 0 deletions openage/convert/nyan/api_loader.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Copyright 2019-2019 the openage authors. See copying.md for legal info.

"""
Loads the API into the converter.
TODO: Implement a parser instead of hardcoded
object creation.
"""

from ...nyan.nyan_structs import NyanObject, NyanMember


def load_api():
"""
Returns a dict with the API object's fqon as keys
and the API objects as values.
"""
api_objects = dict()

# Object creation

# engine.root
# engine.root.Entity
nyan_object = NyanObject("Entity")
fqon = "engine.root.Entity"
nyan_object.set_fqon(fqon)

api_objects.update({fqon: nyan_object})

# engine.aux
# engine.aux.accuracy.Accuracy
parents = [api_objects["engine.root.Entity"]]
nyan_object = NyanObject("Accuracy", parents)
fqon = "engine.aux.accuracy.Accuracy"
nyan_object.set_fqon(fqon)

api_objects.update({fqon: nyan_object})
5 changes: 4 additions & 1 deletion openage/convert/texture.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def __init__(self, input_data, palette=None, custom_cutter=None):
"from unknown source type: %s" % (type(input_data)))

self.image_data, (self.width, self.height), self.image_metadata\
= merge_frames(frames)
= merge_frames(frames)

def _slp_to_subtextures(self, frame, palette=None, custom_cutter=None):
"""
Expand Down Expand Up @@ -186,6 +186,9 @@ def save(self, targetdir, filename, meta_formats=None):
formatter.export(targetdir, meta_formats)

def dump(self, filename):
"""
Creates a DataDefinition object for the texture metadata.
"""
return [data_definition.DataDefinition(self,
self.image_metadata,
filename)]
Expand Down
1 change: 1 addition & 0 deletions openage/nyan/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
add_py_modules(
nyan_file.py
nyan_structs.py
)
60 changes: 60 additions & 0 deletions openage/nyan/nyan_file.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Copyright 2019-2019 the openage authors. See copying.md for legal info.

"""
Nyan file struct that stores a bunch of objects and
manages imports.
"""

from .nyan_structs import NyanObject

FILE_VERSION = "NYAN FILE version 0.1.0"


class NyanFile:
"""
Superclass for nyan files.
"""

def __init__(self, targetdir, filename, nyan_objects=None):

self.targetdir = targetdir
if not isinstance(filename, str):
raise ValueError("str expected as filename, not %s" %
type(filename))

self.filename = filename

self.nyan_objects = set()
if nyan_objects:
self.nyan_objects = nyan_objects

def add_nyan_object(self, new_object):
"""
Adds a nyan object to the file.
"""
if isinstance(new_object, NyanObject):
self.nyan_objects.add(new_object)

else:
raise Exception("nyan file cannot contain %s",
new_object)

def save(self):
"""
Creates a .nyan file from the data.
"""
with self.targetdir[self.filename].open("wb") as nyan_file:
nyan_file.write(self.dump())

def dump(self):
"""
Returns the string that represents the nyan file.
"""
output_str = "# %s" % (FILE_VERSION)

# TODO: imports

for nyan_object in self.nyan_objects:
output_str += nyan_object.dump()

return output_str
Loading

0 comments on commit 3037668

Please sign in to comment.