def load_regions_from_json(self, file_path): json_string = "" with io.open(file_path, 'r') as file: for line in file.readlines(): json_string += line.split('#')[0].replace('\n', ' ') region_json = json.loads(json_string) for region in region_json: new_region = Region(region['region_name']) new_region.world = self if 'dungeon' in region: new_region.dungeon = region['dungeon'] if 'locations' in region: for location, rule in region['locations'].items(): new_location = LocationFactory(location) new_location.parent_region = new_region if self.logic_rules != 'none': new_location.access_rule = parse_rule_string( rule, self) new_location.world = self new_region.locations.append(new_location) if 'exits' in region: for exit, rule in region['exits'].items(): new_exit = Entrance('%s -> %s' % (new_region.name, exit), new_region) new_exit.connected_region = exit if self.logic_rules != 'none': new_exit.access_rule = parse_rule_string(rule, self) new_region.exits.append(new_exit) self.regions.append(new_region)
def load_regions_from_json(self, file_path): json_string = "" with io.open(file_path, 'r') as file: for line in file.readlines(): json_string += line.split('#')[0].replace('\n', ' ') json_string = re.sub(' +', ' ', json_string) try: region_json = json.loads(json_string) except json.JSONDecodeError as error: raise Exception("JSON parse error around text:\n" + \ json_string[error.pos-35:error.pos+35] + "\n" + \ " ^^\n") for region in region_json: new_region = Region(region['region_name']) new_region.world = self if 'scene' in region: new_region.scene = region['scene'] if 'hint' in region: new_region.hint = region['hint'] if 'dungeon' in region: new_region.dungeon = region['dungeon'] if 'time_passes' in region: new_region.time_passes = region['time_passes'] if 'locations' in region: for location, rule in region['locations'].items(): new_location = LocationFactory(location) new_location.parent_region = new_region if self.logic_rules != 'none': new_location.access_rule = parse_rule_string( rule, self) new_location.world = self new_region.locations.append(new_location) if 'exits' in region: for exit, rule in region['exits'].items(): new_exit = Entrance('%s -> %s' % (new_region.name, exit), new_region) new_exit.connected_region = exit if self.logic_rules != 'none': new_exit.access_rule = parse_rule_string(rule, self) new_region.exits.append(new_exit) self.regions.append(new_region)