--[[ DYNAMIC ZONE Original Author(s) Singustromo Edited by License Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0) Lazy monkey patches that overwrite those functions completely --]] -- main script functors and variables are accessed through this variable parent = _G["dynamic_zone"] if not (parent and parent.VERSION and parent.VERSION >= 20240120) then return end -------------------------- -- Dependencies -------------------------- local opt = dynamic_zone_mcm local utils = dynamic_zone_utils local debug = dynamic_zone_debug local route_manager = dynamic_zone_routes local discovery = dynamic_zone_discovery CONST_LOGGING_PREFIX = "TXR-Routes" local log = debug.log_register("info", CONST_LOGGING_PREFIX) local log_error = debug.log_register("error", CONST_LOGGING_PREFIX) ------------------------------- -- Patched Functions ------------------------------- ReloadRouteHints = txr_routes.reload_route_hints OpenRoute = txr_routes.open_route ----------------------------- -- Monkey patches ----------------------------- -- Let's make sure we update the transition mapspots and use our hint -- This is executed undermost on_game_load and is used -- to ensure that the spot hints adhere to set localization function txr_routes.reload_route_hints() if (utils.debug_level_loaded()) then return end log("Running patched txr_routes.reload_route_hints()") -- This function is actually called before our parent.main_routine() -- We just do this for a new game, so that we can leverage our logic here if (route_manager.route_count() < 1) then log("reload_route_hints | Populating route list") parent.register_game_routes() parent.update_game_route_properties() end log("reload_route_hints | Updating transition mapspots") local include_blacklisted = true for route_id, route in route_manager.iterate_routes(include_blacklisted) do for name, _ in route_manager.iterate_transitions(route_id) do discovery.update_transition_mapspot(name, nil, not route.block_discovered) end end end -- Prevents txr_routes from overwriting our map icons when a route is unlocked -- (e.g. Debug: Unlock all) -- Overwrote this in it's entirety because the changes needed, require it. function txr_routes.open_route(map_1, map_2, no_msg) local a = txr_routes.get_route(map_1, map_2) -- all space_restrictors between those two if (utils.assert_failed(a, "Got no route between %s and %s", map_1, map_2)) then return end local msg for _, transition in pairs(a) do local id, spot, hint = txr_routes.get_route_info(transition) if utils.assert_failed(id and spot and hint) then log_error("Unknown restrictor: %s (Defined in txr_routes.routes)", transition) return -- prevent possible crash end local route = route_manager.get_route_by_transition(transition) if utils.assert_failed(route, "Can not get a route ID with '%s' as a member!", transition) then goto continue elseif (route.block_discovered) then goto continue end if utils.map_spot_exists(id, spot) then log("Map spot for transition '%s' already exists!", transition) goto continue end hint = hint and game.translate_string(hint) level.map_add_object_spot_ser(id, spot, hint) mlr_utils.save_var("routes_".. transition, true) txr_routes.register_map(map_1, map_2) msg = true ::continue:: route.unlocked = true discovery.update_transition_mapspot(transition) end if msg and (not no_msg) then txr_routes.msg_route(map_1, map_2) end end