368910e2 by Barry

Added automated release script and changes for utils / items / inventory

1 parent ce1ef4e7
1 import os
2 import sys
3
4 files = [
5 "commandhandler.py",
6 "main.py",
7 "mudserver.py",
8 "roomloader.py",
9 "utils.py",
10 "welcome.txt",
11 "wifiweb.py"
12 ]
13
14 for f in os.listdir('help'):
15 files.append('help/' + f)
16
17 for f in os.listdir('rooms'):
18 files.append('rooms/' + f)
19
20 password = sys.argv[1]
21
22 for file in files:
23 os.system("python webrepl\webrepl_cli.py -p {} {} 192.168.1.126:/{}".format(password, file, file))
24
1 1
2 import json 2 import json
3 import utils
3 4
4 class RoomLoader(object): 5 class RoomLoader(object):
5 6
...@@ -7,25 +8,39 @@ class RoomLoader(object): ...@@ -7,25 +8,39 @@ class RoomLoader(object):
7 self.directory = directory 8 self.directory = directory
8 9
9 def _get_room_file(self, room_name): 10 def _get_room_file(self, room_name):
10 try:
11 filename = self.directory + '/' + room_name + ".txt" 11 filename = self.directory + '/' + room_name + ".txt"
12 with open(filename, 'r', encoding='utf-8') as f: 12 room_data = utils.load_object_from_file(filename)
13 return json.loads(f.read()) 13 if room_data is None:
14 except Exception as e: 14 print("Error opening room file: {}".format(room_name))
15 print("Error opening room file: {} with exception: {}".format(room_name, e)) 15 return {"title": "", "description": "", "exits": {}, "look_items": {}, "inventory": {}}
16 return {"title": "", "description": "", "exits": {}, "look_items": {}} 16 return room_data
17
18 def _save_room_file(self, room_name, room_data):
19 filename = self.directory + '/' + room_name + ".txt"
20 utils.save_object_to_file(filename, room_data)
17 21
18 def get_title(self, room_name): 22 def get_title(self, room_name):
19 return self._get_room_file(room_name)['title'] 23 return self._get_room_file(room_name)['title']
20 24
21 def get_description(self, room_name): 25 def get_description(self, room_name):
22 return self._get_room_file(room_name)['description'] 26 return self._get_room_file(room_name)['description']
23 # chunks, chunk_size = len(desc), 80 #len(x)/4
24 # lines = [ desc[i:i+chunk_size] for i in range(0, chunks, chunk_size) ]
25 # return '\r\n'.join(lines)
26 27
27 def get_exits(self, room_name): 28 def get_exits(self, room_name):
28 return self._get_room_file(room_name)['exits'] 29 return self._get_room_file(room_name)['exits']
29 30
30 def get_look_items(self, room_name): 31 def get_look_items(self, room_name):
31 return self._get_room_file(room_name)['look_items'] 32 return self._get_room_file(room_name)['look_items']
33
34 def get_inventory(self, room_name):
35 return self._get_room_file(room_name)['inventory']
36
37 def add_to_inventory(self, room_name, item_name, item_template):
38 room_data = self._get_room_file(room_name)
39 if item_name in room_data['inventory']:
40 # the item_name should always be unique. Let this happen just in case so it will
41 # prune a dupe from player
42 return True
43 else:
44 room_data['inventory']['item_name'] = item_template
45 self._save_room_file(room_name, room_data)
46 return
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -5,5 +5,5 @@ ...@@ -5,5 +5,5 @@
5 "look_items": { 5 "look_items": {
6 "tavern": "A roughly constructed building." 6 "tavern": "A roughly constructed building."
7 }, 7 },
8 "inventory": [] 8 "inventory": {}
9 } 9 }
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -7,5 +7,5 @@ ...@@ -7,5 +7,5 @@
7 "barrel,barrels": "The old barrels bands are thick with oxidation and stained with the purple of spilled wine.", 7 "barrel,barrels": "The old barrels bands are thick with oxidation and stained with the purple of spilled wine.",
8 "wooden,oak,plank": "An old solid oak plank that has a large number of chips and drink marks." 8 "wooden,oak,plank": "An old solid oak plank that has a large number of chips and drink marks."
9 }, 9 },
10 "inventory": [] 10 "inventory": {}
11 } 11 }
......
...@@ -8,5 +8,5 @@ ...@@ -8,5 +8,5 @@
8 "wooden,oak,plank": "An old solid oak plank that has a large number of chips and drink marks.", 8 "wooden,oak,plank": "An old solid oak plank that has a large number of chips and drink marks.",
9 "fire": "The fire crackles quietly in the corner providing a small amount of light and heat." 9 "fire": "The fire crackles quietly in the corner providing a small amount of light and heat."
10 }, 10 },
11 "inventory": [] 11 "inventory": {}
12 } 12 }
...\ No newline at end of file ...\ No newline at end of file
......
1 import json 1 import json
2 2
3 def save_object_to_file(self, obj, filename):
4 with open(filename, 'w', encoding='utf-8') as f:
5 f.write(json.dumps(obj))
6
7 def save_object_to_file(obj, filename): 3 def save_object_to_file(obj, filename):
8 with open(filename, 'w', encoding='utf-8') as f: 4 with open(filename, 'w', encoding='utf-8') as f:
9 f.write(json.dumps(obj)) 5 f.write(json.dumps(obj))
......
webrepl @ 4cb75569
1 Subproject commit 4cb755698470b9160bdb0a58d5ff54176cfc1abb