1+ import json
2+
3+ class Vector3 :
4+ def __init__ (self , x = None , y = None , z = None , posArray = None ):
5+ if (posArray is not None ):
6+ self .x = posArray [0 ]
7+ self .y = posArray [1 ]
8+ self .z = posArray [2 ]
9+ else :
10+ self .x = x
11+ self .y = y
12+ self .z = z
13+
14+ def __repr__ (self ):
15+ return [self .x , self .y , self .z ]
16+
17+ def raw (self ):
18+ return self .__repr__ ()
19+
20+ class Robot :
21+ def __init__ (self , robotID , fuel = 0 , pos = [0 ,0 ,0 ], facing = "+x" ):
22+ self .id = robotID ;
23+ self .fuel = fuel
24+
25+ self .lastReturn = [None , None ]
26+ self .lastCommand = ""
27+ self .pos = Vector3 (posArray = pos )
28+ self .facing = facing
29+
30+ def getRaw (self ):
31+ return {"robotID" : self .id , "fuel" : self .fuel , "lastData" : self .lastReturn , "lastCommand" : self .lastCommand , "pos" : self .pos .raw (), "facing" : self .facing }
32+
33+ def getSaveInfo (self ):
34+ return {"robotID" : self .id , "fuel" : self .fuel , "pos" : self .pos .raw (), "facing" : self .facing }
35+
36+ class Message :
37+ def __init__ (self , message , forID ):
38+ self .content = message
39+ self .id = forID
40+
41+ def __repr__ (self ):
42+ return f"[Message '{ self .content } ' for id { self .id } ]"
43+
44+ class BotMessage :
45+ def __init__ (self , val1 , val2 , botID ):
46+ self .content = [val1 , val2 ]
47+ self .id = botID
48+
49+ class HTTPMessage :
50+ def __init__ (self , message , userID , in_data = None ):
51+ self .content = message
52+ self .userID = userID
53+ self .in_data = in_data
54+
55+ def getJSON (self ):
56+ if (self .in_data is not None ):
57+ return json .dumps ({"message" :self .content , "id" : self .userID , "data" :self .in_data })
58+ else :
59+ return json .dumps ({"message" :self .content , "id" : self .userID })
60+
61+ def __repr__ (self ):
62+ return f"[Message: { self .content } , ID: { self .userID } ]"
0 commit comments