This repository has been archived by the owner on Oct 19, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmongoengine_models.py
executable file
·76 lines (61 loc) · 2.37 KB
/
mongoengine_models.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import datetime
import mongoengine as me
class IntVector(me.EmbeddedDocument):
'''A document for holding documents with three integer vectors:
x, y and z.'''
x = me.IntField(default=0)
y = me.IntField(default=0)
z = me.IntField(default=0)
class FloatVector(me.EmbeddedDocument):
'''A document for holding documents with three float vectors:
x, y and z.'''
x = me.FloatField(default=0)
y = me.FloatField(default=0)
z = me.FloatField(default=0)
class Object(me.Document):
'''In-world objects.'''
name = me.StringField(default="")
resource = me.StringField(default="")
loc = me.EmbeddedDocumentField(IntVector) # FIXME: Make this a floatvector.
rot = me.EmbeddedDocumentField(FloatVector)
scale = me.EmbeddedDocumentField(FloatVector)
vel = me.EmbeddedDocumentField(FloatVector)
states = me.ListField(me.StringField())
physical = me.BooleanField(default=True)
last_modified = me.DateTimeField(default=datetime.datetime.now)
meta = {'indexes': ['last_modified',
'loc.x', 'loc.y', 'loc.z',
'states',
'physical'],
'allow_inheritance': True,
}
def set_modified(self, date_time=None):
if date_time is None:
date_time = datetime.datetime.now()
self.last_modified = date_time
self.save()
class ScriptedObject(Object):
scripts = me.ListField(me.StringField())
meta = {'allow_inheritance': True}
class Character(ScriptedObject):
'''Players' characters in-world representation.'''
speed = me.FloatField(default=5)
owner = me.StringField()
meta = {'allow_inheritance': True}
class Message(me.Document):
'''A message said and displayed as if it were in world.
Used only for zone-local messages.'''
last_modified = me.DateTimeField(default=datetime.datetime.now)
sender = me.StringField(default="")
body = me.StringField(default="")
loc = me.EmbeddedDocumentField(IntVector)
player_generated = me.BooleanField(default=False)
meta = {'indexes': ['last_modified', 'loc'],
'allow_inheritance': True,
}
class PrivateMessage(Message):
'''A message from and to a specific thing.'''
recipient = me.StringField(default="")
meta = {'indexes': ['recipient'],
'allow_inheritance': True,
}