368910e2 by Barry

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

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