Files
LonaRPG-Online-Games/ModScripts/_Mods/LonaCraft/Scripts/98_SelfTest.rb
T

1576 lines
85 KiB
Ruby
Raw Normal View History

2026-10-29 21:59:06 +04:00
#==============================================================================
# LonaCraft - 98_SelfTest.rb
# What it does:
# * A start-up self-test that finds what a game update (or a broken edit of
# the mod) broke: game methods LonaCraft hooks or calls, game data it names
# (items, NPCs, EventLib events, shops, pictures, tilesets, maps, scripts),
# the mod's own data (text keys, JSON files, item ids, fixed town tiles,
# save registry, loader order) and a few safe runtime results (recipes per
# station, tier variants, the config defaults writers).
# * Runs once per game start, at DataManager.load_mod_database after every
# LonaCraft part has loaded its data (this file loads last, so its alias is
# the outer one), and only when Config/LonaCraft.json has "debug": true and
# "self_test": true (05_Config.rb).
# * Each check gives pass / fail / skip with a one-line reason and never
# raises: a check that crashes is a failure with the exception text. Skip =
# not applicable here (a part switched off, a mod not loaded, a packed
# game without loose files); skips are not counted in M.
# * Writes the report to "self_test_log" (default
# UserData/LonaCraft_selftest.log, overwritten each start, UTF-8): date,
# game version, mod version, mod load order, LonaCraft's script order, the
# failures, then every check. On any failure: one message box
# "LonaCraft self-test: N of M checks failed. See <log path>." and one
# console line per failure; otherwise one console line.
# * Kept under about a second: no map is drawn; load_data only of the game
# maps with checked tiles or events (2, 43, 59, 62, once each) and of the
# mod's own maps.
# Adding a check: add one row to a table below (METHODS, INPUT_KEYS,
# SETTINGS, GLOBALS, ITEM_LISTS, EVENTLIB_LISTS, MAPS, MAP_EVENTS, TILESETS,
# GAME_FILES, LOAD_ORDER); the "where" column says where the expectation comes
# from. A new kind of check is one more check(group, name){ ... } in
# run_checks: the block returns nil or true (pass), a String (fail, the
# reason), skip("why") (skip) or note("text") (pass with a note).
# Arity (Ruby): n = exactly n arguments, -(n+1) = n required plus optional
# ones or *args. A changed arity still passes (with a note) when the method
# takes every call it took before (fewer required, optional or *args added).
# Keep this file plain ASCII (the game evaluates it as binary text).
#==============================================================================
module LonaCraft
module SelfTest
#----------------------------------------------------------------------
# 1. Game methods: [owner, :i instance / :s module method, name,
# arity in B.0.10.8.26, where]. For a hook the row names the saved
# original (the alias LonaCraft made): missing = the hook is not
# installed (the guard found no game method); the arity is the game's.
#----------------------------------------------------------------------
METHODS = [
# Game_Map
["Game_Map", :i, :setup_lonacraft_furniture, 1, "31_Game_Map.rb:159 setup(map_id), 90_Furniture.rb hook"],
["Game_Map", :i, :setup_lonacraft_homes, 1, "31_Game_Map.rb:159, 100_Homes.rb hook"],
["Game_Map", :i, :setup_lonacraft_bases, 1, "31_Game_Map.rb:159, 110_Bases.rb hook"],
["Game_Map", :i, :setup_lonacraft_raids, 1, "31_Game_Map.rb:159, 120_Raids.rb hook (raid end; 2026-10-08 leave_check before the setup)"],
["Game_Map", :i, :setup_lonacraft_away, 1, "31_Game_Map.rb:159, 140_AwayRaids.rb hook (entry report)"],
["Game_Map", :i, :setup_lonacraft_mercs, 1, "31_Game_Map.rb:159, 150_Mercs.rb hook (the squad)"],
["Game_Map", :i, :storypoint_map, 0, "31_Game_Map.rb attr_reader, 150_Mercs.rb post tiles"],
["Game_Map", :i, :setup_event_hack_lonacraft_furniture, 0, "31_Game_Map.rb:223 setup_event_hack, 90_Furniture.rb hook"],
["Game_Map", :i, :setup_event_hack_lonacraft_homes, 0, "31_Game_Map.rb:223, 100_Homes.rb hook"],
["Game_Map", :i, :setup_event_hack_lonacraft_bases, 0, "31_Game_Map.rb:223, 110_Bases.rb hook"],
["Game_Map", :i, :reset_events_lonacraft_stale, 0, "31_Game_Map.rb:359 reset_events, 90_Furniture.rb hook"],
["Game_Map", :i, :setup_region_map_lonacraft_bases, 0, "31_Game_Map.rb:270 setup_region_map, 110_Bases.rb hook"],
["Game_Map", :i, :reserve_summon_event_lonacraft, -2, "31_Game_Map.rb:1243 reserve_summon_event, 40_Mining.rb hook"],
["Game_Map", :i, :lonacraft_raids_map_nap, -1, "70_Game_Map_DayNightAndOvermap.rb:13 nap, 120_Raids.rb hook"],
["Game_Map", :i, :lonacraft_raids_call_nap_event, 0, "31_Game_Map.rb:1305 call_nap_event, 120_Raids.rb hook"],
["Game_Map", :i, :summon_event, -2, "31_Game_Map.rb:1237, 130_Sewer.rb population"],
["Game_Map", :i, :popup, 4, "200_Galv_Event_Popup.rb:84, 95_Debug.rb say"],
["Game_Map", :i, :layered_tiles, 2, "31_Game_Map.rb:752, 90_Furniture.rb lonacraft_layer_pass?"],
["Game_Map", :i, :valid?, 2, "31_Game_Map.rb:714, 90_Furniture.rb lonacraft_town_tile_free?"],
["Game_Map", :i, :region_id, 2, "31_Game_Map.rb:880, 110_Bases.rb"],
["Game_Map", :i, :tileset, 0, "31_Game_Map.rb:470, 90_Furniture.rb"],
["Game_Map", :i, :region_map, 0, "31_Game_Map.rb:44 attr_reader, 110_Bases.rb"],
["Game_Map", :i, :storypoint_map, 0, "31_Game_Map.rb:43 attr_reader, 100_Homes.rb"],
["Game_Map", :i, :isOverMap, 0, "31_Game_Map.rb:35 attr_reader, 110_Bases.rb"],
["Game_Map", :i, :threat, 0, "31_Game_Map.rb:42 attr_accessor, 120_Raids.rb"],
# Game_Interpreter and GIM_ADDON (34_Functions_*.rb, included at 40_Game_Interpreter.rb:19)
["Game_Interpreter", :i, :show_npc_info_lonacraft_homes, -2, "29_Functions_417_Interpreter.rb:455 show_npc_info, 100_Homes.rb hook"],
["Game_Interpreter", :i, :call_msg_lonacraft_homes, -2, "29_Functions_417_Interpreter.rb:202 call_msg, 100_Homes.rb hook"],
["Game_Interpreter", :i, :call_msg_lonacraft_bases, -2, "29_Functions_417_Interpreter.rb:202 call_msg, 110_Bases.rb hook (Rename base on the tile menu)"],
["Window_NameEdit", :i, :initialize, 2, "78_Window_NameEdit.rb:17, 110_Bases.rb base names"],
["Window_NameInput", :i, :initialize, 1, "79_Window_NameInput.rb:64, 110_Bases.rb base names"],
["SceneManager", :s, :call, 1, "6_SceneManager.rb, 110_Bases.rb name-entry screen"],
["Game_Interpreter", :i, :call_msg_lonacraft_mercs, -2, "29_Functions_417_Interpreter.rb:202 call_msg, 150_Mercs.rb hook (guild menu line)"],
["Game_Interpreter", :i, :optain_lose_item, -2, "29_Functions_417_Interpreter.rb:386, 150_Mercs.rb payment"],
["Game_Interpreter", :i, :doorEV_setup, -1, "29_Functions_417_Interpreter.rb:943, 110_Bases.rb doors"],
["Game_Interpreter", :i, :common_pickup_item, -2, "29_Functions_417_Interpreter.rb:861, 45_Nodes.rb loose stone"],
["Game_Interpreter", :i, :darkPot_translate_recipe, 3, "29_Functions_DarkPot.rb:292, 20_Station.rb salvage"],
["Object", :i, :load_script, 1, "102_ScriptImport.rb:61, 40_Mining.rb override calls super"],
["GIM_ADDON", :i, :enter_static_region_map, -1, "34_Functions_ChangeMap.rb:104, 45_Nodes.rb override calls super"],
["GIM_ADDON", :i, :lonacraft_bases_change_map_enter_region, 0, "34_Functions_ChangeMap.rb:257 change_map_enter_region, 110_Bases.rb hook"],
["GIM_ADDON", :i, :lonacraft_raids_nap_stats, 0, "34_Functions_RegionMap.rb:237 region_map_wildness_nap_stats, 120_Raids.rb hook"],
["GIM_ADDON", :i, :lonacraft_raids_race_list, 0, "34_Functions_RegionMap.rb:248 region_map_wildness_nap_stats_create_race_list, 120_Raids.rb hook"],
["GIM_ADDON", :i, :lonacraft_raids_spawn, -1, "34_Functions_RegionMap.rb:361 region_map_wildness_spawn, 120_Raids.rb hook"],
["GIM_ADDON", :i, :lonacraft_raids_wildness_nap, -1, "34_Functions_RegionMap.rb:1645 region_map_wildness_nap, 120_Raids.rb hook"],
# Text (the game's translation table)
["Text", :i, :lonacraft_text_fb_orig, -2, "121_Dialog_Control_System.rb:98 Text#[], 15_Text.rb hook"],
["Text", :i, :lonacraft_text_fb_load_orig, -2, "121_Dialog_Control_System.rb:113 Text#load_file, 15_Text.rb hook"],
["Text", :i, :lonacraft_tier_text_orig, -2, "15_Text.rb Text#[] (key, noError = false), 50_Tiers.rb hook"],
["Text", :i, :parse, 1, "121_Dialog_Control_System.rb:123, 15_Text.rb TextFallback"],
# Game_Party, Game_Date
["Game_Party", :i, :has_item_lonacraft_homes?, -2, "29_Game_Party.rb:303 has_item?, 100_Homes.rb hook"],
["Game_Party", :i, :lose_item_lonacraft_homes, -2, "29_Game_Party.rb:384 lose_item, 100_Homes.rb hook"],
["Game_Party", :i, :item_number, 1, "29_Game_Party.rb:282, 30_Process.rb / 55_Recipes.rb"],
["Game_Party", :i, :gain_item, -2, "29_Game_Party.rb:363, 55_Recipes.rb / 95_Debug.rb"],
["Game_Date", :i, :shift_lonacraft_homes, 0, "123_Game_Date.rb:198 shift, 100_Homes.rb hook"],
["Game_Date", :i, :addDays_lonacraft_homes, -2, "123_Game_Date.rb:221 addDays, 100_Homes.rb hook"],
["Game_Date", :i, :oneDayForward_lonacraft_homes, -1, "123_Game_Date.rb:138 oneDayForward, 100_Homes.rb hook"],
["Game_Date", :i, :shift_lonacraft_away, 0, "123_Game_Date.rb:198 shift, 140_AwayRaids.rb hook"],
["Game_Date", :i, :addDays_lonacraft_away, -2, "123_Game_Date.rb:221 addDays, 140_AwayRaids.rb hook"],
["Game_Date", :i, :oneDayForward_lonacraft_away, -1, "123_Game_Date.rb:138 oneDayForward, 140_AwayRaids.rb hook"],
["Game_Date", :i, :shift_lonacraft_mercs, 0, "123_Game_Date.rb:198 shift, 150_Mercs.rb hook"],
["Game_Date", :i, :addDays_lonacraft_mercs, -2, "123_Game_Date.rb:221 addDays, 150_Mercs.rb hook"],
["Game_Date", :i, :oneDayForward_lonacraft_mercs, -1, "123_Game_Date.rb:138 oneDayForward, 150_Mercs.rb hook"],
# Scenes and menus
["Scene_Menu", :i, :lonacraft_menu_create_contents, 1, "170_menu_base.rb:111 create_contents, 85_MenuCraft.rb hook"],
["Scene_Menu", :i, :lonacraft_menu_create_menu, 1, "170_menu_base.rb:107 create_menu, 85_MenuCraft.rb hook"],
["Scene_Map", :i, :start_lonacraft_skill, 0, "102_00_Scene_Map.rb:19 start, 60_Skill.rb hook"],
["Scene_Map", :i, :update_lonacraft_homes, 0, "102_00_Scene_Map.rb:76 update, 100_Homes.rb hook"],
["Scene_Map", :i, :update_lonacraft_bases, 0, "102_00_Scene_Map.rb:76 update, 110_Bases.rb hook"],
["Scene_Map", :i, :update_lonacraft_raids, 0, "102_00_Scene_Map.rb:76 update, 120_Raids.rb hook"],
["Scene_Map", :i, :update_lonacraft_away, 0, "102_00_Scene_Map.rb:76 update, 140_AwayRaids.rb hook"],
["Scene_Map", :i, :update_lonacraft_mercs, 0, "102_00_Scene_Map.rb:76 update, 150_Mercs.rb hook"],
["Scene_Map", :i, :lonacraft_debug_update, 0, "102_00_Scene_Map.rb:76 update, 95_Debug.rb hook"],
["Menu_System", :i, :create_sprites_lonacraft_bases, 0, "194_menu_08_0_System.rb:67 create_sprites, 110_Bases.rb hook"],
["Menu_System", :i, :update_input_lonacraft_bases, 0, "194_menu_08_0_System.rb:487 update_input, 110_Bases.rb hook"],
["Menu_System", :i, :mouse_update_input_lonacraft_bases, 0, "194_menu_08_0_System.rb:502 mouse_update_input, 110_Bases.rb hook"],
["Menu_System", :i, :mouse_force_main_menu_pause_lonacraft_bases, 0, "194_menu_08_0_System.rb:909 mouse_force_main_menu_pause, 110_Bases.rb hook"],
["Menu_System", :i, :dispose_lonacraft_bases, 0, "194_menu_08_0_System.rb:922 dispose, 110_Bases.rb hook"],
["Window_ChoiceList", :i, :draw_selected_item_lonacraft_homes, 0, "80_Window_ChoiceList.rb:183 draw_selected_item, 100_Homes.rb hook"],
# Characters
["Game_Event", :i, :lonacraft_raids_self_movement, 0, "39_Game_Event.rb:962 update_self_movement, 120_Raids.rb hook"],
["Game_Actor", :i, :process_nap_change_lonacraft_rest, 0, "97_Game_Actor_Stats&State&Nap.rb:63 process_nap_change, 160_Rest.rb hook"],
["Game_Actor", :i, :batch_take_bath, -1, "480_GameActorBatch.rb:4, 160_Rest.rb bath"],
["Game_Actor", :i, :attr_dimensions, 0, "25_Game_Actor.rb:1444, 160_Rest.rb restore"],
["Game_Actor", :i, :take_damage_lonacraft_god, -3, "Modules/BattleSystem.rb:495 take_damage (RolePlayS replaces it in its own BattleSystem script, line 38), 95_Debug.rb god mode hook"],
["Game_Actor", :i, :process_nap_change_lonacraft_god, -1, "97_Game_Actor_Stats&State&Nap.rb:63 process_nap_change as 160_Rest.rb wraps it (*args), 95_Debug.rb god mode hook"],
["Game_Actor", :i, :battle_stat, 0, "25_Game_Actor.rb:1531, 95_Debug.rb god top-up"],
["Game_Actor", :i, :prev_health=, 1, "25_Game_Actor.rb:60 attr_accessor, 95_Debug.rb god top-up"],
["Game_Actor", :i, :prev_sta=, 1, "25_Game_Actor.rb:61 attr_accessor, 95_Debug.rb god top-up"],
["Game_Actor", :i, :health=, 1, "94_Game_Actor_Stats.rb:386, 95_Debug.rb god top-up"],
["Game_Actor", :i, :sta=, 1, "94_Game_Actor_Stats.rb:389, 95_Debug.rb god top-up"],
["Game_Actor", :i, :sat=, 1, "94_Game_Actor_Stats.rb:390, 95_Debug.rb god top-up"],
["ActorStat", :i, :get_stat, -2, "280_Actor&NPC_Stat_root.rb:69 get_stat(stat_name, type), 95_Debug.rb god top-up (MAX_STAT 2)"],
["GIM_OM", :i, :handleNap_lonacraft_rest, -1, "Game_Interpreter_Modifies_OM.rb:12 handleNap, 160_Rest.rb hook"],
["Game_Map", :i, :call_nap_event_lonacraft_rest, 0, "31_Game_Map.rb:1305 call_nap_event, 160_Rest.rb hook"],
["GIM_ADDON", :i, :lonacraft_rest_nap_stats, 0, "34_Functions_RegionMap.rb:237 region_map_wildness_nap_stats, 160_Rest.rb hook"],
["Game_Interpreter", :i, :lonacraft_furniture_action_rest, 3, "90_Furniture.rb lonacraft_furniture_action, 160_Rest.rb hook"],
["Game_Map", :i, :setup_lonacraft_maid, 1, "31_Game_Map.rb:159, 170_Maid.rb hook (the maid)"],
["Game_Event", :i, :lonacraft_maid_self_movement, 0, "39_Game_Event.rb:962 update_self_movement, 170_Maid.rb hook"],
["Scene_Map", :i, :update_lonacraft_maid, 0, "102_00_Scene_Map.rb:76 update, 170_Maid.rb hook"],
["Game_Date", :i, :shift_lonacraft_maid, 0, "123_Game_Date.rb:198 shift, 170_Maid.rb hook (wages, cooking)"],
["Game_NonPlayerCharacter", :i, :process_death_lonacraft_maid, 0, "281_Game_NonPlayerCharacter.rb:797 process_death, 170_Maid.rb hook"],
["DataManager", :s, :load_mod_database_lonacraft_maid, 0, "5_DataManager.rb:224, 170_Maid.rb hook (NPC data)"],
["Npc_RunAway", :i, :get_move_command, 0, "4003_Npc_RunAway.rb:13, 170_Maid.rb Npc_LonaCraftMaid"],
["Game_Event", :i, :lonacraft_mercs_self_movement, 0, "39_Game_Event.rb:962 update_self_movement, 150_Mercs.rb hook"],
["Game_Event", :i, :move_toward_xy, -3, "39_Game_Event.rb:1925, 150_Mercs.rb walk back to post"],
["Game_Event", :i, :nappable=, 1, "39_Game_Event.rb:53 attr_accessor, 90_Furniture.rb"],
["Game_Event", :i, :foreign_event, 0, "39_Game_Event.rb:61 attr_accessor, 90_Furniture.rb / 100_Homes.rb"],
["Game_Event", :i, :foreign_event=, 1, "39_Game_Event.rb:61 attr_accessor, 90_Furniture.rb"],
["Game_Event", :i, :summon_data, 0, "39_Game_Event.rb:52 attr_reader, 110_Bases.rb / 120_Raids.rb"],
["Game_Player", :i, :check_action_event_lonacraft_bases, -1, "35_Game_Player.rb:604 check_action_event, 110_Bases.rb hook"],
["Game_NonPlayerCharacter", :i, :master, 0, "281_Game_NonPlayerCharacter.rb:57 attr_accessor, 110_Bases.rb / 120_Raids.rb"],
["Game_NonPlayerCharacter", :i, :master=, 1, "281_Game_NonPlayerCharacter.rb:57 attr_accessor, 150_Mercs.rb squad init"],
["Game_NonPlayerCharacter", :i, :fraction_mode=, 1, "281_Game_NonPlayerCharacter.rb, 150_Mercs.rb squad init (as setup_follower_summoned)"],
# 2026-10-08: hostiles siege the base (120_Raids.rb), building blocked only by hostiles (110_Bases.rb)
["Game_Event", :i, :lonacraft_raids_npc_sensor, 0, "39_Game_Event.rb:698 update_npc_sensor, 120_Raids.rb hook (siege units keep their target)"],
["Game_NonPlayerCharacter", :i, :target, 0, "281_Game_NonPlayerCharacter.rb:11 attr_reader, 120_Raids.rb / 110_Bases.rb"],
["Game_NonPlayerCharacter", :i, :targetLock_HP, 0, "281_Game_NonPlayerCharacter.rb:77 attr_accessor, 120_Raids.rb hold_target"],
["Game_NonPlayerCharacter", :i, :targetLock_HP=, 1, "281_Game_NonPlayerCharacter.rb:77 attr_accessor, 120_Raids.rb hold_target (sense_target :456-463)"],
["Game_NonPlayerCharacter", :i, :ai_state, 0, "281_Game_NonPlayerCharacter.rb:15 attr_accessor, 120_Raids.rb / 110_Bases.rb (:flee)"],
["Game_NonPlayerCharacter", :i, :check_ai_state, 4, "281_Game_NonPlayerCharacter.rb:710 check_ai_state, 110_Bases.rb would_attack_lona? (as 35_Game_Player.rb:355)"],
["Game_NonPlayerCharacter", :i, :friendly?, 1, "281_Game_NonPlayerCharacter.rb:1025 friendly?, 110_Bases.rb would_attack_lona?"],
["Game_NonPlayerCharacter", :i, :race, 0, "281_Game_NonPlayerCharacter.rb:1283 race (NPCdata race), 110_Bases.rb animal? / 120_Raids.rb"],
["Game_NonPlayerCharacter", :i, :npc_name, 0, "281_Game_NonPlayerCharacter.rb:14 attr_reader, 110_Bases.rb animal? (Wild*) / 120_Raids.rb trace"],
["Game_NonPlayerCharacter", :i, :is_object, 0, "281_Game_NonPlayerCharacter.rb:39 attr_accessor, 110_Bases.rb / 120_Raids.rb"],
["Game_NonPlayerCharacter", :i, :sta, 0, "281_Game_NonPlayerCharacter.rb:246 sta, 110_Bases.rb blocking_hostile"],
# 2026-10-08: leaving during a raid hands the units up to the away raid (120_Raids.rb leave_unit)
["Game_NonPlayerCharacter", :i, :health, 0, "281_Game_NonPlayerCharacter.rb:247 health, 120_Raids.rb leave_unit (away power)"],
["Game_NonPlayerCharacter", :i, :atk, 0, "281_Game_NonPlayerCharacter.rb:248 atk, 120_Raids.rb atk_of / leave_unit"],
["Game_NonPlayerCharacter", :i, :ranged?, 0, "281_Game_NonPlayerCharacter.rb:1164 ranged?, 120_Raids.rb role / leave_unit"],
# 2026-10-08: the mercenaries hunt every foe on the map and Lona's victims (150_Mercs.rb engage)
["Game_NonPlayerCharacter", :i, :set_last_attacker_lonacraft_mercs, 1, "281_Game_NonPlayerCharacter.rb:874 set_last_attacker, 150_Mercs.rb hook (NPCs Lona hits)"],
["Game_NonPlayerCharacter", :i, :set_aggro, -3, "281_Game_NonPlayerCharacter.rb:1256 set_aggro, 150_Mercs.rb hold (target, alert 2, aggro frames)"],
["Game_NonPlayerCharacter", :i, :aggro_frame, 0, "281_Game_NonPlayerCharacter.rb:54 attr_reader, 150_Mercs.rb hold (@aggro_frame topped up)"],
["Game_NonPlayerCharacter", :i, :update_aggro_frame, 0, "281_Game_NonPlayerCharacter.rb:1220 update_aggro_frame, 150_Mercs.rb (aggro 0 = target lost)"],
["Game_NonPlayerCharacter", :i, :sense_target, -2, "281_Game_NonPlayerCharacter.rb:417 sense_target, 150_Mercs.rb (aggro holds an unseen target, :451)"],
["Game_NonPlayerCharacter", :i, :killer?, 2, "281_Game_NonPlayerCharacter.rb:731 killer? (aggro = killer), 150_Mercs.rb engage"],
["Game_NonPlayerCharacter", :i, :set_killer_skill, 1, "281_Game_NonPlayerCharacter.rb:904 set_killer_skill (process_killer), 150_Mercs.rb engage"],
["Game_NonPlayerCharacter", :i, :process_target_lost, -1, "281_Game_NonPlayerCharacter.rb:490 process_target_lost, 150_Mercs.rb engage (a foe it cannot reach)"],
["Game_NonPlayerCharacter", :i, :action_state, 0, "281_Game_NonPlayerCharacter.rb:13 attr_reader, 150_Mercs.rb idle? / foe_alive?"],
["Game_NonPlayerCharacter", :i, :npc_dead?, 0, "281_Game_NonPlayerCharacter.rb:857 npc_dead?, 150_Mercs.rb foe_alive? / 110_Bases.rb"],
["Game_NonPlayerCharacter", :i, :event, 0, "281_Game_NonPlayerCharacter.rb:45 attr_accessor, 150_Mercs.rb lona_hit"],
["Game_NonPlayerCharacter", :i, :user_redirect, 0, "281_Game_NonPlayerCharacter.rb:56 attr_accessor, 150_Mercs.rb hold (set_aggro :1264 aims at the user)"],
["Npc_CompanionCharge", :i, :get_move_command, 0, "4000_Npc_CompanionCharge.rb:9 (to the target: move_toward_TargetSmartAI), 150_Mercs.rb squad AI"],
["Game_Event", :i, :move_toward_TargetSmartAI, -2, "39_Game_Event.rb:1282 move_toward_TargetSmartAI, 150_Mercs.rb squad walk to a foe (the game's AI)"],
# DataManager, Cache, libraries
["DataManager", :s, :load_mod_database_LonaCraft, 0, "5_DataManager.rb:224 load_mod_database, 0_Core.rb hook"],
["DataManager", :s, :load_mod_database_lonacraft_nodes, 0, "5_DataManager.rb:224, 45_Nodes.rb hook"],
["DataManager", :s, :load_mod_database_lonacraft_homes, 0, "5_DataManager.rb:224, 100_Homes.rb hook"],
["DataManager", :s, :load_mod_database_lonacraft_mercs, 0, "5_DataManager.rb:224, 150_Mercs.rb hook (squad NPC data)"],
["NonPlayerCharacter::Data_NPC", :s, :load_from_json, 1, "Modules/NonPlayerCharacter.rb:94, 150_Mercs.rb load_npcs"],
["JSON", :s, :decode, 1, "101_jsonEnDecoder.rb:69, 150_Mercs.rb load_npcs"],
["DataManager", :s, :load_mod_database_lonacraft_selftest, 0, "5_DataManager.rb:224, 98_SelfTest.rb hook"],
["DataManager", :s, :make_save_contents_lonacraft, 0, "5_DataManager.rb:929 make_save_contents, 70_Save.rb hook"],
["DataManager", :s, :extract_save_contents_lonacraft, 1, "5_DataManager.rb:954 extract_save_contents, 70_Save.rb hook"],
["DataManager", :s, :extract_save_contents_lonacraft_bases, 1, "5_DataManager.rb:954, 110_Bases.rb hook"],
["DataManager", :s, :extract_save_contents_lonacraft_raids, 1, "5_DataManager.rb:954, 120_Raids.rb hook"],
["DataManager", :s, :export_full_ver_info, 0, "5_DataManager.rb:881, 98_SelfTest.rb log header"],
["Cache", :s, :system_lonacraft_orig, 1, "4_Cache.rb:65 Cache.system, 10_Icons.rb hook"],
["EvLib", :s, :sum, -2, "511_EvLib.rb:5, 45_Nodes.rb / 130_Sewer.rb"],
["EvLib", :s, :NewEventCMD, 1, "511_EvLib.rb:48, 100_Homes.rb / 110_Bases.rb doors"],
["Note", :s, :get_data, 1, "NoteReading.rb:14, 100_Homes.rb / 110_Bases.rb"],
["FileGetter", :s, :load_alchemy_recipes_from_dir, -1, "103_FileGetter.rb:526, 0_Core.rb salvage recipes"],
["RPG::Item", :i, :load_additional_data, -1, "ItemConfig.rb:50, 0_Core.rb load_items"],
["RPG::Weapon", :i, :load_additional_data, -1, "ItemConfig.rb:50, 0_Core.rb load_weapons (the Hatchet)"],
["RPG::Weapon", :i, :createLonaState, 1, "LonaState.rb:12, 0_Core.rb load_weapons held picture"],
["RPG::Weapon", :i, :added_skills=, 1, "1_DataStructure.rb:238 attr_accessor, 0_Core.rb load_weapons Hatchet look"],
["RPG::Weapon", :i, :skill_sealed=, 1, "1_DataStructure.rb:239 attr_accessor, 0_Core.rb load_weapons Hatchet look"],
["LonaStatAdapter::LonaStat", :i, :affectValue=, 1, "LonaState.rb:19 attr_accessor, 0_Core.rb load_weapons held picture"],
["Lona_CHS_Part", :i, :bitmaps, 0, "08_Lona_Part.rb:9 attr_reader, 0_Core.rb held_part?"],
["Lona_CHS_Part", :i, :name_order, 0, "12_Lona_CHS_Part.rb:8 attr_accessor, 0_Core.rb held_part?"],
["Input", :s, :trigger?, 1, "2000_GamePad.rb:561, 95_Debug.rb / 110_Bases.rb / 120_Raids.rb keys"],
["SceneManager", :s, :scene_is?, 1, "6_SceneManager.rb:75, 110_Bases.rb / 120_Raids.rb debug keys"],
["ModManager", :i, :load_order, 0, "730_Mod_InGameUI_mod_manager.rb:58, 0_Core.rb check_load_order"],
["ModManager", :i, :mods, 0, "730_Mod_InGameUI_mod_manager.rb:7 attr_reader, 0_Core.rb path"],
["ModManager", :i, :get_resource, 2, "730_Mod_InGameUI_mod_manager.rb:258, loader.rb"],
# Engine drawables (RGSS301.dll; the methods 02_ViewportGuard.rb hooks or calls)
["Sprite", :i, :viewport=, 1, "RGSS3 built-in, 02_ViewportGuard.rb hook"],
["Sprite", :i, :dispose, 0, "RGSS3 built-in, 02_ViewportGuard.rb hook"],
["Sprite", :i, :disposed?, 0, "RGSS3 built-in, 02_ViewportGuard.rb"],
["Plane", :i, :viewport=, 1, "RGSS3 built-in, 02_ViewportGuard.rb hook"],
["Plane", :i, :dispose, 0, "RGSS3 built-in, 02_ViewportGuard.rb hook"],
["Plane", :i, :disposed?, 0, "RGSS3 built-in, 02_ViewportGuard.rb"],
["Window", :i, :viewport=, 1, "RGSS3 built-in, 02_ViewportGuard.rb hook"],
["Window", :i, :dispose, 0, "RGSS3 built-in, 02_ViewportGuard.rb hook"],
["Window", :i, :disposed?, 0, "RGSS3 built-in, 02_ViewportGuard.rb"],
["Tilemap", :i, :viewport=, 1, "RGSS3 built-in, 02_ViewportGuard.rb hook"],
["Tilemap", :i, :dispose, 0, "RGSS3 built-in, 02_ViewportGuard.rb hook"],
["Tilemap", :i, :disposed?, 0, "RGSS3 built-in, 02_ViewportGuard.rb"],
["Viewport", :i, :dispose, 0, "RGSS3 built-in, 02_ViewportGuard.rb hook (disposes what is left on it first)"],
]
# Input symbols the mod reads: [symbol, where]
INPUT_KEYS = [
[:NUMPAD0, "95_Debug.rb"], [:NUMPAD1, "95_Debug.rb"], [:NUMPAD3, "95_Debug.rb"],
[:NUMPAD5, "95_Debug.rb"], [:NUMPAD7, "95_Debug.rb"], [:NUMPAD9, "95_Debug.rb"],
[:ADD, "95_Debug.rb"], [:SUBTRACT, "95_Debug.rb"], [:MULTIPLY, "95_Debug.rb"],
[:DIVIDE, "110_Bases.rb DEBUG_KEY"], [:DECIMAL, "120_Raids.rb DEBUG_KEY"], [:HOME, "95_Debug.rb GOD_KEY"],
[:UI_DeleteItem, "110_Bases.rb KEY_TAKE"], [:L, "110_Bases.rb KEY_PREV"], [:R, "110_Bases.rb KEY_NEXT"],
[:B, "80_CraftScene.rb / 110_Bases.rb"], [:C, "80_CraftScene.rb / 110_Bases.rb"],
[:UP, "80_CraftScene.rb"], [:DOWN, "80_CraftScene.rb"], [:LEFT, "80_CraftScene.rb"], [:RIGHT, "80_CraftScene.rb"],
[:MZ_LINK, "85_MenuCraft.rb / 110_Bases.rb mouse"], [:MX_LINK, "85_MenuCraft.rb / 110_Bases.rb mouse"]
]
# System_Settings constants: [name, where]
SETTINGS = [
["MAP_HUD_Z", "50_System_Settings.rb:192, 110_Bases.rb HUD_Z"],
["SCENE_Menu_Cursor_Z", "50_System_Settings.rb:157, 85_MenuCraft.rb"],
["SCENE_Menu_Contents_Z", "50_System_Settings.rb:159, 85_MenuCraft.rb"]
]
# Globals the mod reads: [name, [classes], where]
GLOBALS = [
["$data_ItemName", [Hash], "5_DataManager.rb load_items_to_ItemHash"],
["$data_EventLib", [Hash], "5_DataManager.rb:161 FileGetter.read_EventLib"],
["$data_npcs", [Hash], "5_DataManager.rb:156 load_npcs, 0_Core.rb hunting drops"],
["$data_barters", [Hash], "5_DataManager.rb:162, 0_Core.rb merge_barters, 25_Shops.rb"],
["$data_mapinfos", [Hash], "5_DataManager.rb:145, 100_Homes.rb / 110_Bases.rb / 130_Sewer.rb"],
["$data_tag_maps", [Hash], "5_DataManager.rb:157, 100_Homes.rb / 130_Sewer.rb"],
["$data_region_maps", [Hash], "5_DataManager.rb:158, 110_Bases.rb"],
["$data_tilesets", [Array, Hash], "5_DataManager.rb:139, 100_Homes.rb / 110_Bases.rb"],
["$mod_load_script", [Hash], "102_ScriptImport.rb:63, 45_Nodes.rb / 100_Homes.rb redirects"],
["$mod_manager", [Object], "730_Mod_InGameUI_mod_manager.rb:296"],
["$game_text", [Text], "5_DataManager.rb:115 update_Lang"]
]
#----------------------------------------------------------------------
# 2. Game data. The lists are built from the mod's own tables when the
# check runs; a lambda that returns :skip skips the row.
#----------------------------------------------------------------------
# [label, where, lambda => item names]
ITEM_LISTS = [
["game items named in code", "45_Nodes.rb PICKAXES, 100_Homes.rb COIN / :coin / :nap_keys, Recipes/Arrows_Fire.json ItemOil",
lambda{ ["ItemMhPickAxe", "ItemMhWoodenClub", "ItemCoin1", "ItemCoin2", "ItemCoin3", "ItemOil", "ItemNoerTavernNapKey",
"ItemPirateBaneInnNapKey", "ItemDoomFortressInnNapKey", "ItemFishTownInnNapKey", "ItemSouthFL_INN_Key", "ItemNorthFL_INN_Key"] }],
["PROCESS_RECIPES inputs and outputs", "30_Process.rb", lambda{ SelfTest.process_items }],
["mining ores and by-products", "40_Mining.rb MINING_ORES / MINING_BYPRODUCTS",
lambda{ LonaCraft::MINING_ORES + LonaCraft::MINING_BYPRODUCTS.map{|r| r[0] } }],
["nodes tools and yields", "45_Nodes.rb PICKAXES / STONE_ITEM / IRON_ITEM / AXES[0]",
lambda{ n = SelfTest.const("LonaCraft::Nodes"); n ? n::PICKAXES + [n::STONE_ITEM, n::IRON_ITEM, n::AXES[0]] : :skip }],
["RolePlayS axes", "45_Nodes.rb AXES (RolePlayS items)",
lambda{ SelfTest.mod_on?("RolePlayS") ? ["ItemMhLumbAx", "ItemMhPoleaxe"] : :skip }],
["debug raw inputs", "95_Debug.rb RAW_INPUTS", lambda{ LonaCraft::Debug::RAW_INPUTS }],
["shop additions", "25_Shops.rb DEFAULTS",
lambda{ s = SelfTest.const("LonaCraft::Shops"); s ? s.default_items : :skip }],
["base pieces and repair", "110_Bases.rb PIECE_ITEMS / REPAIR / REPAIR_STONE",
lambda{ b = SelfTest.const("LonaCraft::Bases::PIECE_ITEMS"); b ? b.keys + [LonaCraft::Bases::REPAIR["item"]] + (LonaCraft::Bases.const_defined?(:REPAIR_STONE) ? [LonaCraft::Bases::REPAIR_STONE["item"]] : []) : :skip }]
]
# [label, where, lambda => EventLib event names]
EVENTLIB_LISTS = [
["ground-drop template", "0_Core.rb DROP_EVENT_TEMPLATE", lambda{ [LonaCraft::DROP_EVENT_TEMPLATE] }],
["material and weapon ground drops", "0_Core.rb register_drop_events (ITEMS + WEAPONS)",
lambda{ LonaCraft::ITEM_NAMES + (SelfTest.const("LonaCraft::WEAPON_NAMES") || []) }],
["furniture ground drops", "90_Furniture.rb ITEM_NAMES (register_drop_events)",
lambda{ SelfTest.const("LonaCraft::Furniture::ITEM_NAMES") || :skip }],
["mining ores", "40_Mining.rb MINING_ORES (summoned by Mining_*.rb)", lambda{ LonaCraft::MINING_ORES }],
["node template and stone picture", "45_Nodes.rb BOULDER_TEMPLATE, ItemRock (Map001 EV93, LOOSE_SHEET)",
lambda{ n = SelfTest.const("LonaCraft::Nodes"); n ? [n::BOULDER_TEMPLATE, "ItemRock"] : :skip }],
["node events made at load", "45_Nodes.rb BOULDER_EVENT / LOOSE_EVENT",
lambda{ n = SelfTest.const("LonaCraft::Nodes"); n ? [n::BOULDER_EVENT, n::LOOSE_EVENT] : :skip }],
["raid extra raiders", "120_Raids.rb EXTRA_UNIT",
lambda{ x = SelfTest.const("LonaCraft::Raids::EXTRA_UNIT"); x ? x.values.uniq : :skip }],
["Deep Sewer population", "130_Sewer.rb VERMIN / HOBOS / GOBLIN / RAT_UNIT",
lambda{ s = SelfTest.const("LonaCraft::Sewer"); s ? (s::VERMIN.map{|r| r[0] } + s::HOBOS + [s::GOBLIN, s::RAT_UNIT]).uniq : :skip }]
]
# Game maps: [map id, MapInfos name, tileset id (nil = map not loaded), where]
MAPS = [
[2, "OvermapMain", 1, "100_Homes.rb doors, 110_Bases.rb WALLED"],
[59, "NoerTavern", 22, "100_Homes.rb noer_inn_room, 110_Bases.rb DOOR_FRONT"],
[53, "NoerSewer", nil, "docs/RESEARCH_SEWER.md, the Deep Sewer's look and events (r3/build_deep_sewer_v2.py)"],
[58, "NoerMobHouse", nil, "130_Sewer.rb ENTRANCES_ALL slum grate (parked 2026-10-06: the capture house, wrong map)"],
[14, "NoerDock", nil, "130_Sewer.rb ENTRANCES dock grate"],
[63, "NoerBackStreet", nil, "130_Sewer.rb ENTRANCES backstreet grate"],
[43, "NoerBlackSmithShop", 26, "90_Furniture.rb TOWN_STATIONS"],
[62, "NoerMarket", 27, "90_Furniture.rb TOWN_STATIONS"],
[15, "NoerBank", nil, "100_Homes.rb SELLERS NoerBankMaani"],
[195, "NoerTransHouse", nil, "100_Homes.rb noer_shack (room copied from it)"],
[81, "PirateBaneInn", 22, "100_Homes.rb piratebane_inn_room (R16)"],
[97, "DoomFortressInn", 22, "100_Homes.rb doomfortress_inn_room (R16)"],
[117, "FishTownInn", 38, "100_Homes.rb fishtown_inn_room (R16)"],
[135, "SouthFL_INN", 22, "100_Homes.rb southfl_inn_room (R16)"],
[148, "NorthFL_INN", 22, "100_Homes.rb northfl_inn_room (R16)"]
]
# Events in game maps: [map id, event id, character sheet of page 1, where]
MAP_EVENTS = [
[59, 54, "!Door4", "110_Bases.rb DOOR_FRONT (NoerTavern events 54/55)"],
[59, 55, "!Door4", "110_Bases.rb DOOR_FRONT (NoerTavern events 54/55)"]
]
# Tilesets whose tile ids the mod bakes in: [id, name, tileset_names, where]
TILESETS = [
[1, "Field", ["World_A1", "World_A2", "", "", "", "World_B", "!World Map 01", "!World Map 02", "!World Map 03"],
"OvermapMain (100_Homes.rb doors, 110_Bases.rb markers)"],
[19, "Mack-Sewer", ["macks417_sewer_A1", "macks417_Sewer_A2", "macks_A3", "macks417_Tomb_A4", "macks417_Tomb_A5", "TileC_exterior417Ver", "417Mixupedd-slum", "TileD_exterior2", "macks417_badland_E"],
"Maps/LonaCraftDeepSewer.rvdata2 (130_Sewer.rb)"],
[22, "RMDLC INSA TARVEN", ["TileA1", "TileA2_interior", "TileA3", "TileA4_2", "TileA5_interior", "tileb_interior", "tilec_interior", "417Mixupedd-slum", "Village&town-417EDITION_D_Interior"],
"Maps/NoerShack.rvdata2, Maps/NoerStoneHouse.rvdata2 (100_Homes.rb), the NoerTavern room"]
]
# Game files LonaCraft runs, redirects or cites (loose files; skipped in a packed game)
GAME_FILES = [
["Data/HCGframes/event/NoerBankMaani.rb", "100_Homes.rb SELLERS"],
["Data/HCGframes/event/NoerTavernWaifu.rb", "100_Homes.rb SELLERS"],
["Data/HCGframes/event/NoerTavern_Nap.rb", "100_Homes.rb :nap_script"],
["Data/HCGframes/event/PirateBaneInnKeeper.rb", "100_Homes.rb SELLERS (R16)"],
["Data/HCGframes/event/PirateBaneInn_Nap.rb", "100_Homes.rb :nap_script (R16)"],
["Data/HCGframes/event/DoomFortressInnKeeper.rb", "100_Homes.rb SELLERS (R16)"],
["Data/HCGframes/event/DoomFortressInn_Nap.rb", "100_Homes.rb :nap_script (R16)"],
["Data/HCGframes/event/FishTownInnKeeper.rb", "100_Homes.rb SELLERS (R16)"],
["Data/HCGframes/event/FishTownInn_Nap.rb", "100_Homes.rb :nap_script (R16)"],
["Data/HCGframes/event/InnKeeper_SouthFL_INN.rb", "100_Homes.rb SELLERS (R16)"],
["Data/HCGframes/event/SouthFL_INN_Nap.rb", "100_Homes.rb :nap_script (R16)"],
["Data/HCGframes/event/NorthFL_INN_Keeper.rb", "100_Homes.rb SELLERS (R16)"],
["Data/HCGframes/event/NorthFL_INN_Nap.rb", "100_Homes.rb :nap_script (R16)"],
["Data/HCGframes/event/NoerTavernGuildEmpolyee.rb", "150_Mercs.rb GUILD_SCRIPT (the receptionist's menu line)"],
["Data/CHSConfig/CHSconfigs_NPC/-char-F-REGULAR01.json", "170_Maid.rb SPRITE (the 02Maid look, HAIRS / FACES)"],
["Data/HCGframes/event/CommonTree.rb", "45_Nodes.rb TREE_SCRIPTS"],
["Data/HCGframes/event/CommonTreeNoble.rb", "45_Nodes.rb TREE_SCRIPTS"],
["Data/HCGframes/Command_DarkPot.rb", "20_Station.rb POT_SCRIPT"],
["Data/HCGframes/Command_AreaNap.rb", "90_Furniture.rb NAP_SCRIPT"],
["Data/HCGframes/Command_bath.rb", "90_Furniture.rb BATH_SCRIPT"],
["Data/HCGframes/event/Mining_*.rb", "40_Mining.rb (yield hook, at least one file)"],
["Data/Scripts/101_jsonEnDecoder.rb", "55_Recipes.rb ConfigJSON note"],
["Data/Scripts/Editables/50_System_Settings.rb", "SETTINGS above"],
["Data/Scripts/Frames/RVscript/1000_Hime_AllKey.rb", "INPUT_KEYS above"],
["Data/Scripts/Frames/RVscript/3000_InputMenu.rb", "INPUT_KEYS above"]
]
# Room tiles of the inn rooms (flood of the map file + :tile_overrides),
# docs/RESEARCH_INNS.md 4 (Noer: 100_Homes.rb noer_inn_room comment)
ROOM_TILES = {"noer_inn_room" => 11, "piratebane_inn_room" => 6, "doomfortress_inn_room" => 8,
"fishtown_inn_room" => 9, "southfl_inn_room" => 8, "northfl_inn_room" => 8}
# LonaCraft script order in loader.rb: [first, second, where] = first loads before second
LOAD_ORDER = [
["0_Core.rb", "05_Config.rb", "05_Config.rb loads right after 0_Core.rb"],
["05_Config.rb", "10_Icons.rb", "05_Config.rb loads right after 0_Core.rb"],
["15_Text.rb", "50_Tiers.rb", "15_Text.rb header (alias order on Text#[])"],
["50_Tiers.rb", "55_Recipes.rb", "0_Core.rb load_database (Tiers before Recipes)"],
["55_Recipes.rb", "80_CraftScene.rb", "loader.rb (the crafting screen after the data layer)"],
["55_Recipes.rb", "110_Bases.rb", "05_Config.rb (ConfigJSON before the first debug? call)"],
["55_Recipes.rb", "02_ViewportGuard.rb", "02_ViewportGuard.rb (ConfigJSON before its viewport_guard switch is read)"],
["80_CraftScene.rb", "85_MenuCraft.rb", "loader.rb"],
["80_CraftScene.rb", "90_Furniture.rb", "loader.rb"],
["90_Furniture.rb", "100_Homes.rb", "100_Homes.rb (furniture records)"],
["110_Bases.rb", "120_Raids.rb", "120_Raids.rb (needs 110_Bases.rb)"],
["120_Raids.rb", "140_AwayRaids.rb", "140_AwayRaids.rb (Raids.cfg, scenario_for, pick_group)"],
["140_AwayRaids.rb", "150_Mercs.rb", "150_Mercs.rb (date hook order: away rolls before the contract end)"],
["100_Homes.rb", "150_Mercs.rb", "150_Mercs.rb (Homes.redirect, extend_menu, notice)"],
["120_Raids.rb", "160_Rest.rb", "160_Rest.rb (Raids.cfg rest, its roll alias over the Raids alias)"],
["160_Rest.rb", "170_Maid.rb", "170_Maid.rb (Rest::DISHES)"],
["150_Mercs.rb", "170_Maid.rb", "170_Maid.rb (the guild line while Boss Mama is away)"],
["55_Recipes.rb", "25_Shops.rb", "25_Shops.rb (ConfigJSON, RecipeConfig.dump / item_text at load_database)"],
["95_Debug.rb", "98_SelfTest.rb", "98_SelfTest.rb loads last"]
]
#----------------------------------------------------------------------
# Runner
#----------------------------------------------------------------------
@results = [] # [group, name, status (:pass / :fail / :skip), reason]
@ran = false
@maps = {}
@eng = {}
@loader = nil
def self.results
@results
end
# The text in UTF-8, safe to join with any other string
def self.u(s)
s = s.to_s.dup
s.force_encoding("UTF-8")
return s if s.valid_encoding?
s.force_encoding("ASCII-8BIT").encode("UTF-8", :invalid => :replace, :undef => :replace, :replace => "?")
rescue
"?"
end
def self.skip(why)
[:skip, why]
end
def self.note(text)
[:pass, text]
end
def self.record(group, name, status, reason)
@results << [u(group), u(name), status, u(reason)]
end
# Runs one check. The block returns nil / true (pass), a String (fail),
# false (fail without a reason), skip(...) or note(...).
def self.check(group, name)
res = yield
if res.nil? || res == true
record(group, name, :pass, "")
elsif res == false
record(group, name, :fail, "failed")
elsif res.is_a?(Array) && (res[0] == :skip || res[0] == :pass)
record(group, name, res[0], res[1])
else
record(group, name, :fail, res)
end
rescue StandardError, ScriptError, SystemStackError => e
at = e.backtrace && e.backtrace[0] ? " at #{e.backtrace[0]}" : ""
record(group, name, :fail, "crashed: #{e.class} #{e.message}#{at}")
end
#----------------------------------------------------------------------
# Helpers
#----------------------------------------------------------------------
# Constant by path ("LonaCraft::Bases::REPAIR"), nil when not defined
def self.const(path)
path.to_s.split("::").inject(Object){|mod, name|
return nil unless mod.is_a?(Module) && mod.const_defined?(name)
mod.const_get(name)
}
rescue NameError
nil
end
def self.unbound(mod, kind, meth)
(kind == :s ? mod.singleton_class : mod).instance_method(meth)
rescue NameError
nil
end
def self.required(arity)
arity < 0 ? -arity - 1 : arity
end
# true when a method of +actual+ arity takes every call one of +expected+ took
def self.arity_ok?(actual, expected)
return true if actual == expected
return false if actual >= 0
required(actual) <= required(expected)
end
def self.mod_on?(id)
return false if $mod_manager.nil? || $mod_manager.load_order.nil?
$mod_manager.load_order.any?{|m| m.id == id && m.enabled }
rescue
false
end
def self.packed?
defined?(FileGetter::COMPRESSED) && FileGetter::COMPRESSED ? true : false
end
def self.read(path)
File.open(path, "rb"){|f| f.read }
end
def self.item?(name)
!$data_ItemName.nil? && !$data_ItemName[name.to_s].nil?
end
def self.process_items
out = []
LonaCraft::PROCESS_RECIPES.each{|key, ins, outs|
out.concat(ins.keys.reject{|n| n == LonaCraft::FIBRE })
out.concat(outs.keys)
}
out.uniq
end
def self.input_known?(sym)
return true if defined?(Input::KEYMAP) && Input::KEYMAP.is_a?(Hash) && Input::KEYMAP.has_key?(sym)
return true if defined?(Input::SYM_KEYS) && Input::SYM_KEYS.is_a?(Hash) && Input::SYM_KEYS.has_key?(sym)
if defined?(InputUtils)
[:keyList, :gamepadList, :mouseDefaultKeys, :multiBindKeys, :gamepadMenuOnlyList].each{|m|
next unless InputUtils.respond_to?(m)
list = InputUtils.send(m)
next unless list.is_a?(Array)
return true if list.any?{|row| row.is_a?(Array) ? row[0] == sym : row == sym }
}
end
false
end
# Game map number of a MapInfos name (integer keys only), or nil
def self.map_id(name)
return nil if $data_mapinfos.nil?
$data_mapinfos.each{|key, info|
next unless key.is_a?(Integer) && info
return key if info.name.to_s == name.to_s
}
nil
end
# RPG::Map of a game map number (loaded once per run)
def self.game_map(id)
return @maps[id] if @maps.has_key?(id)
info = $data_mapinfos ? $data_mapinfos[id] : nil
file = info && info.respond_to?(:filename) && info.filename ? info.filename : sprintf("Data/Map%03d.rvdata2", id)
@maps[id] = load_data(file)
end
def self.in_map?(map, x, y)
x >= 0 && y >= 0 && x < map.width && y < map.height
end
def self.event_at(map, x, y)
map.events.values.find{|e| e && e.x == x && e.y == y }
end
# All four directions passable on the map layers (as 90_Furniture.rb
# lonacraft_layer_pass?, after 31_Game_Map.rb:734 check_passage)
def self.tile_pass?(map, x, y)
flags = $data_tilesets[map.tileset_id].flags
[1, 2, 4, 8].all?{|bit|
ok = false
[2, 1, 0].each{|z|
flag = flags[map.data[x, y, z]]
next if flag & 0x10 != 0
ok = (flag & bit == 0)
break
}
ok
}
end
# [width, height] from a PNG header, or nil
def self.png_size(path)
head = File.open(path, "rb"){|f| f.read(24) }
return nil if head.nil? || head.length < 24 || head[1, 3] != "PNG"
head[16, 8].unpack("NN")
end
# LonaCraft scripts in loader.rb order
def self.loader_scripts
@loader ||= read(LonaCraft.resource("loader.rb")).split("\n").map{|line|
next nil if line.strip.start_with?("#")
m = line.match(/"Scripts\/([^"]+\.rb)"/)
m ? m[1] : nil
}.compact
end
# Parsed Text/ENG/<file>.txt of the mod ({} when missing)
def self.eng(file)
return @eng[file] if @eng.has_key?(file)
path = LonaCraft.resource("Text/ENG/#{file}.txt")
parser = $game_text.is_a?(Text) ? $game_text : Text.new("Text/ENG")
@eng[file] = File.exist?(path) ? parser.parse(read(path).force_encoding("UTF-8")) : {}
end
RE_TEXT_LITERAL = /"LonaCraft:([A-Za-z]+):([^"\#\{\}\\]+)"/
RE_TEXT_KEY = /(?:\b([A-Za-z_]+)\.|(?<![\w.]))text_key\("([^"\#\{\}\\]+)"\)/
RE_TEXT_FALLBACK = /TextFallback\.get\("([A-Za-z]+)",\s*"([^"\#\{\}\\]+)"/
RE_TEXT_CONST = /^\s*TEXT\s*=\s*"LonaCraft:([A-Za-z]+):"/
# {source file => [[text file, id], ...]}: the text keys the code names
# literally (loaded scripts and HCGframes/*.rb). A text_key call takes
# the TEXT constant of its receiver (homes., bases., fur. ...) or of
# its own file; "?" marks a receiver with no known TEXT.
def self.text_keys
files = loader_scripts.map{|f| LonaCraft.resource("Scripts/#{f}") }
files.concat(Dir.glob(LonaCraft.resource("HCGframes/*.rb")).sort)
sources = {}
files.each{|f| sources[f] = read(f) if File.exist?(f) }
receivers = {}
sources.each_value{|src| src.scan(RE_TEXT_CONST){|m| receivers[m[0].downcase] = m[0] } }
receivers["fur"] = receivers["furniture"] if receivers["furniture"]
out = {}
sources.each{|f, src|
own = src.scan(RE_TEXT_CONST).map{|m| m[0] }
keys = []
src.scan(RE_TEXT_LITERAL){|a, b| keys << [a, b] }
src.scan(RE_TEXT_FALLBACK){|a, b| keys << [a, b] }
src.scan(RE_TEXT_KEY){|recv, id|
file = recv ? receivers[recv.downcase] : (own.size == 1 ? own[0] : nil)
keys << [file || "?#{recv}", id]
}
out[File.basename(f)] = keys.map{|a, b| [u(a), u(b)] }.uniq
}
out
end
#----------------------------------------------------------------------
# The checks
#----------------------------------------------------------------------
def self.run_checks
# Ruby 3.1.0 / mkxp-z compatibility (the executable controls Ruby version).
check("runtime", "Ruby version"){ RUBY_VERSION.start_with?("3.1.") ? note(RUBY_VERSION) : note("#{RUBY_VERSION}; target Ruby 3.1.x, interpreter comes from Game.exe") }
check("runtime", "Ruby310Compat"){ defined?(Ruby310Compat) ? nil : "game Ruby310Compat not loaded" }
# 1. Game methods, input keys, settings, globals
METHODS.each{|owner, kind, meth, arity, where|
check("methods", "#{owner}#{kind == :s ? "." : "#"}#{meth}"){
mod = const(owner)
next "#{owner} is missing (#{where})" unless mod.is_a?(Module)
um = unbound(mod, kind, meth)
next "missing (#{where})" if um.nil?
a = um.arity
next nil if a == arity
next note("arity #{a}, was #{arity}: still takes the old calls") if arity_ok?(a, arity)
"arity #{a}, expected #{arity} (#{where})"
}
}
INPUT_KEYS.each{|sym, where|
check("input", ":#{sym}"){ input_known?(sym) ? nil : "unknown Input symbol (#{where})" }
}
SETTINGS.each{|name, where|
check("settings", "System_Settings::#{name}"){
next "System_Settings is missing" unless defined?(System_Settings)
next "missing (#{where})" unless System_Settings.const_defined?(name)
v = System_Settings.const_get(name)
v.is_a?(Integer) ? nil : "not a number: #{v.inspect} (#{where})"
}
}
GLOBALS.each{|name, classes, where|
check("globals", name){
v = eval(name)
next "nil (#{where})" if v.nil?
classes.any?{|c| v.is_a?(c) } ? nil : "a #{v.class}, expected #{classes.join(" or ")} (#{where})"
}
}
check("globals", "$mod_manager entry LonaCraft"){
mod = $mod_manager.mods["LonaCraft"]
next "no mod \"LonaCraft\" in $mod_manager.mods (0_Core.rb MOD_ID)" if mod.nil?
gone = [:id, :version, :path, :enabled, :name].reject{|a| mod.respond_to?(a) }
next "Mod lacks #{gone.join(", ")} (710_Mod_InGameUI_ClassMod.rb)" unless gone.empty?
File.directory?(mod.path.to_s) ? note(mod.path.to_s) : "mod path #{mod.path} is not a folder"
}
# 2. Game data
ITEM_LISTS.each{|label, where, list|
check("items", label){
names = list.call
next skip("not loaded or not needed") if names == :skip
missing = names.compact.uniq.reject{|n| item?(n) }
missing.empty? ? note("#{names.size} items") : "not in $data_ItemName: #{missing.join(", ")} (#{where})"
}
}
Dir.glob(LonaCraft.resource("Recipes/*.json")).sort.each{|path|
check("items", "Recipes/#{File.basename(path)} items"){
raw = LonaCraft::ConfigJSON.parse(read(path))
entries = raw.is_a?(Array) ? raw : [raw]
missing = []
used = 0
entries.each{|e|
next unless e.is_a?(Hash)
next if e.has_key?("requires") && !LonaCraft::Recipes.requires_met?(e["requires"])
used += 1
missing << e["output"].to_s unless item?(e["output"])
(e["inputs"].is_a?(Hash) ? e["inputs"].keys : []).each{|n| missing << n unless n == LonaCraft::FIBRE || item?(n) }
}
next skip("needs a mod that is not loaded") if used == 0
missing.empty? ? nil : "not in $data_ItemName: #{missing.uniq.join(", ")}"
}
}
LonaCraft::HUNTING_DROPS.each{|npc_name, adds|
check("npcs", npc_name){
npc = $data_npcs[npc_name]
next "not in $data_npcs (0_Core.rb HUNTING_DROPS)" if npc.nil?
next "no drop_list (281_Game_NonPlayerCharacter.rb:974)" unless npc.respond_to?(:drop_list) && npc.drop_list.is_a?(Array)
gone = adds.map{|a| a[0] }.reject{|n| npc.drop_list.include?(n) }
gone.empty? ? nil : "drops not merged: #{gone.join(", ")} (0_Core.rb merge_hunting_drops)"
}
}
mc = const("LonaCraft::Mercs")
if mc && mc.const_defined?(:NPC_FILES)
mc::NPC_FILES.each{|rel|
check("npcs", "mod #{rel}"){
path = LonaCraft.resource(rel)
next "missing (150_Mercs.rb NPC_FILES)" unless File.exist?(path)
name = File.basename(rel, ".json")
npc = $data_npcs[name]
next "not in $data_npcs (150_Mercs.rb load_npcs)" if npc.nil?
next "ai #{npc.ai.inspect}, expected Npc_CompanionCharge" unless npc.ai.to_s == "Npc_CompanionCharge"
Object.const_defined?(npc.ai.to_s) ? note("atk #{npc.atk}, health #{npc.health}") : "AI class #{npc.ai} missing"
}
}
check("npcs", "squad death event"){
names = mc::NPC_DATA.values.uniq.map{|n| $data_npcs[n] }.compact.map{|n| n.death_event.to_s }.uniq
missing = names.reject{|n| $data_EventLib.has_key?(n) }
missing.empty? ? note(names.join(", ")) : "not in $data_EventLib: #{missing.join(", ")} (NPC/*.json death_event)"
}
end
md = const("LonaCraft::Maid")
if md && md.const_defined?(:NPC_FILE)
check("npcs", "mod #{md::NPC_FILE}"){
next "missing (170_Maid.rb NPC_FILE)" unless File.exist?(LonaCraft.resource(md::NPC_FILE))
npc = $data_npcs[md::NPC_NAME]
next "not in $data_npcs (170_Maid.rb load_npc)" if npc.nil?
next "AI class #{npc.ai} missing" unless Object.const_defined?(npc.ai.to_s)
note("health #{npc.health}, ai #{npc.ai}")
}
check("npcs", "maid hair and face in the 02Maid part"){
path = "Data/CHSConfig/CHSconfigs_NPC/#{md::SPRITE[0]}.json"
next skip("packed game") if packed? || !File.exist?(path)
txt = read(path)
gone = (md::HAIRS + md::FACES).reject{|n| txt.include?(n) }
gone.empty? ? note("#{md::HAIRS.size} hairs, #{md::FACES.size} faces") : "not in #{path}: #{gone.join(", ")}"
}
check("files", "redirect Data/HCGframes/event/NoerTavernWaifu.rb (the maid line)"){
want = LonaCraft::Homes.wrapper_script("Data/HCGframes/event/NoerTavernWaifu.rb")
got = $mod_load_script["Data/HCGframes/event/NoerTavernWaifu.rb"]
got == want ? nil : "$mod_load_script points to #{got.inspect}, expected #{want}"
}
check("runtime", "maid recipes"){
n = md.recipes.size
n > 0 ? note("#{n} dark-pot recipes she can cook") : "no recipe from $data_AlchemyRecipes matches Rest::DISHES"
}
# 2026-10-07: a post is a base or an owned house ("base" / "home" in her record)
hm = const("LonaCraft::Homes")
check("runtime", "maid posts (bases and houses)"){
next skip("no Maid.post_ref or Homes") unless md.respond_to?(:post_ref) && hm
next skip("homes off (100_Homes.rb ENABLED)") unless hm.enabled?
bad = []
bad << "base shape" unless md.post_ref({"name" => "x", "base" => 3}) == [:base, 3]
bad << "home shape" unless md.post_ref({"name" => "x", "home" => "noer_shack"}) == [:home, "noer_shack"]
bad << "home over base" unless md.post_ref({"name" => "x", "base" => 3, "home" => "noer_shack"}) == [:home, "noer_shack"]
bad << "no post" unless md.post_ref({"name" => "x"}).nil?
houses = hm::LOCATIONS.select{|loc| !hm.rent?(loc) && loc[:interior].is_a?(Array) }.map{|loc| loc[:id] }
off = houses.reject{|id| md.house?(id) }
bad << "houses that cannot be posts: #{off.join(" ")}" unless off.empty?
rented = hm::LOCATIONS.select{|loc| hm.rent?(loc) }.map{|loc| loc[:id] }.select{|id| md.house?(id) }
bad << "rented rooms taken as posts: #{rented.join(" ")}" unless rented.empty?
bad.empty? ? note("#{houses.size} houses can be posts (#{houses.join(", ")})") : bad.join("; ")
}
end
rs = const("LonaCraft::Rest")
if rs && rs.const_defined?(:DISHES)
check("items", "rest dishes (160_Rest.rb DISHES)"){
missing = rs::DISHES.keys.reject{|n| $data_ItemName[n] || (n == "ItemMeatSalad" && $data_items[rs::MEAT_SALAD_ID]) }
missing.empty? ? note("#{rs::DISHES.size} dishes") : "not in $data_ItemName: #{missing.join(", ")}"
}
check("items", "Meat Salad data typo (food_SF_MeatSalad.json item_name)"){
it = $data_items[rs::MEAT_SALAD_ID]
next "no $data_items[#{rs::MEAT_SALAD_ID}] (160_Rest.rb MEAT_SALAD_ID)" if it.nil?
$data_ItemName["ItemMeatSalad"] ? note("ItemMeatSalad registered now (the game fixed the typo?)") : note("matched by id #{rs::MEAT_SALAD_ID}, item_name #{it.respond_to?(:item_name) ? it.item_name.inspect : "?"}")
}
check("items", "rest dishes are dark-pot outputs"){
next skip("no $data_AlchemyRecipes") unless defined?($data_AlchemyRecipes) && $data_AlchemyRecipes
txt = $data_AlchemyRecipes.inspect
gone = rs::DISHES.keys.reject{|n| txt.include?(n) }
gone.empty? ? nil : "not a recipe output: #{gone.join(", ")} (160_Rest.rb DISHES)"
}
end
EVENTLIB_LISTS.each{|label, where, list|
check("eventlib", label){
names = list.call
next skip("not loaded") if names == :skip
missing = names.compact.uniq.reject{|n| $data_EventLib.has_key?(n) }
missing.empty? ? note("#{names.size} events") : "not in $data_EventLib: #{missing.join(", ")} (#{where})"
}
}
# 25_Shops.rb: every default row names a loaded item and a trader
# whose barter exists and whose script opens it; the merged rows are in
shops = const("LonaCraft::Shops")
check("barters", "25_Shops.rb loaded"){ shops ? note("#{shops::DEFAULTS.size} traders") : "LonaCraft::Shops not defined (loader.rb, 25_Shops.rb)" }
(shops ? shops::DEFAULTS : {}).each{|shop, rows|
check("barters", shop){
data = $data_barters[shop]
next "trader not in $data_barters (Data/Barters/#{shop}.json, 25_Shops.rb DEFAULTS)" if data.nil?
info = shops::TRADERS[shop]
next "no TRADERS row (25_Shops.rb)" if info.nil?
unless packed?
script = "Data/HCGframes/event/#{info[0]}"
next "#{script} missing (25_Shops.rb TRADERS)" unless File.exist?(script)
call = 'manual_barters("' + shop + '")'
next "#{script} does not call #{call} (25_Shops.rb TRADERS)" unless read(script).include?(call)
end
missing = rows.map{|r| r["item"] }.reject{|n| item?(n) }
next "unknown items: #{missing.join(", ")} (25_Shops.rb DEFAULTS)" unless missing.empty?
merged = shops.merged[shop] || []
items = (data["items"] || []).map{|i| i["item_name"] }
gone = merged.map{|e| e["item_name"] }.reject{|n| items.include?(n) }
gone.empty? ? note("#{rows.size} default rows, #{merged.size} merged") : "entries not merged: #{gone.join(", ")}"
}
}
# Price floor (owner 2026-10-07): every sold item that has a recipe is
# sold at a base price of at least its input cost (25_Shops.rb
# input_cost, from the recipes as built now)
check("barters", "shop prices >= input cost"){
next skip("25_Shops.rb not loaded") unless shops
next "25_Shops.rb has no price floor (input_cost)" unless shops.respond_to?(:input_cost)
next skip("Config/Shops.json \x22price_floor_margin\x22: 0, the floor is off") if shops.margin <= 0
bad = []
n = 0
shops.merged.each{|shop, entries|
entries.each{|e|
cost = shops.input_cost(e["item_name"])
next if cost.nil?
n += 1
price = shops.base_price(e)
bad << "#{shop} #{e["item_name"]} #{price ? shops.cost_text(price) : e["price"]} < #{shops.cost_text(cost)}" if price.nil? || price < cost - 0.001 # float noise
}
}
bad.empty? ? note("#{n} rows of craftable items, none below its inputs (x#{shops.margin})") : "below the input cost: #{bad.join(", ")} (25_Shops.rb price floor, 55_Recipes.rb recipes)"
}
check_sheets
check_tilesets
check_wall_sheets
check_maps
check_game_files
# 3. Mod self-consistency
check_text_keys
check_json_files
check_item_ids
check_places
check_save_and_loader
# 4. Runtime results that are safe at boot
check_runtime
end
def self.check_sheets
sheets = {}
add = lambda{|name, where| sheets[name.to_s] ||= where unless name.nil? || name.to_s.empty? }
(const("LonaCraft::Furniture::KINDS") || []).each{|row| add.call(row[2], "90_Furniture.rb KINDS #{row[0]}") }
b = const("LonaCraft::Bases")
if b
add.call(b::MARKER_SPRITE[0], "110_Bases.rb MARKER_SPRITE") if b.const_defined?(:MARKER_SPRITE)
add.call(b::DOOR_FRONT[0], "110_Bases.rb DOOR_FRONT") if b.const_defined?(:DOOR_FRONT)
add.call(b::DOOR_SIDE[0], "110_Bases.rb DOOR_SIDE") if b.const_defined?(:DOOR_SIDE)
add.call(b::GRATE_FRONT[0], "110_Bases.rb GRATE_FRONT") if b.const_defined?(:GRATE_FRONT)
end
(const("LonaCraft::Homes::LOCATIONS") || []).each{|loc|
add.call(loc[:door][3][0], "100_Homes.rb #{loc[:id]} door") if loc[:door].is_a?(Array) && loc[:door][3].is_a?(Array)
}
n = const("LonaCraft::Nodes")
if n
add.call(n::PLACEHOLDER_SPRITE, "45_Nodes.rb PLACEHOLDER_SPRITE")
add.call(n::LOOSE_SHEET, "45_Nodes.rb LOOSE_SHEET")
end
s = const("LonaCraft::Sewer")
add.call(s::GRATE_SPRITE[0], "130_Sewer.rb GRATE_SPRITE") if s && s.const_defined?(:GRATE_SPRITE)
mc = const("LonaCraft::Mercs")
mc::SPRITES.each{|role, row| add.call(row[0], "150_Mercs.rb SPRITES #{role}") } if mc && mc.const_defined?(:SPRITES)
md = const("LonaCraft::Maid")
add.call(md::SPRITE[0], "170_Maid.rb SPRITE") if md && md.const_defined?(:SPRITE)
sheets.each{|name, where|
check("sheets", "Graphics/Characters/#{name}"){
next skip("packed game") if packed?
File.exist?("Graphics/Characters/#{name}.png") ? nil : "missing (#{where})"
}
}
Dir.glob(LonaCraft.resource("Graphics/**/*.png")).sort.each{|path|
check("sheets", "mod #{path.sub(LonaCraft.path + "/", "")}"){
png_size(path) ? nil : "not a PNG file"
}
}
check("sheets", "Iconset_LonaCraft.png cells"){
size = png_size(LonaCraft.iconset_file)
next "missing or not a PNG (10_Icons.rb)" if size.nil?
w, h = size
next "#{w} x #{h} is wider than #{LonaCraft::ICON_COLUMNS} icons (10_Icons.rb)" if w > LonaCraft::ICON_COLUMNS * LonaCraft::ICON_SIZE
cells = (w / LonaCraft::ICON_SIZE) * (h / LonaCraft::ICON_SIZE)
need = LonaCraft::ITEMS.map{|r| r[2] }.max + 1
cells >= need ? note("#{w} x #{h}, #{cells} cells") : "#{cells} cells, 0_Core.rb ITEMS needs #{need}"
}
check("sheets", "game Iconset size"){
base = Cache.system_lonacraft_orig("Iconset")
w = base.width
h = base.height
want = LonaCraft::ICON_COLUMNS * LonaCraft::ICON_SIZE
next "#{w} px wide, 10_Icons.rb expects #{want}" if w != want
first = (h + LonaCraft::ICON_SIZE - 1) / LonaCraft::ICON_SIZE * LonaCraft::ICON_COLUMNS
next "Iconset is #{w} x #{h}: mod icons start at #{first}, 0_Core.rb ICON_BASE_FALLBACK is #{LonaCraft::ICON_BASE_FALLBACK} (update it)" if first != LonaCraft::ICON_BASE_FALLBACK
LonaCraft.merged_iconset ? note("#{w} x #{h}, mod icons from #{first}") : "merge failed (10_Icons.rb, see the console)"
}
# ground pictures of the mod's items (0_Core.rb drop_pictures, made by tools/build_drop_sheet.py)
check("sheets", "ground-drop pictures (LonaCraft_drops.json)"){
next "0_Core.rb drop_pictures missing" unless LonaCraft.respond_to?(:drop_pictures)
pics = LonaCraft.drop_pictures
names = LonaCraft::ITEM_NAMES + (const("LonaCraft::WEAPON_NAMES") || []) + (const("LonaCraft::Furniture::ITEM_NAMES") || [])
gone = names.reject{|n| pics[n] }
next "#{gone.length} items without a picture, they show raw meat (run tools/build_drop_sheet.py): #{gone.join(", ")}" unless gone.empty?
wrong = names.select{|n|
ev = $data_EventLib[n]
ev && ev[1].pages[0].graphic.character_name != pics[n][0]
}
next "drop events with another picture (0_Core.rb register_drop_events): #{wrong.join(", ")}" unless wrong.empty?
note("#{names.length} items on #{pics.values.map{|v| v[0] }.uniq.length} sheet(s)")
}
end
# the mod's wall sheets (tools/build_wall_sheets.py): every sheet of
# 110_Bases.rb WALL_A4 has its PNG and JSON entry, and the painted blocks
# still hold the approved art (checksum as the tool computes it)
def self.block_sum(bmp, rect)
s = 0
i = 0
rect.height.times{|y|
rect.width.times{|x|
c = bmp.get_pixel(rect.x + x, rect.y + y)
a = c.alpha.to_i
s = (s + (c.red.to_i + 3 * c.green.to_i + 7 * c.blue.to_i + 11 * a) * (i % 251 + 1)) % 2147483647 if a > 0
i += 1
}
}
s
end
def self.a4_rect(kind)
j = kind - 80
col = j % 8
row = j / 8
Rect.new(col * 64, (row / 2) * 160 + (row.odd? ? 96 : 0), 64, row.odd? ? 64 : 96)
end
def self.check_wall_sheets
b = const("LonaCraft::Bases")
return if b.nil? || !b.respond_to?(:wall_sheets)
path = LonaCraft.resource(b::WALL_SHEETS_JSON)
raw = nil
check("tilesets", "wall sheets JSON"){
next "missing #{b::WALL_SHEETS_JSON} (tools/build_wall_sheets.py)" unless File.exist?(path)
raw = LonaCraft::ConfigJSON.parse(File.open(path, "rb"){|f| f.read })
raw.is_a?(Hash) && raw["sheets"].is_a?(Hash) ? note("#{raw["sheets"].size} sheets") : "no \"sheets\" block"
}
sheets = raw.is_a?(Hash) && raw["sheets"].is_a?(Hash) ? raw["sheets"] : {}
ref = raw.is_a?(Hash) && raw["reference"].is_a?(Hash) ? raw["reference"] : {}
b::WALL_A4.each_key{|sheet|
check("tilesets", "wall sheet LonaCraft_#{sheet}"){
e = sheets[sheet]
next "no entry in #{b::WALL_SHEETS_JSON}" unless e.is_a?(Hash)
png = LonaCraft.resource("Graphics/Tilesets/#{e["file"]}.png")
next "missing #{png}" unless File.exist?(png)
bmp = Bitmap.new(png)
bad = []
["wood", "stone"].each{|key|
kinds = e[key]
want = ref[key]
next bad << "#{key}: no kinds" unless kinds.is_a?(Array) && kinds.size == 2
got = [block_sum(bmp, a4_rect(kinds[0])), block_sum(bmp, a4_rect(kinds[1]))]
bad << "#{key} #{kinds.inspect} art changed" if want.is_a?(Array) && got != want
}
bmp.dispose
bad.empty? ? note("wood #{e["wood"].inspect}, stone #{e["stone"].inspect}") : bad.join("; ")
}
}
# the floor sheets: the shack's two boards in each family's A5 copy
floors = raw.is_a?(Hash) && raw["floors"].is_a?(Hash) ? raw["floors"] : {}
want = raw.is_a?(Hash) ? raw["reference_floor"] : nil
check("tilesets", "floor sheets in #{b::WALL_SHEETS_JSON}"){
floors.empty? ? "no \"floors\" block (tools/build_wall_sheets.py)" : note("#{floors.size} A5 sheets")
}
floors.each{|sheet, e|
check("tilesets", "floor sheet LonaCraft_#{sheet}"){
next "bad entry" unless e.is_a?(Hash) && e["boards"].is_a?(Array) && e["boards"].size == 2
png = LonaCraft.resource("Graphics/Tilesets/#{e["file"]}.png")
next "missing #{png}" unless File.exist?(png)
bmp = Bitmap.new(png)
got = e["boards"].map{|t| n = t.to_i - 1536; block_sum(bmp, Rect.new((n % 8) * 32, (n / 8) * 32, 32, 32)) }
bmp.dispose
next "boards #{e["boards"].inspect} art changed" if want.is_a?(Array) && got != want
note("boards #{e["boards"].inspect}")
}
}
end
def self.check_tilesets
TILESETS.each{|id, name, sheets, where|
check("tilesets", "tileset #{id} #{name}"){
ts = $data_tilesets[id]
next "missing (#{where})" if ts.nil?
next "named #{ts.name.to_s.inspect}, expected #{name.inspect} (#{where})" if ts.name.to_s != name
got = ts.tileset_names.map{|x| x.to_s }
got == sheets ? nil : "sheets #{got.inspect}, expected #{sheets.inspect} (#{where})"
}
}
b = const("LonaCraft::Bases")
[[:WALL_A4, 3, "A4"], [:FLOOR_TILE, 4, "A5"]].each{|cname, slot, label|
table = b && b.const_defined?(cname) ? b.const_get(cname) : {}
table.each_key{|sheet|
check("tilesets", "#{label} sheet #{sheet}"){
list = $data_tilesets.is_a?(Hash) ? $data_tilesets.values : $data_tilesets
ids = list.compact.select{|ts| ts.tileset_names[slot].to_s == sheet }.map{|ts| ts.id }
ids.empty? ? "no tileset has it as its #{label} sheet (110_Bases.rb #{cname})" : note("tilesets #{ids.join(", ")}")
}
}
}
end
def self.check_maps
MAPS.each{|id, name, tileset, where|
check("maps", "Map#{sprintf("%03d", id)} #{name}"){
info = $data_mapinfos[id]
next "map #{id} missing (#{where})" if info.nil?
next "map #{id} is #{info.name.to_s.inspect}, expected #{name.inspect}; #{name} is now #{map_id(name).inspect} (#{where})" if info.name.to_s != name
next nil if tileset.nil?
m = game_map(id)
m.tileset_id == tileset ? nil : "tileset #{m.tileset_id}, expected #{tileset} (#{where})"
}
}
MAP_EVENTS.each{|id, ev_id, sheet, where|
check("maps", "Map#{sprintf("%03d", id)} event #{ev_id}"){
ev = game_map(id).events[ev_id]
next "missing (#{where})" if ev.nil?
got = ev.pages[0].graphic.character_name.to_s
got == sheet ? nil : "picture #{got.inspect}, expected #{sheet.inspect} (#{where})"
}
}
n = const("LonaCraft::Nodes")
families = n ? (n::LOOSE_MAPS.keys + n::BOULDER_MAPS.keys).uniq.sort : []
families.each{|fam|
check("maps", "r#{fam}_ map family"){
found = $data_mapinfos.values.count{|i| i && i.name.to_s =~ /\Ar#{fam}_/ }
found > 0 ? note("#{found} maps") : "no map named r#{fam}_... (45_Nodes.rb LOOSE_MAPS / BOULDER_MAPS)"
}
}
check("maps", "$data_region_maps filled"){
$data_region_maps.empty? ? "empty (5_DataManager.rb load_tag_and_reg_maps; 110_Bases.rb pins field maps from it)" : note("#{$data_region_maps.size} regions")
}
Dir.glob(LonaCraft.resource("Maps/*.rvdata2")).sort.each{|path|
check("maps", "mod Maps/#{File.basename(path)}"){
m = load_data(path)
next "not an RPG::Map" unless m.is_a?(RPG::Map)
ts = $data_tilesets[m.tileset_id]
ts.nil? ? "tileset #{m.tileset_id} missing" : note("#{m.width} x #{m.height}, tileset #{m.tileset_id} #{ts.name}")
}
}
homes = const("LonaCraft::Homes")
check("maps", "home maps registered"){
next skip("100_Homes.rb not loaded or off") unless homes && homes.enabled?
missing = homes::LOCATIONS.select{|l| l[:interior].is_a?(Array) }.reject{|l|
$data_mapinfos[LonaCraft.resource(l[:interior][0].to_s)]
}.map{|l| l[:id] }
missing.empty? ? nil : "not in $data_mapinfos: #{missing.join(", ")} (100_Homes.rb register_maps)"
}
check("maps", "Deep Sewer registered"){
s = const("LonaCraft::Sewer")
next skip("130_Sewer.rb not loaded") unless s
$data_mapinfos[s::KEY] ? nil : "#{s::KEY} not in $data_mapinfos (130_Sewer.rb)"
}
# the grate and landing tiles must stay free of map events (a game update could move them)
s = const("LonaCraft::Sewer")
(s ? s::ENTRANCES : []).each{|ent|
check("maps", "Deep Sewer grate #{ent[:id]}"){
ids = $data_tag_maps.is_a?(Hash) ? $data_tag_maps[ent[:tag]] : nil
id = ids.is_a?(Array) ? ids.first : nil
next "no map with the tag #{ent[:tag]} (130_Sewer.rb ENTRANCES)" if id.nil?
m = game_map(id)
taken = [ent[:grate], ent[:out]].select{|x, y| m.events.values.any?{|e| e && e.x == x && e.y == y } }
next "map event on #{taken.inspect} (130_Sewer.rb ENTRANCES #{ent[:id]}; the grate is skipped in game)" unless taken.empty?
in_map?(m, ent[:grate][0], ent[:grate][1]) ? note("Map#{sprintf("%03d", id)} (#{ent[:grate].join(",")})") : "grate tile outside the map"
}
}
end
def self.check_game_files
GAME_FILES.each{|path, where|
check("files", path){
next skip("packed game") if packed?
if path.include?("*")
Dir.glob(path).empty? ? "no file matches (#{where})" : nil
else
File.exist?(path) ? nil : "missing (#{where})"
end
}
}
# every game script file cited in METHODS
have = {}
Dir.glob("Data/Scripts/**/*.rb").each{|f| have[File.basename(f)] = true }
cited = []
METHODS.each{|row| row[4].scan(/([A-Za-z0-9_&\-]+\.rb):\d+/){|m| cited << m[0] } } # & and - occur in game file names (97_Game_Actor_Stats&State&Nap.rb)
cited.uniq.each{|file|
next if File.exist?(LonaCraft.resource("Scripts/#{file}")) # one of the mod's own
check("files", "Data/Scripts/.../#{file}"){
next skip("packed game") if packed? || have.empty?
have[file] ? nil : "cited in 98_SelfTest.rb METHODS but not under Data/Scripts (the line numbers in the mod's comments are stale)"
}
}
# the mod's redirects of game scripts ($mod_load_script, 102_ScriptImport.rb:63)
[["LonaCraft::Homes", :SELLERS], ["LonaCraft::Nodes", :TREE_SCRIPTS], ["LonaCraft::Mercs", :GUILD_SCRIPTS]].each{|path, cname|
mod = const(path)
next if mod.nil? || !mod.const_defined?(cname)
list = mod.const_get(cname)
list = list.values.map{|v| v[0] } if list.is_a?(Hash)
list.each{|script|
check("files", "redirect #{script}"){
next skip("#{path} off") if mod.respond_to?(:enabled?) && !mod.enabled?
want = mod.wrapper_script(script)
got = $mod_load_script[script]
got == want ? nil : "$mod_load_script points to #{got.inspect}, expected #{want} (#{path} install_redirects)"
}
}
}
end
def self.check_text_keys
lists = text_keys
total = lists.values.inject(0){|sum, l| sum + l.size }
lists.each{|file, keys|
next if keys.empty?
check("text", "keys in #{file}"){
missing = keys.reject{|f, id| !f.start_with?("?") && eng(f).has_key?(id) }
missing.empty? ? note("#{keys.size} keys") : "not in Text/ENG: #{missing.map{|f, id| "LonaCraft:#{f}:#{id}" }.join(", ")}"
}
}
check("text", "LonaCraft text part registered"){
parts = $game_text.instance_variable_get(:@parts)
next "Text has no @parts (121_Dialog_Control_System.rb:76, 15_Text.rb eng_path)" unless parts.is_a?(Hash)
parts["LonaCraft"] ? note("#{total} literal keys checked") : "no \"LonaCraft\" part (_ModInfo.json \"texts\", ModManager#link_texts)"
}
end
def self.check_json_files
files = Dir.glob(LonaCraft.resource("Recipes/*.json")).sort + Dir.glob(LonaCraft.resource("Config/*.json")).sort
files << LonaCraft.resource("_ModInfo.json")
files.each{|path|
check("json", path.sub(LonaCraft.path + "/", "")){
LonaCraft::ConfigJSON.parse(read(path))
nil
}
}
check("json", "Item/*.json"){
bad = []
list = Dir.glob(LonaCraft.resource("Item/*.json")).sort
list.each{|path|
begin
LonaCraft::ConfigJSON.parse(read(path))
rescue => e
bad << "#{File.basename(path)} (#{e.message})"
end
}
bad.empty? ? note("#{list.size} files") : bad.join(", ")
}
end
def self.check_item_ids
lists = [["materials and building pieces", "0_Core.rb ITEMS", LonaCraft::ITEM_NAMES]]
fur = const("LonaCraft::Furniture::ITEM_NAMES")
lists << ["furniture", "90_Furniture.rb KINDS", fur] if fur
lists.each{|label, where, names|
check("ids", "#{label} have ids"){
bad = names.select{|name|
obj = $data_ItemName[name]
obj.nil? || obj.id.to_i < 1 || !$data_items[obj.id].equal?(obj)
}
bad.empty? ? note("#{names.size} items") : "no id or not in $data_items: #{bad.join(", ")} (#{where})"
}
}
# the mod's weapons (the Hatchet, owner 2026-10-07): main-hand
# RPG::Weapon in $data_weapons, held picture built, no quality tiers
wn = const("LonaCraft::WEAPON_NAMES")
if wn
check("ids", "weapons are main-hand weapons"){
bad = wn.select{|name|
obj = $data_ItemName[name]
obj.nil? || !obj.is_a?(RPG::Weapon) || obj.id.to_i < 1 || !$data_weapons[obj.id].equal?(obj)
}
next "not a weapon in $data_weapons: #{bad.join(", ")} (0_Core.rb load_weapons)" unless bad.empty?
pick = $data_ItemName["ItemMhPickAxe"]
odd = wn.select{|name|
obj = $data_ItemName[name]
(pick && obj.etype_id != pick.etype_id) || obj.lonaStat.nil? ||
(defined?(LonaCraft::Tiers) && LonaCraft::Tiers.craftable?(name))
}
odd.empty? ? note("#{wn.size} weapon(s), main hand, held picture, no tiers") : "other slot than the pickaxe, no held picture or tiered: #{odd.join(", ")} (0_Core.rb load_weapons, 50_Tiers.rb)"
}
end
# the Hatchet's held picture (owner 2026-10-07): RolePlayS's axe when
# that mod is loaded, else the Wooden Club; either way the "MainArm"
# value must name a part in Lona's layer table ($chs_data["Lona"])
if const("LonaCraft::HATCHET_NAME")
check("ids", "Hatchet held picture is in Lona's layer table"){
obj = $data_ItemName[LonaCraft::HATCHET_NAME]
value = obj && obj.lonaStat ? obj.lonaStat.affectValue.to_s : nil
next "the Hatchet has no held picture (0_Core.rb load_weapons)" if value.nil?
look = value == LonaCraft::HATCHET_AXE_LOOK["value"] ? "RolePlayS axe" : "Wooden Club"
LonaCraft.held_part?(value) ? note("MainArm #{value} (#{look})") : "no MainArm part #{value} (#{look}) in $chs_data[\"Lona\"] (0_Core.rb held_part?, hatchet_look)"
}
end
check("ids", "no duplicate item names"){
tiers = const("LonaCraft::Tiers::BASE_OF") || {}
count = Hash.new(0)
[$data_items, $data_weapons, $data_armors].each{|list|
(list || []).each{|obj|
next if obj.nil?
name = (obj.respond_to?(:item_name) && obj.item_name) ? obj.item_name.to_s : obj.name.to_s
next unless name.start_with?("ItemLonaCraft") || tiers.has_key?(name)
count[name] += 1
}
}
dup = count.keys.select{|name| count[name] > 1 }
dup.empty? ? note("#{count.size} names") : "more than once: #{dup.join(", ")}"
}
end
def self.check_places
fur = const("LonaCraft::Furniture")
(fur ? fur::TOWN_STATIONS : []).each{|name, x, y, key, mode|
check("places", "town #{key} on #{name} (#{x},#{y})"){
id = map_id(name)
next "no map named #{name} (90_Furniture.rb TOWN_STATIONS)" if id.nil?
m = game_map(id)
if mode == :existing
ev = event_at(m, x, y)
next "no map event to hook on (#{x},#{y}) (90_Furniture.rb TOWN_STATIONS :existing)" if ev.nil? || ev.name.to_s =~ /\A-point-|\ALonaCraft/
next note("hooks #{ev.name}")
end
kind = fur.kind_by_key(key)
next "no furniture kind #{key}" if kind.nil?
bad = fur.footprint(kind, x, y).reject{|tx, ty|
in_map?(m, tx, ty) && event_at(m, tx, ty).nil? && tile_pass?(m, tx, ty)
}
bad.empty? ? nil : "tiles taken or blocked: #{bad.map{|t| "(#{t[0]},#{t[1]})" }.join(" ")} (90_Furniture.rb TOWN_STATIONS)"
}
}
homes = const("LonaCraft::Homes")
(homes ? homes::LOCATIONS : []).each{|loc|
check("places", "home #{loc[:id]}"){
next skip("100_Homes.rb off") unless homes.enabled?
if loc[:door].is_a?(Array)
name, x, y = loc[:door]
id = map_id(name)
next "no map named #{name} (100_Homes.rb LOCATIONS :door)" if id.nil?
m = game_map(id)
next "door (#{x},#{y}) is off the map #{name}" unless in_map?(m, x, y)
ev = event_at(m, x, y)
next "door tile (#{x},#{y}) on #{name} has the map event #{ev.name} (100_Homes.rb :door)" if ev
end
if loc[:interior].is_a?(Array) && !File.exist?(LonaCraft.resource(loc[:interior][0].to_s))
next "missing #{loc[:interior][0]} (100_Homes.rb :interior)"
end
if loc[:map]
id = map_id(loc[:map])
next "no map named #{loc[:map]} (100_Homes.rb LOCATIONS :map)" if id.nil?
m = game_map(id)
sx, sy = loc[:room_seed]
next "room seed (#{sx},#{sy}) is off the map" unless in_map?(m, sx, sy)
next "room seed (#{sx},#{sy}) on #{loc[:map]} is not walkable (100_Homes.rb :room_seed)" unless tile_pass?(m, sx, sy)
off = (loc[:door_tiles] || []).reject{|tx, ty| in_map?(m, tx, ty) }
next "door tiles off the map: #{off.inspect}" unless off.empty?
end
if loc[:nap_script] && !packed? && !File.exist?(loc[:nap_script].to_s)
next "missing #{loc[:nap_script]} (100_Homes.rb :nap_script)"
end
if loc[:nap_script]
want = homes.wrapper_script(loc[:nap_script])
got = $mod_load_script[loc[:nap_script]]
next "nap script not redirected: #{got.inspect}, expected #{want} (100_Homes.rb install_redirects)" unless got == want
end
if loc[:map] && ROOM_TILES[loc[:id]]
m = game_map(map_id(loc[:map]))
ts = $data_tilesets[m.tileset_id]
tiles = homes.flood_room(m.data, ts.flags, m.width, m.height, loc)
next "room has #{tiles.size} tiles, docs/RESEARCH_INNS.md 4 says #{ROOM_TILES[loc[:id]]}" unless tiles.size == ROOM_TILES[loc[:id]]
next note("#{tiles.size} room tiles")
end
nil
}
}
end
def self.check_save_and_loader
check("save", "save remap registry"){
reg = LonaCraft::Save.payload["registry"]
next "empty (70_Save.rb payload)" if reg.nil? || reg.empty?
gone = (LonaCraft::ITEM_NAMES + (const("LonaCraft::WEAPON_NAMES") || [])).reject{|name| reg.has_key?(name) }
gone.empty? ? note("#{reg.size} ids") : "materials or weapons missing from it: #{gone.join(", ")} (70_Save.rb payload)"
}
scripts = loader_scripts
check("loader", "every Scripts/*.rb is in loader.rb"){
files = Dir.glob(LonaCraft.resource("Scripts/*.rb")).map{|f| File.basename(f) }.sort
gone = files - scripts
gone.empty? ? note("#{scripts.size} scripts") : "not loaded: #{gone.join(", ")}"
}
check("loader", "0_Core.rb first, 98_SelfTest.rb last"){
next "first is #{scripts.first}" unless scripts.first == "0_Core.rb"
scripts.last == "98_SelfTest.rb" ? nil : "last is #{scripts.last}"
}
LOAD_ORDER.each{|a, b, where|
check("loader", "#{a} before #{b}"){
ia = scripts.index(a)
ib = scripts.index(b)
next skip("#{ia ? b : a} not in loader.rb") if ia.nil? || ib.nil?
ia < ib ? nil : "#{a} loads after #{b} (#{where})"
}
}
end
def self.check_runtime
check("runtime", "recipes built"){
n = LonaCraft::Recipes.all.length
n > 0 ? note("#{n} recipes") : "no recipes (55_Recipes.rb build, see the console)"
}
LonaCraft::Stations::LIST.each{|st|
check("runtime", "recipes at station #{st}"){
n = LonaCraft::Recipes.for_station(st).length
n > 0 ? note("#{n} recipes") : "none (55_Recipes.rb Stations)"
}
}
check("runtime", "tier variants"){
n = LonaCraft::Tiers::BASE_OF.size
c = LonaCraft::Tiers::CRAFTABLE.size
n > 0 && c > 0 ? note("#{c} craftable bases, #{n} variants") : "#{c} craftable bases, #{n} variants (50_Tiers.rb generate_variants)"
}
check("runtime", "salvage recipes and plants"){
s = LonaCraft.salvage_recipes.size
f = LonaCraft.fibre_items.size
s > 0 && f > 0 ? note("#{s} salvage recipes, #{f} plants") : "#{s} salvage recipes (Salvage/), #{f} plants (30_Process.rb build_fibre_items)"
}
mods = ["Config", "TextFallback", "Stations", "Recipes", "ConfigJSON", "RecipeConfig", "Tiers", "Skill",
"Save", "CraftUI", "MenuCraft", "Furniture", "Homes", "Nodes", "Bases", "Raids", "Debug"]
mods << "Sewer" if loader_scripts.include?("130_Sewer.rb")
mods << "AwayRaids" if loader_scripts.include?("140_AwayRaids.rb")
mods << "Mercs" if loader_scripts.include?("150_Mercs.rb")
mods << "Rest" if loader_scripts.include?("160_Rest.rb")
mods << "Maid" if loader_scripts.include?("170_Maid.rb")
mods << "Shops" if loader_scripts.include?("25_Shops.rb")
check("runtime", "LonaCraft modules loaded"){
gone = mods.reject{|m| const("LonaCraft::#{m}").is_a?(Module) }
gone.empty? ? note("#{mods.size} modules") : "missing: #{gone.join(", ")}"
}
check("runtime", "Bases and Raids answer"){
next "110_Bases.rb or 120_Raids.rb not loaded" unless const("LonaCraft::Bases") && const("LonaCraft::Raids")
b = LonaCraft::Bases.enabled?
r = LonaCraft::Raids.enabled?
note("bases #{b ? "on" : "off"}, raids #{r ? "on" : "off"}")
}
check("runtime", "Config/Recipes_defaults.json text"){
text = LonaCraft::RecipeConfig.defaults_text(LonaCraft::Recipes.all)
LonaCraft::ConfigJSON.parse(text)
note("#{text.length} bytes, parses")
}
check("runtime", "Config/Shops_defaults.json text and Config/Shops.json"){
next skip("25_Shops.rb not loaded") unless const("LonaCraft::Shops")
text = LonaCraft::Shops.defaults_text
LonaCraft::ConfigJSON.parse(text)
user = LonaCraft::Shops.user_path
LonaCraft::ConfigJSON.parse(read(user)) if File.exist?(user)
note("#{text.length} bytes, parses; #{File.exist?(user) ? "Config/Shops.json parses" : "no Config/Shops.json"}")
}
check("runtime", "Config/Bases_defaults.json text"){
next skip("120_Raids.rb not loaded") unless const("LonaCraft::Raids")
text = LonaCraft::Raids.defaults_text
LonaCraft::ConfigJSON.parse(text)
note("#{text.length} bytes, parses")
}
check_difficulty
check("runtime", "Config/LonaCraft.json"){
st = LonaCraft::Config.status
st.start_with?("read") || st.include?("not found") ? note(st) : st
}
end
# R10 difficulty (120_Raids.rb DEFAULTS "difficulty", Config/Bases.json,
# docs/RESEARCH_DIFFICULTY.md section 4)
DANGER_TEXT = ["Danger/opt", "Danger/lower", "Danger/normal", "Danger/higher",
"Danger/now_lower", "Danger/now_normal", "Danger/now_higher", "Danger/busy"]
DANGER_KNOBS = ["roll_add", "away_chance_mult", "extra_raiders_add", "sewer_chance_add"]
TEXT_LANGS = ["CHT", "ENG", "KOR", "RUS", "RUS2", "UKR"]
def self.check_difficulty
raids = const("LonaCraft::Raids")
if raids.nil? || !const("LonaCraft::Raids::LEVELS")
check("runtime", "difficulty"){ skip("120_Raids.rb not loaded or without levels") }
return
end
dd = raids::DEFAULTS["difficulty"]
knobs = dd["hard"].keys
check("runtime", "difficulty levels have every knob"){
bad = []
raids::LEVELS.each{|lv|
[["defaults", dd[lv]], ["config", raids.cfg["difficulty"][lv]]].each{|src, t|
unless t.is_a?(Hash)
bad << "#{src} #{lv} missing"
next
end
miss = knobs.reject{|k| t[k].is_a?(Numeric) }
bad << "#{src} #{lv} lacks #{miss.join(" ")}" unless miss.empty?
neg = knobs.select{|k| k.end_with?("_mult") && t[k].is_a?(Numeric) && t[k] < 0 }
bad << "#{src} #{lv} negative factor #{neg.join(" ")}" unless neg.empty?
}
}
["lower", "higher"].each{|st|
t = raids.cfg["difficulty"]["base_danger"][st]
miss = t.is_a?(Hash) ? DANGER_KNOBS.reject{|k| t[k].is_a?(Numeric) } : DANGER_KNOBS
bad << "base_danger #{st} lacks #{miss.join(" ")}" unless miss.empty?
}
bad.empty? ? note("#{raids::LEVELS.size} levels x #{knobs.size} knobs, base_danger lower / higher") : "#{bad.join("; ")} (120_Raids.rb DEFAULTS difficulty)"
}
check("runtime", "difficulty hard is today's numbers"){
off = knobs.reject{|k| dd["hard"][k] == raids.knob_identity(k) }
next "defaults hard is not 0 / 1.0 for #{off.join(" ")} (120_Raids.rb DEFAULTS difficulty hard)" unless off.empty?
user = raids.cfg["difficulty"]["hard"]
changed = knobs.reject{|k| user[k] == raids.knob_identity(k) }
changed.empty? ? note("#{knobs.size} knobs, all 0 / 1.0") : note("defaults pinned; Config/Bases.json changes hard #{changed.join(" ")}")
}
check("runtime", "difficulty level names a table"){
want = raids.cfg["difficulty"]["level"].to_s
if raids::LEVELS.include?(want)
note("#{raids.level_name} (Config/Bases.json)")
else
"#{want.inspect} is not #{raids::LEVELS.join(", ")}: hard used (Config/Bases.json difficulty level)"
end
}
check("text", "Danger keys in 6 languages"){
parser = $game_text.is_a?(Text) ? $game_text : Text.new("Text/ENG")
bad = []
TEXT_LANGS.each{|lang|
path = LonaCraft.resource("Text/#{lang}/Bases.txt")
unless File.exist?(path)
bad << "#{lang} no Bases.txt"
next
end
keys = parser.parse(read(path).force_encoding("UTF-8"))
miss = DANGER_TEXT.reject{|k| keys.has_key?(k) }
bad << "#{lang} lacks #{miss.join(" ")}" unless miss.empty?
}
bad.empty? ? note("#{DANGER_TEXT.size} keys x #{TEXT_LANGS.size}") : "#{bad.join("; ")} (Text/<lang>/Bases.txt)"
}
end
#----------------------------------------------------------------------
# Boot, log, report
#----------------------------------------------------------------------
def self.enabled?
LonaCraft.debug? && LonaCraft::Config.get("self_test", true) == true
end
def self.log_path
LonaCraft::Config.get("self_test_log", LonaCraft::Config::DEFAULTS["self_test_log"]).to_s
end
# Called from the DataManager.load_mod_database alias below, once.
def self.boot
return if @ran
@ran = true
return unless enabled?
run
rescue StandardError, ScriptError, SystemStackError => e
p "LonaCraft self-test could not run: #{e.class} #{e.message}"
end
def self.run
@results = []
@maps = {}
@eng = {}
@loader = nil
started = Time.now
begin
run_checks
rescue StandardError, ScriptError, SystemStackError => e
record("runner", "run_checks", :fail, "stopped early: #{e.class} #{e.message}")
end
ms = ((Time.now - started) * 1000).round
@maps = {} # let the map data go
fails = @results.select{|r| r[2] == :fail }
counted = @results.count{|r| r[2] != :skip }
skips = @results.size - counted
path = log_path
written = write_log(path, fails, counted, skips, ms)
where = written ? path : "#{path} (could not be written, see the console)"
if fails.empty?
p "LonaCraft self-test: #{counted} checks passed (#{skips} skipped, #{ms} ms), log #{where}"
else
fails.each{|g, n, s, why| p "LonaCraft self-test FAIL [#{g}] #{n}: #{why}" }
fmt = LonaCraft::TextFallback.get("Info", "SelfTest/failed", "%d of %d checks failed. See %s.")
tail = (format(fmt, fails.size, counted, where) rescue format("%d of %d checks failed. See %s.", fails.size, counted, where))
msgbox("LonaCraft self-test: #{tail}")
end
end
def self.header
lines = []
lines << "LonaCraft self-test"
lines << "Date: #{Time.now.strftime("%Y-%m-%d %H:%M:%S")}"
game = (DataManager.export_full_ver_info rescue "?")
vid = (sprintf("0x%X", $data_system.version_id) rescue "?")
lines << "Game: #{game} (DataManager.export_full_ver_info; version_id #{vid})"
info = (LonaCraft::ConfigJSON.parse(read(LonaCraft.resource("_ModInfo.json"))) rescue Hash.new)
info = {} unless info.is_a?(Hash)
lines << "Mod: LonaCraft #{info["version"] || "?"} (_ModInfo.json), folder #{LonaCraft.path}"
lines << "Config: #{LonaCraft::Config.status}: debug #{LonaCraft.debug?}, self_test #{LonaCraft::Config.get("self_test", true)}"
order = (($mod_manager.load_order || []).each_with_index.map{|m, i|
"#{i + 1}. #{m.id} #{m.version}#{m.enabled ? "" : " (off)"}"
} rescue ["?"])
lines << "Load order: #{order.join(" | ")}"
scripts = (loader_scripts.join(", ") rescue "?")
lines << "Scripts: #{scripts}"
lines
end
def self.write_log(path, fails, counted, skips, ms)
lines = header
lines << "Result: #{fails.size} of #{counted} checks failed, #{skips} skipped, #{ms} ms"
lines << ""
unless fails.empty?
lines << "FAILURES"
fails.each{|g, n, s, why| lines << " FAIL [#{g}] #{n}: #{why}" }
lines << ""
end
lines << "ALL CHECKS"
tags = {:pass => "pass", :fail => "FAIL", :skip => "skip"}
@results.each{|g, n, s, why|
lines << " #{tags[s]} [#{g}] #{n}#{why.empty? ? "" : ": #{why}"}"
}
dir = File.dirname(path)
Dir.mkdir(dir) unless dir == "." || File.directory?(dir)
File.open(path, "wb"){|f|
lines.each{|l|
s = u(l)
s.force_encoding("ASCII-8BIT")
f.write(s)
f.write("\n")
}
}
true
rescue StandardError => e
p "LonaCraft self-test: cannot write #{path} (#{e.class} #{e.message})"
false
end
end
end
# Read Config/LonaCraft.json now if no earlier script did (55_Recipes.rb, its
# parser, is loaded), so the debug keys and the self-test see it from the start.
LonaCraft::Config.load
module DataManager
unless respond_to?(:load_mod_database_lonacraft_selftest)
self.singleton_class.send(:alias_method, :load_mod_database_lonacraft_selftest, :load_mod_database)
def self.load_mod_database
load_mod_database_lonacraft_selftest # every LonaCraft part loads its data first
LonaCraft::SelfTest.boot
end
end
end