-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
148 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
add_py_modules( | ||
nyan_file.py | ||
nyan_structs.py | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters