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)
Exemple #2
0
    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']
                new_region.provides_time = TimeOfDay.ALL
            if new_region.name == 'Ganons Castle Grounds':
                new_region.provides_time = TimeOfDay.DAMPE
            if 'locations' in region:
                for location, rule in region['locations'].items():
                    new_location = LocationFactory(location)
                    new_location.parent_region = new_region
                    new_location.rule_string = rule
                    if self.logic_rules != 'none':
                        self.parser.parse_spot_rule(new_location)
                    new_location.world = self
                    new_region.locations.append(new_location)
            if 'events' in region:
                for event, rule in region['events'].items():
                    # Allow duplicate placement of events
                    lname = '%s from %s' % (event, new_region.name)
                    new_location = Location(lname,
                                            type='Event',
                                            parent=new_region)
                    new_location.rule_string = rule
                    if self.logic_rules != 'none':
                        self.parser.parse_spot_rule(new_location)
                    new_location.world = self
                    new_region.locations.append(new_location)
                    MakeEventItem(event, 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
                    new_exit.rule_string = rule
                    if self.logic_rules != 'none':
                        self.parser.parse_spot_rule(new_exit)
                    new_region.exits.append(new_exit)
            self.regions.append(new_region)
Exemple #3
0
 def load_regions_from_json(self, file_path):
     region_json = read_json(file_path)
         
     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']
             new_region.provides_time = TimeOfDay.ALL
         if new_region.name == 'Ganons Castle Grounds':
             new_region.provides_time = TimeOfDay.DAMPE
         if 'locations' in region:
             for location, rule in region['locations'].items():
                 new_location = LocationFactory(location)
                 new_location.parent_region = new_region
                 new_location.rule_string = rule
                 if self.logic_rules != 'none':
                     self.parser.parse_spot_rule(new_location)
                 if new_location.never:
                     # We still need to fill the location even if ALR is off.
                     logging.getLogger('').debug('Unreachable location: %s', new_location.name)
                 new_location.world = self
                 new_region.locations.append(new_location)
         if 'events' in region:
             for event, rule in region['events'].items():
                 # Allow duplicate placement of events
                 lname = '%s from %s' % (event, new_region.name)
                 new_location = Location(lname, type='Event', parent=new_region)
                 new_location.rule_string = rule
                 if self.logic_rules != 'none':
                     self.parser.parse_spot_rule(new_location)
                 if new_location.never:
                     logging.getLogger('').debug('Dropping unreachable event: %s', new_location.name)
                 else:
                     new_location.world = self
                     new_region.locations.append(new_location)
                     MakeEventItem(event, 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
                 new_exit.rule_string = rule
                 if self.logic_rules != 'none':
                     self.parser.parse_spot_rule(new_exit)
                 if new_exit.never:
                     logging.getLogger('').debug('Dropping unreachable exit: %s', new_exit.name)
                 else:
                     new_region.exits.append(new_exit)
         self.regions.append(new_region)
Exemple #4
0
    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)