Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Primitive lists #4

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 14 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ An ORM tool for parsing and managing game data in your favorite game development

## What

microtome consists of two components: a code generator, and a runtime.
microtome consists of two components: a code generator, and a runtime.

The code generator reads simple descriptor files that describe your game data structure. It generates class files in your game development language of choice.

Expand All @@ -14,45 +14,46 @@ You include the runtime in your game. It reads game data stored in XML and produ
## Quickstart

* Ensure python 2.7 is installed
* Install pystache: ```$ sudo pip install pystache``` or ```$ sudo easy_install pystache```
* Generate test microtome "pages": ```$ /path/to/microtome/bin/gen-test-pages```
* Run the test applications at ```microtome/runtime/src/test/as``` (ActionScript) and ```microtome/runtime/src/main/objc``` (Objective-C).
* `$ cd /path/to/microtome`
* `$ python setup.py install` (or `$ sudo python setup.py install`)
* Generate test microtome "pages": `$ /path/to/microtome/bin/gen-test-pages`
* Run the test applications at `microtome/runtime/src/test/as` (ActionScript) and `microtome/runtime/src/main/objc` (Objective-C).

## Language support

microtome supports ActionScript and Objective-C, but it's designed to be extensible to other languages. To support a new language, you'll need to write a code generator (look at ```microtome/genpages/generator_as.py``` and ```microtome/genpages/generator_objc.py``` for examples) and a runtime (look at ```microtome/runtime/src/main/as``` and ```microtome/runtime/src/main/objc```).
microtome supports ActionScript, Python, and Objective-C, but it's designed to be extensible to other languages. To support a new language, you'll need to write a code generator (look at ```microtome/genpages/generator_as.py``` and ```microtome/genpages/generator_objc.py``` for examples) and a runtime (look at ```microtome/runtime/src/main/as``` and ```microtome/runtime/src/main/objc```).

All runtimes currently support XML, but other data formats (such as JSON) are easily supported as well.

Both runtimes currently support XML, but other data formats (such as JSON) are easily supported as well.

## Example

```
namespace com.dungeoncrawler;

GameData {
page GameData {
HeroPage hero;
Tome<BaddiePage> baddies;
}

HeroPage extends ActorPage {
page HeroPage extends ActorPage {
float mana (min=0);
float manaRegenRate (min=0);
}

BaddiePage extends ActorPage {
page BaddiePage extends ActorPage {
int xpValue;
}

ActorPage {
page ActorPage {
float health (min=0);
float walkSpeed (min=0);
AttackPage attack;
}

AttackPage {
page AttackPage {
int damage;
float range (min=0);
}

```

1 change: 0 additions & 1 deletion microtome/codegen/genpages.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
# microtome - Tim Conkling, 2012

import argparse
import sys
import os
import errno
import re
Expand Down
8 changes: 5 additions & 3 deletions microtome/test/AnnotationPage.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@

# GENERATED IMPORTS START
from microtome.core.prop import Prop
from microtome.core.prop import PropSpec
from microtome.page import Page
from microtome.test.PrimitivePage import PrimitivePage
# GENERATED IMPORTS END

class AnnotationPage(Page):
# GENERATED CONSTRUCTOR START
class AnnotationPage(Page):# GENERATED CONSTRUCTOR START
_s_inited = False
def __init__(self, name):
super(AnnotationPage, self).__init__(name)
Expand Down Expand Up @@ -39,3 +37,7 @@ def primitives(self):
def props(self):
return super(AnnotationPage, self).props + [self._foo, self._bar, self._primitives, ]
# GENERATED PROPS END

# GENERATED CLASS_DECL START
class AnnotationPage(Page):
# GENERATED CLASS_DECL END
8 changes: 5 additions & 3 deletions microtome/test/ListPage.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@

# GENERATED IMPORTS START
from microtome.core.prop import Prop
from microtome.core.prop import PropSpec
from microtome.page import Page
from microtome.test.PrimitivePage import PrimitivePage
# GENERATED IMPORTS END

class ListPage(Page):
# GENERATED CONSTRUCTOR START
class ListPage(Page):# GENERATED CONSTRUCTOR START
_s_inited = False
def __init__(self, name):
super(ListPage, self).__init__(name)
Expand All @@ -27,3 +25,7 @@ def kids(self):
def props(self):
return super(ListPage, self).props + [self._kids, ]
# GENERATED PROPS END

# GENERATED CLASS_DECL START
class ListPage(Page):
# GENERATED CLASS_DECL END
2 changes: 2 additions & 0 deletions microtome/test/MicrotomePages.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from microtome.test.ListPage import ListPage
from microtome.test.NestedPage import NestedPage
from microtome.test.ObjectPage import ObjectPage
from microtome.test.PrimitiveListPage import PrimitiveListPage
from microtome.test.PrimitivePage import PrimitivePage
from microtome.test.RefPage import RefPage
# GENERATED IMPORTS END
Expand All @@ -16,6 +17,7 @@ def get_page_classes():
ListPage,
NestedPage,
ObjectPage,
PrimitiveListPage,
PrimitivePage,
RefPage,
]
Expand Down
8 changes: 5 additions & 3 deletions microtome/test/NestedPage.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@

# GENERATED IMPORTS START
from microtome.core.prop import Prop
from microtome.core.prop import PropSpec
from microtome.page import Page
from microtome.test.PrimitivePage import PrimitivePage
# GENERATED IMPORTS END

class NestedPage(Page):
# GENERATED CONSTRUCTOR START
class NestedPage(Page):# GENERATED CONSTRUCTOR START
_s_inited = False
def __init__(self, name):
super(NestedPage, self).__init__(name)
Expand All @@ -27,3 +25,7 @@ def nested(self):
def props(self):
return super(NestedPage, self).props + [self._nested, ]
# GENERATED PROPS END

# GENERATED CLASS_DECL START
class NestedPage(Page):
# GENERATED CLASS_DECL END
8 changes: 5 additions & 3 deletions microtome/test/ObjectPage.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@

# GENERATED IMPORTS START
from microtome.core.prop import Prop
from microtome.core.prop import PropSpec
from microtome.page import Page
# GENERATED IMPORTS END

class ObjectPage(Page):
# GENERATED CONSTRUCTOR START
class ObjectPage(Page):# GENERATED CONSTRUCTOR START
_s_inited = False
def __init__(self, name):
super(ObjectPage, self).__init__(name)
Expand All @@ -26,3 +24,7 @@ def foo(self):
def props(self):
return super(ObjectPage, self).props + [self._foo, ]
# GENERATED PROPS END

# GENERATED CLASS_DECL START
class ObjectPage(Page):
# GENERATED CLASS_DECL END
47 changes: 47 additions & 0 deletions microtome/test/PrimitiveListPage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# GENERATED IMPORTS START
from microtome.core.prop import Prop
from microtome.core.prop import PropSpec
from microtome.page import Page
# GENERATED IMPORTS END

# GENERATED CLASS_DECL START
class PrimitiveListPage(Page):
# GENERATED CLASS_DECL END
# GENERATED CONSTRUCTOR START
_s_inited = False
def __init__(self, name):
super(PrimitiveListPage, self).__init__(name)
if not PrimitiveListPage._s_inited:
PrimitiveListPage._s_inited = True
PrimitiveListPage._s_stringsSpec = PropSpec("strings", None, [list, str, ])
PrimitiveListPage._s_booleansSpec = PropSpec("booleans", None, [list, bool, ])
PrimitiveListPage._s_intsSpec = PropSpec("ints", None, [list, int, ])
PrimitiveListPage._s_floatsSpec = PropSpec("floats", None, [list, float, ])

self._strings = Prop(self, PrimitiveListPage._s_stringsSpec)
self._booleans = Prop(self, PrimitiveListPage._s_booleansSpec)
self._ints = Prop(self, PrimitiveListPage._s_intsSpec)
self._floats = Prop(self, PrimitiveListPage._s_floatsSpec)
# GENERATED CONSTRUCTOR END

# GENERATED PROPS START
@property
def strings(self):
return self._strings.value

@property
def booleans(self):
return self._booleans.value

@property
def ints(self):
return self._ints.value

@property
def floats(self):
return self._floats.value

@property
def props(self):
return super(PrimitiveListPage, self).props + [self._strings, self._booleans, self._ints, self._floats, ]
# GENERATED PROPS END
8 changes: 5 additions & 3 deletions microtome/test/PrimitivePage.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@

# GENERATED IMPORTS START
from microtome.core.prop import Prop
from microtome.core.prop import PropSpec
from microtome.page import Page
# GENERATED IMPORTS END

class PrimitivePage(Page):
# GENERATED CONSTRUCTOR START
class PrimitivePage(Page):# GENERATED CONSTRUCTOR START
_s_inited = False
def __init__(self, name):
super(PrimitivePage, self).__init__(name)
Expand Down Expand Up @@ -38,3 +36,7 @@ def baz(self):
def props(self):
return super(PrimitivePage, self).props + [self._foo, self._bar, self._baz, ]
# GENERATED PROPS END

# GENERATED CLASS_DECL START
class PrimitivePage(Page):
# GENERATED CLASS_DECL END
8 changes: 5 additions & 3 deletions microtome/test/RefPage.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

# GENERATED IMPORTS START
from microtome.core.page_ref import PageRef
from microtome.core.prop import Prop
Expand All @@ -7,8 +6,7 @@
from microtome.test.PrimitivePage import PrimitivePage
# GENERATED IMPORTS END

class RefPage(Page):
# GENERATED CONSTRUCTOR START
class RefPage(Page):# GENERATED CONSTRUCTOR START
_s_inited = False
def __init__(self, name):
super(RefPage, self).__init__(name)
Expand All @@ -28,3 +26,7 @@ def nested(self):
def props(self):
return super(RefPage, self).props + [self._nested, ]
# GENERATED PROPS END

# GENERATED CLASS_DECL START
class RefPage(Page):
# GENERATED CLASS_DECL END
6 changes: 6 additions & 0 deletions microtome/test/data/AnnotationTest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"annotationTest": {
"pageType": "AnnotationPage",
"foo": 4
}
}
19 changes: 19 additions & 0 deletions microtome/test/data/ListTest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"listTest": {
"pageType": "ListPage",
"kids": [
{
"pageType": "PrimitivePage",
"foo": true,
"bar": 2,
"baz": 3.1415
},
{
"pageType": "PrimitivePage",
"foo": false,
"bar": 666,
"baz": 0.1
}
]
}
}
11 changes: 11 additions & 0 deletions microtome/test/data/NestedTest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"nestedTest": {
"pageType": "NestedPage",
"nested": {
"pageType": "PrimitivePage",
"foo": true,
"bar": 2,
"baz": 3.1415
}
}
}
6 changes: 6 additions & 0 deletions microtome/test/data/ObjectTest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"objectTest": {
"pageType": "ObjectPage",
"foo": "foo"
}
}
28 changes: 28 additions & 0 deletions microtome/test/data/PrimitiveListTest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"primitiveListTest": {
"pageType": "PrimitiveListPage",
"strings": [
"one",
"two",
"three"
],
"booleans": [
true,
false
],
"ints": [
1,
2,
3,
5,
7,
11
],
"floats": [
1.0,
2.1,
3.2,
4.3
]
}
}
29 changes: 29 additions & 0 deletions microtome/test/data/PrimitiveListTest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<microtome>
<primitiveListTest pageType="PrimitiveListPage">
<strings>
<value>one</value>
<value>two</value>
<value>three</value>
</strings>
<booleans>
<value>true</value>
<value>false</value>
</booleans>
<ints>
<value>1</value>
<value>2</value>
<value>3</value>
<value>5</value>
<value>7</value>
<value>11</value>
</ints>
<floats>
<!-- line wrap for testing -->
<value>1.0
</value>
<value>2.1</value>
<value>3.2</value>
<value>4.3</value>
</floats>
</primitiveListTest>
</microtome>
8 changes: 8 additions & 0 deletions microtome/test/data/PrimitiveTest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"primitiveTest": {
"pageType": "PrimitivePage",
"foo": true,
"bar": 2,
"baz": 3.1415
}
}
6 changes: 6 additions & 0 deletions microtome/test/data/RefTest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"refTest": {
"pageType": "RefPage",
"nested": "tomeTest.test1"
}
}
Loading