def run(self): self.current_floor = None # Initialize pygame system stuff pygame.init() update_notifier = self.check_for_update() pygame.display.set_caption("Rebirth Item Tracker" + update_notifier) # Create drawing tool to use to draw everything - it'll create its own screen self.drawing_tool = DrawingTool() os.environ['SDL_VIDEO_WINDOW_POS'] = "%d, %d" % ( self.drawing_tool.options[Option.X_POSITION], self.drawing_tool.options[Option.Y_POSITION]) self.drawing_tool.start_pygame() pygame.display.set_icon(self.drawing_tool.get_image("collectibles_333.png")) done = False clock = pygame.time.Clock() winInfo = None if platform.system() == "Windows": winInfo = pygameWindowInfo.PygameWindowInfo() del os.environ['SDL_VIDEO_WINDOW_POS'] while not done: # pygame logic for event in pygame.event.get(): if event.type == pygame.QUIT: if platform.system() == "Windows": winPos = winInfo.getScreenPosition() self.drawing_tool.options[Option.X_POSITION] = winPos["left"] self.drawing_tool.options[Option.Y_POSITION] = winPos["top"] self.drawing_tool.save_options() done = True elif event.type == VIDEORESIZE: screen = pygame.display.set_mode(event.dict['size'], RESIZABLE) self.drawing_tool.options[Option.WIDTH] = event.dict["w"] self.drawing_tool.options[Option.HEIGHT] = event.dict["h"] self.drawing_tool.save_options() self.drawing_tool.reflow(self.collected_items) pygame.display.flip() elif event.type == MOUSEMOTION: if pygame.mouse.get_focused(): pos = pygame.mouse.get_pos() self.drawing_tool.select_item_on_hover(*pos) elif event.type == KEYDOWN: if len(self.collected_items) > 0: if event.key == pygame.K_RIGHT: self.drawing_tool.adjust_select_item_on_keypress(1) elif event.key == pygame.K_LEFT: self.drawing_tool.adjust_select_item_on_keypress(-1) elif event.key == pygame.K_RETURN: self.drawing_tool.load_selected_detail_page() elif event.key == pygame.K_c and pygame.key.get_mods() & pygame.KMOD_CTRL: pass #self.generate_run_summary() # This is commented out because run summaries are broken with the new "state" model rewrite of the item tracker elif event.type == MOUSEBUTTONDOWN: if event.button == 1: self.drawing_tool.load_selected_detail_page() if event.button == 3: import option_picker pygame.event.set_blocked([QUIT, MOUSEBUTTONDOWN, KEYDOWN, MOUSEMOTION]) option_picker.options_menu(self.file_prefix + "options.json").run() pygame.event.set_allowed([QUIT, MOUSEBUTTONDOWN, KEYDOWN, MOUSEMOTION]) self.drawing_tool.reset() self.drawing_tool.load_options() self.drawing_tool.reflow(self.collected_items) # Drawing logic clock.tick(int(self.drawing_tool.options[Option.FRAMERATE_LIMIT])) if self.log_not_found: self.drawing_tool.write_message("log.txt not found. Put the RebirthItemTracker folder inside the isaac folder, next to log.txt") self.drawing_tool.draw_items(self) self.framecount += 1 # Now we re-process the log file to get anything that might have loaded; do it every read_delay seconds (making sure to truncate to an integer or else it might never mod to 0) if self.framecount % int(self.drawing_tool.options[Option.FRAMERATE_LIMIT] * self.read_delay) == 0: self.load_log_file() self.splitfile = self.content.splitlines() # Return to start if seek passes the end of the file (usually because the log file restarted) if self.seek > len(self.splitfile): self.log_msg("Current line number longer than lines in file, returning to start of file", "D") self.seek = 0 should_reflow = False getting_start_items = False # This will become true if we are getting starting items # Process log's new output for current_line_number, line in enumerate(self.splitfile[self.seek:]): self.log_msg(line, "V") # The end floor boss should be defeated now if line.startswith('Mom clear time:'): kill_time = int(line.split(" ")[-1]) # If you re-enter a room you get a "mom clear time" again, check for that (can you fight the same boss twice?) if self.current_room not in [x[0] for x in self.bosses]: self.bosses.append((self.current_room, kill_time)) self.log_msg( "Defeated %s%s boss %s at time %s" % (len(self.bosses), self.suffix(len(self.bosses)), self.current_room, kill_time), "D") # Check and handle the end of the run; the order is important - we want it after boss kill but before "RNG Start Seed" self.check_end_run(line, current_line_number + self.seek) if line.startswith('RNG Start Seed:'): # The start of a run self.seed = line[16:25] # This assumes a fixed width, but from what I see it seems safe if line.startswith('Room'): self.current_room = re.search('\((.*)\)', line).group(1) if 'Start Room' not in line: getting_start_items = False self.log_msg("Entered room: %s" % self.current_room,"D") if line.startswith('Level::Init'): if self.GAME_VERSION == "Afterbirth": floor_tuple = tuple([re.search("Level::Init m_Stage (\d+), m_StageType (\d+)",line).group(x) for x in [1, 2]]) else: floor_tuple = tuple([re.search("Level::Init m_Stage (\d+), m_AltStage (\d+)",line).group(x) for x in [1, 2]]) # Assume floors aren't cursed until we see they are self.blind_floor = False getting_start_items = True floor = int(floor_tuple[0]) alt = floor_tuple[1] # Special handling for cath and chest if alt == '1' and (floor == 9 or floor == 11): floor += 1 floor_id = 'f' + str(floor) # when we see a new floor 1, that means a new run has started if floor == 1: self.start_new_run(current_line_number) self.current_floor=Floor(floor_id,self,(alt=='1')) should_reflow = True if line.startswith("Curse of the Labyrinth!"): # It SHOULD always begin with f (that is, it's a floor) because this line only comes right after the floor line self.current_floor.add_curse(Curse.Labyrinth) if line.startswith("Curse of Blind"): self.current_floor.add_curse(Curse.Blind) if line.startswith("Curse of the Lost!"): self.current_floor.add_curse(Curse.Lost) if line.startswith("Spawn co-player!"): self.spawned_coop_baby = current_line_number + self.seek if re.search("Added \d+ Collectibles", line): self.log_msg("Reroll detected!", "D") map(lambda item: item.rerolled(),self.collected_items) if line.startswith('Adding collectible'): if len(self.splitfile) > 1 and self.splitfile[current_line_number + self.seek - 1] == line: self.log_msg("Skipped duplicate item line from baby presence", "D") continue space_split = line.split(" ") # Hacky string manipulation item_id = space_split[2] # A string has the form of "Adding collectible 105 (The D6)" # Check if the item ID exists if item_id.zfill(3) not in self.items_info: item_id = "NEW" item_info = self.get_item_info(item_id) # Default current floor to basement 1 if none if self.current_floor is None: self.current_floor = Floor("f1", self, False) # If the item IDs are equal, it should say this item already exists temp_item = Item(item_id,self.current_floor,item_info,getting_start_items) if ((current_line_number + self.seek) - self.spawned_coop_baby) < (len(self.collected_items) + 10) \ and temp_item in self.collected_items: self.log_msg("Skipped duplicate item line from baby entry","D") continue item_name = " ".join(space_split[3:])[1:-1] self.log_msg("Picked up item. id: %s, name: %s" % (item_id, item_name), "D") with open(self.file_prefix + "overlay text/itemInfo.txt", "w+") as f: desc = temp_item.generate_item_description() f.write(item_info[ItemProperty.NAME] + ":" + desc) # Ignore repeated pickups of space bar items if not (item_info.get(ItemProperty.SPACE,False) and temp_item in self.collected_items): self.collected_items.append(temp_item) self.item_message_start_time = self.framecount self.item_pickup_time = self.framecount self.drawing_tool.item_picked_up() else: self.log_msg("Skipped adding item %s to avoid space-bar duplicate" % item_id, "D") self.add_stats_for_item(temp_item, item_id) should_reflow = True self.seek = len(self.splitfile) if should_reflow: self.drawing_tool.reflow(self.collected_items)