diff --git a/src/__pycache__/interpreter.cpython-32.pyc b/src/__pycache__/interpreter.cpython-32.pyc new file mode 100644 index 0000000..2d36d9f --- /dev/null +++ b/src/__pycache__/interpreter.cpython-32.pyc Binary files differ diff --git a/src/__pycache__/interpreter.cpython-32.pyc b/src/__pycache__/interpreter.cpython-32.pyc new file mode 100644 index 0000000..2d36d9f --- /dev/null +++ b/src/__pycache__/interpreter.cpython-32.pyc Binary files differ diff --git a/src/__pycache__/interpreter.cpython-34.pyc b/src/__pycache__/interpreter.cpython-34.pyc index 56c3add..dac27af 100644 --- a/src/__pycache__/interpreter.cpython-34.pyc +++ b/src/__pycache__/interpreter.cpython-34.pyc Binary files differ diff --git a/src/__pycache__/interpreter.cpython-32.pyc b/src/__pycache__/interpreter.cpython-32.pyc new file mode 100644 index 0000000..2d36d9f --- /dev/null +++ b/src/__pycache__/interpreter.cpython-32.pyc Binary files differ diff --git a/src/__pycache__/interpreter.cpython-34.pyc b/src/__pycache__/interpreter.cpython-34.pyc index 56c3add..dac27af 100644 --- a/src/__pycache__/interpreter.cpython-34.pyc +++ b/src/__pycache__/interpreter.cpython-34.pyc Binary files differ diff --git a/src/__pycache__/place.cpython-32.pyc b/src/__pycache__/place.cpython-32.pyc new file mode 100644 index 0000000..721a318 --- /dev/null +++ b/src/__pycache__/place.cpython-32.pyc Binary files differ diff --git a/src/__pycache__/interpreter.cpython-32.pyc b/src/__pycache__/interpreter.cpython-32.pyc new file mode 100644 index 0000000..2d36d9f --- /dev/null +++ b/src/__pycache__/interpreter.cpython-32.pyc Binary files differ diff --git a/src/__pycache__/interpreter.cpython-34.pyc b/src/__pycache__/interpreter.cpython-34.pyc index 56c3add..dac27af 100644 --- a/src/__pycache__/interpreter.cpython-34.pyc +++ b/src/__pycache__/interpreter.cpython-34.pyc Binary files differ diff --git a/src/__pycache__/place.cpython-32.pyc b/src/__pycache__/place.cpython-32.pyc new file mode 100644 index 0000000..721a318 --- /dev/null +++ b/src/__pycache__/place.cpython-32.pyc Binary files differ diff --git a/src/__pycache__/place.cpython-34.pyc b/src/__pycache__/place.cpython-34.pyc new file mode 100644 index 0000000..5eaa6ef --- /dev/null +++ b/src/__pycache__/place.cpython-34.pyc Binary files differ diff --git a/src/__pycache__/interpreter.cpython-32.pyc b/src/__pycache__/interpreter.cpython-32.pyc new file mode 100644 index 0000000..2d36d9f --- /dev/null +++ b/src/__pycache__/interpreter.cpython-32.pyc Binary files differ diff --git a/src/__pycache__/interpreter.cpython-34.pyc b/src/__pycache__/interpreter.cpython-34.pyc index 56c3add..dac27af 100644 --- a/src/__pycache__/interpreter.cpython-34.pyc +++ b/src/__pycache__/interpreter.cpython-34.pyc Binary files differ diff --git a/src/__pycache__/place.cpython-32.pyc b/src/__pycache__/place.cpython-32.pyc new file mode 100644 index 0000000..721a318 --- /dev/null +++ b/src/__pycache__/place.cpython-32.pyc Binary files differ diff --git a/src/__pycache__/place.cpython-34.pyc b/src/__pycache__/place.cpython-34.pyc new file mode 100644 index 0000000..5eaa6ef --- /dev/null +++ b/src/__pycache__/place.cpython-34.pyc Binary files differ diff --git a/src/__pycache__/server.cpython-34.pyc b/src/__pycache__/server.cpython-34.pyc index e273538..45db28b 100644 --- a/src/__pycache__/server.cpython-34.pyc +++ b/src/__pycache__/server.cpython-34.pyc Binary files differ diff --git a/src/__pycache__/interpreter.cpython-32.pyc b/src/__pycache__/interpreter.cpython-32.pyc new file mode 100644 index 0000000..2d36d9f --- /dev/null +++ b/src/__pycache__/interpreter.cpython-32.pyc Binary files differ diff --git a/src/__pycache__/interpreter.cpython-34.pyc b/src/__pycache__/interpreter.cpython-34.pyc index 56c3add..dac27af 100644 --- a/src/__pycache__/interpreter.cpython-34.pyc +++ b/src/__pycache__/interpreter.cpython-34.pyc Binary files differ diff --git a/src/__pycache__/place.cpython-32.pyc b/src/__pycache__/place.cpython-32.pyc new file mode 100644 index 0000000..721a318 --- /dev/null +++ b/src/__pycache__/place.cpython-32.pyc Binary files differ diff --git a/src/__pycache__/place.cpython-34.pyc b/src/__pycache__/place.cpython-34.pyc new file mode 100644 index 0000000..5eaa6ef --- /dev/null +++ b/src/__pycache__/place.cpython-34.pyc Binary files differ diff --git a/src/__pycache__/server.cpython-34.pyc b/src/__pycache__/server.cpython-34.pyc index e273538..45db28b 100644 --- a/src/__pycache__/server.cpython-34.pyc +++ b/src/__pycache__/server.cpython-34.pyc Binary files differ diff --git a/src/__pycache__/world.cpython-32.pyc b/src/__pycache__/world.cpython-32.pyc new file mode 100644 index 0000000..4276447 --- /dev/null +++ b/src/__pycache__/world.cpython-32.pyc Binary files differ diff --git a/src/__pycache__/interpreter.cpython-32.pyc b/src/__pycache__/interpreter.cpython-32.pyc new file mode 100644 index 0000000..2d36d9f --- /dev/null +++ b/src/__pycache__/interpreter.cpython-32.pyc Binary files differ diff --git a/src/__pycache__/interpreter.cpython-34.pyc b/src/__pycache__/interpreter.cpython-34.pyc index 56c3add..dac27af 100644 --- a/src/__pycache__/interpreter.cpython-34.pyc +++ b/src/__pycache__/interpreter.cpython-34.pyc Binary files differ diff --git a/src/__pycache__/place.cpython-32.pyc b/src/__pycache__/place.cpython-32.pyc new file mode 100644 index 0000000..721a318 --- /dev/null +++ b/src/__pycache__/place.cpython-32.pyc Binary files differ diff --git a/src/__pycache__/place.cpython-34.pyc b/src/__pycache__/place.cpython-34.pyc new file mode 100644 index 0000000..5eaa6ef --- /dev/null +++ b/src/__pycache__/place.cpython-34.pyc Binary files differ diff --git a/src/__pycache__/server.cpython-34.pyc b/src/__pycache__/server.cpython-34.pyc index e273538..45db28b 100644 --- a/src/__pycache__/server.cpython-34.pyc +++ b/src/__pycache__/server.cpython-34.pyc Binary files differ diff --git a/src/__pycache__/world.cpython-32.pyc b/src/__pycache__/world.cpython-32.pyc new file mode 100644 index 0000000..4276447 --- /dev/null +++ b/src/__pycache__/world.cpython-32.pyc Binary files differ diff --git a/src/__pycache__/world.cpython-34.pyc b/src/__pycache__/world.cpython-34.pyc index 9f6b508..6102fe5 100644 --- a/src/__pycache__/world.cpython-34.pyc +++ b/src/__pycache__/world.cpython-34.pyc Binary files differ diff --git a/src/__pycache__/interpreter.cpython-32.pyc b/src/__pycache__/interpreter.cpython-32.pyc new file mode 100644 index 0000000..2d36d9f --- /dev/null +++ b/src/__pycache__/interpreter.cpython-32.pyc Binary files differ diff --git a/src/__pycache__/interpreter.cpython-34.pyc b/src/__pycache__/interpreter.cpython-34.pyc index 56c3add..dac27af 100644 --- a/src/__pycache__/interpreter.cpython-34.pyc +++ b/src/__pycache__/interpreter.cpython-34.pyc Binary files differ diff --git a/src/__pycache__/place.cpython-32.pyc b/src/__pycache__/place.cpython-32.pyc new file mode 100644 index 0000000..721a318 --- /dev/null +++ b/src/__pycache__/place.cpython-32.pyc Binary files differ diff --git a/src/__pycache__/place.cpython-34.pyc b/src/__pycache__/place.cpython-34.pyc new file mode 100644 index 0000000..5eaa6ef --- /dev/null +++ b/src/__pycache__/place.cpython-34.pyc Binary files differ diff --git a/src/__pycache__/server.cpython-34.pyc b/src/__pycache__/server.cpython-34.pyc index e273538..45db28b 100644 --- a/src/__pycache__/server.cpython-34.pyc +++ b/src/__pycache__/server.cpython-34.pyc Binary files differ diff --git a/src/__pycache__/world.cpython-32.pyc b/src/__pycache__/world.cpython-32.pyc new file mode 100644 index 0000000..4276447 --- /dev/null +++ b/src/__pycache__/world.cpython-32.pyc Binary files differ diff --git a/src/__pycache__/world.cpython-34.pyc b/src/__pycache__/world.cpython-34.pyc index 9f6b508..6102fe5 100644 --- a/src/__pycache__/world.cpython-34.pyc +++ b/src/__pycache__/world.cpython-34.pyc Binary files differ diff --git a/src/atlantis.py b/src/atlantis.py index 2999593..2a8490e 100644 --- a/src/atlantis.py +++ b/src/atlantis.py @@ -7,7 +7,7 @@ # date: 02/05/2015 # -VERSION = (0, 0, 5) #release, major revision, minor (git) revision +VERSION = (0, 0, 6) #release, major revision, minor (git) revision import sys import os diff --git a/src/__pycache__/interpreter.cpython-32.pyc b/src/__pycache__/interpreter.cpython-32.pyc new file mode 100644 index 0000000..2d36d9f --- /dev/null +++ b/src/__pycache__/interpreter.cpython-32.pyc Binary files differ diff --git a/src/__pycache__/interpreter.cpython-34.pyc b/src/__pycache__/interpreter.cpython-34.pyc index 56c3add..dac27af 100644 --- a/src/__pycache__/interpreter.cpython-34.pyc +++ b/src/__pycache__/interpreter.cpython-34.pyc Binary files differ diff --git a/src/__pycache__/place.cpython-32.pyc b/src/__pycache__/place.cpython-32.pyc new file mode 100644 index 0000000..721a318 --- /dev/null +++ b/src/__pycache__/place.cpython-32.pyc Binary files differ diff --git a/src/__pycache__/place.cpython-34.pyc b/src/__pycache__/place.cpython-34.pyc new file mode 100644 index 0000000..5eaa6ef --- /dev/null +++ b/src/__pycache__/place.cpython-34.pyc Binary files differ diff --git a/src/__pycache__/server.cpython-34.pyc b/src/__pycache__/server.cpython-34.pyc index e273538..45db28b 100644 --- a/src/__pycache__/server.cpython-34.pyc +++ b/src/__pycache__/server.cpython-34.pyc Binary files differ diff --git a/src/__pycache__/world.cpython-32.pyc b/src/__pycache__/world.cpython-32.pyc new file mode 100644 index 0000000..4276447 --- /dev/null +++ b/src/__pycache__/world.cpython-32.pyc Binary files differ diff --git a/src/__pycache__/world.cpython-34.pyc b/src/__pycache__/world.cpython-34.pyc index 9f6b508..6102fe5 100644 --- a/src/__pycache__/world.cpython-34.pyc +++ b/src/__pycache__/world.cpython-34.pyc Binary files differ diff --git a/src/atlantis.py b/src/atlantis.py index 2999593..2a8490e 100644 --- a/src/atlantis.py +++ b/src/atlantis.py @@ -7,7 +7,7 @@ # date: 02/05/2015 # -VERSION = (0, 0, 5) #release, major revision, minor (git) revision +VERSION = (0, 0, 6) #release, major revision, minor (git) revision import sys import os diff --git a/src/interpreter.py b/src/interpreter.py index 6db846e..1da4220 100644 --- a/src/interpreter.py +++ b/src/interpreter.py @@ -1,8 +1,8 @@ #!/usr/bin/python3 # # Atlantis is a framework for creating multi-user dungeon worlds. -# This module reads in a world file and parses it. This is where the -# structure of the Atlantis language is defined. +# This module reads in a world file and parses it. The structure of +# the Atlantis language ATL is defined here. # # Licensed under the terms of the GPLv3 # author: Daniel Vedder @@ -55,8 +55,7 @@ option_function: The function that this option calls (this function should take exactly one string argument) ''' - option_dict = dict["docstring":option_docstring, - "function":option_function] + option_dict = dict(docstring=option_docstring, function=option_function) self.option_registry[option_name] = option_dict @@ -76,8 +75,6 @@ self.line_command_registry = dict() self.world = World() self.add_line_commands() - self.load(world_file_name) - return self.world def load(self, world_file_name): ''' @@ -87,9 +84,11 @@ world_file = open(world_file_name, 'r') atl_text = world_file.readlines() world_file.close() + print("Loaded "+world_file_name) except IOError: print("Failed to load world file '"+world_file_name+"'!") self.interpret_atl(atl_text) + return self.world def add_line_commands(self): ''' @@ -104,39 +103,43 @@ def interpret_atl(self, atl_source): ''' - This method interprets a list of atl source lines, passing them + This method interprets a list of ATL source lines, passing them on to the relevant define commands. ''' define_command = None # The define command currently being executed line_no = 0 for line in atl_source: # TODO allow for linebreaks + # while line[-2] == "\\": + # line = line + atl_source[line_no+1] + # line_no = line_no+1 line_no = line_no + 1 - if line[0] == "#": - pass #comments are ignored - elif (line == "" or line == "\n") and define_command: + if len(line) < 2 and define_command: # Empty lines finish off define blocks object_type, game_object = define_command.return_object() self.world.add_object(object_type, game_object) define_command = None + elif len(line) < 2 or line[0] == "#": + pass #comments and empty lines are ignored else: - print("Line: '"+line+"'") command = line.split()[0] + print("Line "+str(line_no)+": '"+line+"'\nCommand: '"+command+"'") # execute a line command - if command in line_command_registry.keys(): - line_command_registry[command](line[line.find(" ")+1:]) + if command in self.line_command_registry.keys(): + self.line_command_registry[command](line[line.find(" ")+1:-1]) # start of a define block elif command in define_command_registry.keys(): define_command = define_command_registry[command] - object_name = line[line.find(" ")+1:] + object_name = line[line.find(" ")+1:-1] define_command.init_object(object_name) + print("Found define command '"+define_command.name) # parse an option command elif line[0] == " " or line[0] == "\t": while line[0] == " " or line[0] == "\t": line = line[1:] if line and define_command: option_command = line.split()[0] - option_arg = line[line.find(" ")+1:] + option_arg = line[line.find(" ")+1:-1] define_command.pass_option(option_command, option_arg) else: # XXX: What should be done here? Do nothing, raise a diff --git a/src/__pycache__/interpreter.cpython-32.pyc b/src/__pycache__/interpreter.cpython-32.pyc new file mode 100644 index 0000000..2d36d9f --- /dev/null +++ b/src/__pycache__/interpreter.cpython-32.pyc Binary files differ diff --git a/src/__pycache__/interpreter.cpython-34.pyc b/src/__pycache__/interpreter.cpython-34.pyc index 56c3add..dac27af 100644 --- a/src/__pycache__/interpreter.cpython-34.pyc +++ b/src/__pycache__/interpreter.cpython-34.pyc Binary files differ diff --git a/src/__pycache__/place.cpython-32.pyc b/src/__pycache__/place.cpython-32.pyc new file mode 100644 index 0000000..721a318 --- /dev/null +++ b/src/__pycache__/place.cpython-32.pyc Binary files differ diff --git a/src/__pycache__/place.cpython-34.pyc b/src/__pycache__/place.cpython-34.pyc new file mode 100644 index 0000000..5eaa6ef --- /dev/null +++ b/src/__pycache__/place.cpython-34.pyc Binary files differ diff --git a/src/__pycache__/server.cpython-34.pyc b/src/__pycache__/server.cpython-34.pyc index e273538..45db28b 100644 --- a/src/__pycache__/server.cpython-34.pyc +++ b/src/__pycache__/server.cpython-34.pyc Binary files differ diff --git a/src/__pycache__/world.cpython-32.pyc b/src/__pycache__/world.cpython-32.pyc new file mode 100644 index 0000000..4276447 --- /dev/null +++ b/src/__pycache__/world.cpython-32.pyc Binary files differ diff --git a/src/__pycache__/world.cpython-34.pyc b/src/__pycache__/world.cpython-34.pyc index 9f6b508..6102fe5 100644 --- a/src/__pycache__/world.cpython-34.pyc +++ b/src/__pycache__/world.cpython-34.pyc Binary files differ diff --git a/src/atlantis.py b/src/atlantis.py index 2999593..2a8490e 100644 --- a/src/atlantis.py +++ b/src/atlantis.py @@ -7,7 +7,7 @@ # date: 02/05/2015 # -VERSION = (0, 0, 5) #release, major revision, minor (git) revision +VERSION = (0, 0, 6) #release, major revision, minor (git) revision import sys import os diff --git a/src/interpreter.py b/src/interpreter.py index 6db846e..1da4220 100644 --- a/src/interpreter.py +++ b/src/interpreter.py @@ -1,8 +1,8 @@ #!/usr/bin/python3 # # Atlantis is a framework for creating multi-user dungeon worlds. -# This module reads in a world file and parses it. This is where the -# structure of the Atlantis language is defined. +# This module reads in a world file and parses it. The structure of +# the Atlantis language ATL is defined here. # # Licensed under the terms of the GPLv3 # author: Daniel Vedder @@ -55,8 +55,7 @@ option_function: The function that this option calls (this function should take exactly one string argument) ''' - option_dict = dict["docstring":option_docstring, - "function":option_function] + option_dict = dict(docstring=option_docstring, function=option_function) self.option_registry[option_name] = option_dict @@ -76,8 +75,6 @@ self.line_command_registry = dict() self.world = World() self.add_line_commands() - self.load(world_file_name) - return self.world def load(self, world_file_name): ''' @@ -87,9 +84,11 @@ world_file = open(world_file_name, 'r') atl_text = world_file.readlines() world_file.close() + print("Loaded "+world_file_name) except IOError: print("Failed to load world file '"+world_file_name+"'!") self.interpret_atl(atl_text) + return self.world def add_line_commands(self): ''' @@ -104,39 +103,43 @@ def interpret_atl(self, atl_source): ''' - This method interprets a list of atl source lines, passing them + This method interprets a list of ATL source lines, passing them on to the relevant define commands. ''' define_command = None # The define command currently being executed line_no = 0 for line in atl_source: # TODO allow for linebreaks + # while line[-2] == "\\": + # line = line + atl_source[line_no+1] + # line_no = line_no+1 line_no = line_no + 1 - if line[0] == "#": - pass #comments are ignored - elif (line == "" or line == "\n") and define_command: + if len(line) < 2 and define_command: # Empty lines finish off define blocks object_type, game_object = define_command.return_object() self.world.add_object(object_type, game_object) define_command = None + elif len(line) < 2 or line[0] == "#": + pass #comments and empty lines are ignored else: - print("Line: '"+line+"'") command = line.split()[0] + print("Line "+str(line_no)+": '"+line+"'\nCommand: '"+command+"'") # execute a line command - if command in line_command_registry.keys(): - line_command_registry[command](line[line.find(" ")+1:]) + if command in self.line_command_registry.keys(): + self.line_command_registry[command](line[line.find(" ")+1:-1]) # start of a define block elif command in define_command_registry.keys(): define_command = define_command_registry[command] - object_name = line[line.find(" ")+1:] + object_name = line[line.find(" ")+1:-1] define_command.init_object(object_name) + print("Found define command '"+define_command.name) # parse an option command elif line[0] == " " or line[0] == "\t": while line[0] == " " or line[0] == "\t": line = line[1:] if line and define_command: option_command = line.split()[0] - option_arg = line[line.find(" ")+1:] + option_arg = line[line.find(" ")+1:-1] define_command.pass_option(option_command, option_arg) else: # XXX: What should be done here? Do nothing, raise a diff --git a/src/place.py b/src/place.py index eabd30e..86ea286 100644 --- a/src/place.py +++ b/src/place.py @@ -32,6 +32,7 @@ items: a list of instances of items ''' self.name = name + print("Creating place "+name) self.description = description self.neighbours = neighbours self.monsters = monsters @@ -68,16 +69,16 @@ ''' The Atlantis language construct to create a place. ''' - + def __init__(self): - DefineCommand.__init__("define-place", + DefineCommand.__init__(self, "define-place", "Describe a new location in the game world") self.add_option("description", "Describe this place", - set_description) + self.set_description) self.add_option("neighbour", "Add a neighbouring place to this place", - add_neighbour) + self.add_neighbour) def init_object(self, place_name): self.place = Place(name=place_name) diff --git a/src/__pycache__/interpreter.cpython-32.pyc b/src/__pycache__/interpreter.cpython-32.pyc new file mode 100644 index 0000000..2d36d9f --- /dev/null +++ b/src/__pycache__/interpreter.cpython-32.pyc Binary files differ diff --git a/src/__pycache__/interpreter.cpython-34.pyc b/src/__pycache__/interpreter.cpython-34.pyc index 56c3add..dac27af 100644 --- a/src/__pycache__/interpreter.cpython-34.pyc +++ b/src/__pycache__/interpreter.cpython-34.pyc Binary files differ diff --git a/src/__pycache__/place.cpython-32.pyc b/src/__pycache__/place.cpython-32.pyc new file mode 100644 index 0000000..721a318 --- /dev/null +++ b/src/__pycache__/place.cpython-32.pyc Binary files differ diff --git a/src/__pycache__/place.cpython-34.pyc b/src/__pycache__/place.cpython-34.pyc new file mode 100644 index 0000000..5eaa6ef --- /dev/null +++ b/src/__pycache__/place.cpython-34.pyc Binary files differ diff --git a/src/__pycache__/server.cpython-34.pyc b/src/__pycache__/server.cpython-34.pyc index e273538..45db28b 100644 --- a/src/__pycache__/server.cpython-34.pyc +++ b/src/__pycache__/server.cpython-34.pyc Binary files differ diff --git a/src/__pycache__/world.cpython-32.pyc b/src/__pycache__/world.cpython-32.pyc new file mode 100644 index 0000000..4276447 --- /dev/null +++ b/src/__pycache__/world.cpython-32.pyc Binary files differ diff --git a/src/__pycache__/world.cpython-34.pyc b/src/__pycache__/world.cpython-34.pyc index 9f6b508..6102fe5 100644 --- a/src/__pycache__/world.cpython-34.pyc +++ b/src/__pycache__/world.cpython-34.pyc Binary files differ diff --git a/src/atlantis.py b/src/atlantis.py index 2999593..2a8490e 100644 --- a/src/atlantis.py +++ b/src/atlantis.py @@ -7,7 +7,7 @@ # date: 02/05/2015 # -VERSION = (0, 0, 5) #release, major revision, minor (git) revision +VERSION = (0, 0, 6) #release, major revision, minor (git) revision import sys import os diff --git a/src/interpreter.py b/src/interpreter.py index 6db846e..1da4220 100644 --- a/src/interpreter.py +++ b/src/interpreter.py @@ -1,8 +1,8 @@ #!/usr/bin/python3 # # Atlantis is a framework for creating multi-user dungeon worlds. -# This module reads in a world file and parses it. This is where the -# structure of the Atlantis language is defined. +# This module reads in a world file and parses it. The structure of +# the Atlantis language ATL is defined here. # # Licensed under the terms of the GPLv3 # author: Daniel Vedder @@ -55,8 +55,7 @@ option_function: The function that this option calls (this function should take exactly one string argument) ''' - option_dict = dict["docstring":option_docstring, - "function":option_function] + option_dict = dict(docstring=option_docstring, function=option_function) self.option_registry[option_name] = option_dict @@ -76,8 +75,6 @@ self.line_command_registry = dict() self.world = World() self.add_line_commands() - self.load(world_file_name) - return self.world def load(self, world_file_name): ''' @@ -87,9 +84,11 @@ world_file = open(world_file_name, 'r') atl_text = world_file.readlines() world_file.close() + print("Loaded "+world_file_name) except IOError: print("Failed to load world file '"+world_file_name+"'!") self.interpret_atl(atl_text) + return self.world def add_line_commands(self): ''' @@ -104,39 +103,43 @@ def interpret_atl(self, atl_source): ''' - This method interprets a list of atl source lines, passing them + This method interprets a list of ATL source lines, passing them on to the relevant define commands. ''' define_command = None # The define command currently being executed line_no = 0 for line in atl_source: # TODO allow for linebreaks + # while line[-2] == "\\": + # line = line + atl_source[line_no+1] + # line_no = line_no+1 line_no = line_no + 1 - if line[0] == "#": - pass #comments are ignored - elif (line == "" or line == "\n") and define_command: + if len(line) < 2 and define_command: # Empty lines finish off define blocks object_type, game_object = define_command.return_object() self.world.add_object(object_type, game_object) define_command = None + elif len(line) < 2 or line[0] == "#": + pass #comments and empty lines are ignored else: - print("Line: '"+line+"'") command = line.split()[0] + print("Line "+str(line_no)+": '"+line+"'\nCommand: '"+command+"'") # execute a line command - if command in line_command_registry.keys(): - line_command_registry[command](line[line.find(" ")+1:]) + if command in self.line_command_registry.keys(): + self.line_command_registry[command](line[line.find(" ")+1:-1]) # start of a define block elif command in define_command_registry.keys(): define_command = define_command_registry[command] - object_name = line[line.find(" ")+1:] + object_name = line[line.find(" ")+1:-1] define_command.init_object(object_name) + print("Found define command '"+define_command.name) # parse an option command elif line[0] == " " or line[0] == "\t": while line[0] == " " or line[0] == "\t": line = line[1:] if line and define_command: option_command = line.split()[0] - option_arg = line[line.find(" ")+1:] + option_arg = line[line.find(" ")+1:-1] define_command.pass_option(option_command, option_arg) else: # XXX: What should be done here? Do nothing, raise a diff --git a/src/place.py b/src/place.py index eabd30e..86ea286 100644 --- a/src/place.py +++ b/src/place.py @@ -32,6 +32,7 @@ items: a list of instances of items ''' self.name = name + print("Creating place "+name) self.description = description self.neighbours = neighbours self.monsters = monsters @@ -68,16 +69,16 @@ ''' The Atlantis language construct to create a place. ''' - + def __init__(self): - DefineCommand.__init__("define-place", + DefineCommand.__init__(self, "define-place", "Describe a new location in the game world") self.add_option("description", "Describe this place", - set_description) + self.set_description) self.add_option("neighbour", "Add a neighbouring place to this place", - add_neighbour) + self.add_neighbour) def init_object(self, place_name): self.place = Place(name=place_name) diff --git a/src/server.py b/src/server.py index 8c6b6ea..c3b1abf 100644 --- a/src/server.py +++ b/src/server.py @@ -9,6 +9,7 @@ # from interpreter import Parser +from world import World #TODO: lock file for the server! @@ -22,8 +23,9 @@ print("The server is still under construction!") self.port = port self.world_file = world_file - self.world = Parser(self.world_file) - test_parser() + parser = Parser(self.world_file) + self.world = parser.load(self.world_file) + self.test_parser() def test_parser(self): print("World loaded. Details:") diff --git a/src/__pycache__/interpreter.cpython-32.pyc b/src/__pycache__/interpreter.cpython-32.pyc new file mode 100644 index 0000000..2d36d9f --- /dev/null +++ b/src/__pycache__/interpreter.cpython-32.pyc Binary files differ diff --git a/src/__pycache__/interpreter.cpython-34.pyc b/src/__pycache__/interpreter.cpython-34.pyc index 56c3add..dac27af 100644 --- a/src/__pycache__/interpreter.cpython-34.pyc +++ b/src/__pycache__/interpreter.cpython-34.pyc Binary files differ diff --git a/src/__pycache__/place.cpython-32.pyc b/src/__pycache__/place.cpython-32.pyc new file mode 100644 index 0000000..721a318 --- /dev/null +++ b/src/__pycache__/place.cpython-32.pyc Binary files differ diff --git a/src/__pycache__/place.cpython-34.pyc b/src/__pycache__/place.cpython-34.pyc new file mode 100644 index 0000000..5eaa6ef --- /dev/null +++ b/src/__pycache__/place.cpython-34.pyc Binary files differ diff --git a/src/__pycache__/server.cpython-34.pyc b/src/__pycache__/server.cpython-34.pyc index e273538..45db28b 100644 --- a/src/__pycache__/server.cpython-34.pyc +++ b/src/__pycache__/server.cpython-34.pyc Binary files differ diff --git a/src/__pycache__/world.cpython-32.pyc b/src/__pycache__/world.cpython-32.pyc new file mode 100644 index 0000000..4276447 --- /dev/null +++ b/src/__pycache__/world.cpython-32.pyc Binary files differ diff --git a/src/__pycache__/world.cpython-34.pyc b/src/__pycache__/world.cpython-34.pyc index 9f6b508..6102fe5 100644 --- a/src/__pycache__/world.cpython-34.pyc +++ b/src/__pycache__/world.cpython-34.pyc Binary files differ diff --git a/src/atlantis.py b/src/atlantis.py index 2999593..2a8490e 100644 --- a/src/atlantis.py +++ b/src/atlantis.py @@ -7,7 +7,7 @@ # date: 02/05/2015 # -VERSION = (0, 0, 5) #release, major revision, minor (git) revision +VERSION = (0, 0, 6) #release, major revision, minor (git) revision import sys import os diff --git a/src/interpreter.py b/src/interpreter.py index 6db846e..1da4220 100644 --- a/src/interpreter.py +++ b/src/interpreter.py @@ -1,8 +1,8 @@ #!/usr/bin/python3 # # Atlantis is a framework for creating multi-user dungeon worlds. -# This module reads in a world file and parses it. This is where the -# structure of the Atlantis language is defined. +# This module reads in a world file and parses it. The structure of +# the Atlantis language ATL is defined here. # # Licensed under the terms of the GPLv3 # author: Daniel Vedder @@ -55,8 +55,7 @@ option_function: The function that this option calls (this function should take exactly one string argument) ''' - option_dict = dict["docstring":option_docstring, - "function":option_function] + option_dict = dict(docstring=option_docstring, function=option_function) self.option_registry[option_name] = option_dict @@ -76,8 +75,6 @@ self.line_command_registry = dict() self.world = World() self.add_line_commands() - self.load(world_file_name) - return self.world def load(self, world_file_name): ''' @@ -87,9 +84,11 @@ world_file = open(world_file_name, 'r') atl_text = world_file.readlines() world_file.close() + print("Loaded "+world_file_name) except IOError: print("Failed to load world file '"+world_file_name+"'!") self.interpret_atl(atl_text) + return self.world def add_line_commands(self): ''' @@ -104,39 +103,43 @@ def interpret_atl(self, atl_source): ''' - This method interprets a list of atl source lines, passing them + This method interprets a list of ATL source lines, passing them on to the relevant define commands. ''' define_command = None # The define command currently being executed line_no = 0 for line in atl_source: # TODO allow for linebreaks + # while line[-2] == "\\": + # line = line + atl_source[line_no+1] + # line_no = line_no+1 line_no = line_no + 1 - if line[0] == "#": - pass #comments are ignored - elif (line == "" or line == "\n") and define_command: + if len(line) < 2 and define_command: # Empty lines finish off define blocks object_type, game_object = define_command.return_object() self.world.add_object(object_type, game_object) define_command = None + elif len(line) < 2 or line[0] == "#": + pass #comments and empty lines are ignored else: - print("Line: '"+line+"'") command = line.split()[0] + print("Line "+str(line_no)+": '"+line+"'\nCommand: '"+command+"'") # execute a line command - if command in line_command_registry.keys(): - line_command_registry[command](line[line.find(" ")+1:]) + if command in self.line_command_registry.keys(): + self.line_command_registry[command](line[line.find(" ")+1:-1]) # start of a define block elif command in define_command_registry.keys(): define_command = define_command_registry[command] - object_name = line[line.find(" ")+1:] + object_name = line[line.find(" ")+1:-1] define_command.init_object(object_name) + print("Found define command '"+define_command.name) # parse an option command elif line[0] == " " or line[0] == "\t": while line[0] == " " or line[0] == "\t": line = line[1:] if line and define_command: option_command = line.split()[0] - option_arg = line[line.find(" ")+1:] + option_arg = line[line.find(" ")+1:-1] define_command.pass_option(option_command, option_arg) else: # XXX: What should be done here? Do nothing, raise a diff --git a/src/place.py b/src/place.py index eabd30e..86ea286 100644 --- a/src/place.py +++ b/src/place.py @@ -32,6 +32,7 @@ items: a list of instances of items ''' self.name = name + print("Creating place "+name) self.description = description self.neighbours = neighbours self.monsters = monsters @@ -68,16 +69,16 @@ ''' The Atlantis language construct to create a place. ''' - + def __init__(self): - DefineCommand.__init__("define-place", + DefineCommand.__init__(self, "define-place", "Describe a new location in the game world") self.add_option("description", "Describe this place", - set_description) + self.set_description) self.add_option("neighbour", "Add a neighbouring place to this place", - add_neighbour) + self.add_neighbour) def init_object(self, place_name): self.place = Place(name=place_name) diff --git a/src/server.py b/src/server.py index 8c6b6ea..c3b1abf 100644 --- a/src/server.py +++ b/src/server.py @@ -9,6 +9,7 @@ # from interpreter import Parser +from world import World #TODO: lock file for the server! @@ -22,8 +23,9 @@ print("The server is still under construction!") self.port = port self.world_file = world_file - self.world = Parser(self.world_file) - test_parser() + parser = Parser(self.world_file) + self.world = parser.load(self.world_file) + self.test_parser() def test_parser(self): print("World loaded. Details:") diff --git a/src/world.py b/src/world.py index aaacc17..1165f30 100644 --- a/src/world.py +++ b/src/world.py @@ -9,6 +9,8 @@ # import copy +#import player +#import place class World(object):