refactor: Replace I/O-based requires
With the switch back to bundle-based mod distribution, we can now use the built-in `require`/`dofile`.
This commit is contained in:
parent
b0b7395f02
commit
9486af9177
12 changed files with 45 additions and 113 deletions
|
@ -3,9 +3,6 @@ local dmf
|
|||
-- Native mod object used by Fatshark mod manager
|
||||
local dmf_mod_object = {}
|
||||
|
||||
-- Global method to load a file through iowith a return
|
||||
local io_dofile = Mods.file.dofile
|
||||
|
||||
-- Global backup of original print() method
|
||||
local print = __print
|
||||
|
||||
|
@ -14,38 +11,37 @@ local print = __print
|
|||
-- #####################################################################################################################
|
||||
|
||||
function dmf_mod_object:init()
|
||||
io_dofile("dmf/scripts/mods/dmf/modules/dmf_mod_data")
|
||||
io_dofile("dmf/scripts/mods/dmf/modules/dmf_mod_manager")
|
||||
--io_dofile("dmf/scripts/mods/dmf/modules/dmf_dummy")
|
||||
io_dofile("dmf/scripts/mods/dmf/modules/dmf_package_manager")
|
||||
io_dofile("dmf/scripts/mods/dmf/modules/core/safe_calls")
|
||||
io_dofile("dmf/scripts/mods/dmf/modules/core/events")
|
||||
io_dofile("dmf/scripts/mods/dmf/modules/core/settings")
|
||||
io_dofile("dmf/scripts/mods/dmf/modules/core/logging")
|
||||
io_dofile("dmf/scripts/mods/dmf/modules/core/misc")
|
||||
io_dofile("dmf/scripts/mods/dmf/modules/core/persistent_tables")
|
||||
io_dofile("dmf/scripts/mods/dmf/modules/core/io")
|
||||
dofile("dmf/scripts/mods/dmf/modules/dmf_mod_data")
|
||||
dofile("dmf/scripts/mods/dmf/modules/dmf_mod_manager")
|
||||
-- dofile("dmf/scripts/mods/dmf/modules/dmf_dummy")
|
||||
dofile("dmf/scripts/mods/dmf/modules/dmf_package_manager")
|
||||
dofile("dmf/scripts/mods/dmf/modules/core/safe_calls")
|
||||
dofile("dmf/scripts/mods/dmf/modules/core/events")
|
||||
dofile("dmf/scripts/mods/dmf/modules/core/settings")
|
||||
dofile("dmf/scripts/mods/dmf/modules/core/logging")
|
||||
dofile("dmf/scripts/mods/dmf/modules/core/misc")
|
||||
dofile("dmf/scripts/mods/dmf/modules/core/persistent_tables")
|
||||
dofile("dmf/scripts/mods/dmf/modules/core/io")
|
||||
|
||||
-- DMF's internal io module is now loaded:
|
||||
dmf = get_mod("DMF")
|
||||
|
||||
dmf:io_dofile("dmf/scripts/mods/dmf/modules/debug/dev_console")
|
||||
dmf:io_dofile("dmf/scripts/mods/dmf/modules/debug/table_dump")
|
||||
dmf:io_dofile("dmf/scripts/mods/dmf/modules/core/hooks")
|
||||
dmf:io_dofile("dmf/scripts/mods/dmf/modules/core/require")
|
||||
dmf:io_dofile("dmf/scripts/mods/dmf/modules/core/toggling")
|
||||
dmf:io_dofile("dmf/scripts/mods/dmf/modules/core/keybindings")
|
||||
dmf:io_dofile("dmf/scripts/mods/dmf/modules/core/chat")
|
||||
dmf:io_dofile("dmf/scripts/mods/dmf/modules/core/localization")
|
||||
dmf:io_dofile("dmf/scripts/mods/dmf/modules/core/options")
|
||||
dmf:io_dofile("dmf/scripts/mods/dmf/modules/core/network")
|
||||
dmf:io_dofile("dmf/scripts/mods/dmf/modules/core/commands")
|
||||
dmf:io_dofile("dmf/scripts/mods/dmf/modules/gui/custom_textures")
|
||||
dmf:io_dofile("dmf/scripts/mods/dmf/modules/gui/custom_views")
|
||||
dmf:io_dofile("dmf/scripts/mods/dmf/modules/ui/chat/chat_actions")
|
||||
dmf:io_dofile("dmf/scripts/mods/dmf/modules/ui/options/mod_options")
|
||||
dmf:io_dofile("dmf/scripts/mods/dmf/modules/dmf_options")
|
||||
dmf:io_dofile("dmf/scripts/mods/dmf/modules/core/mutators/mutators_manager")
|
||||
dmf:dofile("dmf/scripts/mods/dmf/modules/debug/dev_console")
|
||||
dmf:dofile("dmf/scripts/mods/dmf/modules/debug/table_dump")
|
||||
dmf:dofile("dmf/scripts/mods/dmf/modules/core/hooks")
|
||||
dmf:dofile("dmf/scripts/mods/dmf/modules/core/require")
|
||||
dmf:dofile("dmf/scripts/mods/dmf/modules/core/toggling")
|
||||
dmf:dofile("dmf/scripts/mods/dmf/modules/core/keybindings")
|
||||
dmf:dofile("dmf/scripts/mods/dmf/modules/core/chat")
|
||||
dmf:dofile("dmf/scripts/mods/dmf/modules/core/localization")
|
||||
dmf:dofile("dmf/scripts/mods/dmf/modules/core/options")
|
||||
dmf:dofile("dmf/scripts/mods/dmf/modules/core/network")
|
||||
dmf:dofile("dmf/scripts/mods/dmf/modules/core/commands")
|
||||
dmf:dofile("dmf/scripts/mods/dmf/modules/gui/custom_textures")
|
||||
dmf:dofile("dmf/scripts/mods/dmf/modules/gui/custom_views")
|
||||
dmf:dofile("dmf/scripts/mods/dmf/modules/ui/chat/chat_actions")
|
||||
dmf:dofile("dmf/scripts/mods/dmf/modules/ui/options/mod_options")
|
||||
dmf:dofile("dmf/scripts/mods/dmf/modules/dmf_options")
|
||||
dmf:dofile("dmf/scripts/mods/dmf/modules/core/mutators/mutators_manager")
|
||||
|
||||
dmf.delayed_chat_messages_hook()
|
||||
dmf:hook(ModManager, "destroy", function(func, ...)
|
||||
|
|
|
@ -119,64 +119,10 @@ local function handle_io(mod, local_path, file_name, file_extension, args, safe_
|
|||
end
|
||||
end
|
||||
|
||||
|
||||
-- Return whether the file exists at the given path
|
||||
local function file_exists(local_path, file_name, file_extension)
|
||||
local file_path = get_file_path(local_path, file_name, file_extension)
|
||||
local f = _io.open(file_path,"r")
|
||||
|
||||
if f ~= nil then
|
||||
_io.close(f)
|
||||
return true
|
||||
else
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
-- #####################################################################################################################
|
||||
-- ##### DMFMod ########################################################################################################
|
||||
-- #####################################################################################################################
|
||||
|
||||
-- Use the io library to execute the given file with a pcall, without return
|
||||
function DMFMod:io_exec(local_path, file_name, file_extension, args)
|
||||
return handle_io(self, local_path, file_name, file_extension, args, true, "exec_boolean")
|
||||
end
|
||||
|
||||
|
||||
-- Use the io library to execute the given file without a pcall, without return
|
||||
function DMFMod:io_exec_unsafe(local_path, file_name, file_extension, args)
|
||||
return handle_io(self, local_path, file_name, file_extension, args, false, "exec_boolean")
|
||||
end
|
||||
|
||||
|
||||
-- Use the io library to execute the given file with a pcall and return the result
|
||||
function DMFMod:io_exec_with_return(local_path, file_name, file_extension, args)
|
||||
return handle_io(self, local_path, file_name, file_extension, args, true, "exec_result")
|
||||
end
|
||||
|
||||
|
||||
-- Use the io library to execute the given file without a pcall and return the result
|
||||
function DMFMod:io_exec_unsafe_with_return(local_path, file_name, file_extension, args)
|
||||
return handle_io(self, local_path, file_name, file_extension, args, false, "exec_result")
|
||||
end
|
||||
|
||||
|
||||
-- Use the io library to execute the given file with a pcall and return the result,
|
||||
-- but treat the first parameter as the entire path to the file, and assume .lua.
|
||||
-- IO version of the dofile method with a pcall.
|
||||
function DMFMod:io_dofile(file_path)
|
||||
return handle_io(self, file_path, nil, nil, nil, true, "exec_result")
|
||||
end
|
||||
|
||||
|
||||
-- Use the io library to execute the given file without a pcall and return the result,
|
||||
-- but treat the first parameter as the entire path to the file, and assume .lua.
|
||||
-- IO version of the dofile method.
|
||||
function DMFMod:io_dofile_unsafe(file_path)
|
||||
return handle_io(self, file_path, nil, nil, nil, false, "exec_result")
|
||||
end
|
||||
|
||||
|
||||
-- Use the io library to return the contents of the given file
|
||||
function DMFMod:io_read_content(file_path, file_extension)
|
||||
return handle_io(self, file_path, nil, file_extension, nil, true, "data")
|
||||
|
@ -199,4 +145,4 @@ end
|
|||
|
||||
-- #####################################################################################################################
|
||||
-- ##### Script ########################################################################################################
|
||||
-- #####################################################################################################################
|
||||
-- #####################################################################################################################
|
||||
|
|
|
@ -138,5 +138,5 @@ end
|
|||
-- ##### Script #######################################################################################################
|
||||
-- ####################################################################################################################
|
||||
|
||||
local localization_table = dmf:io_dofile("dmf/localization/dmf")
|
||||
local localization_table = dmf:dofile("dmf/localization/dmf")
|
||||
dmf.initialize_mod_localization(dmf, localization_table)
|
||||
|
|
|
@ -27,11 +27,11 @@ local _mutators_sorted = false
|
|||
local _all_mutators_disabled = false
|
||||
|
||||
-- External modules
|
||||
local reward_manager = dmf:io_dofile("dmf/scripts/mods/dmf/modules/core/mutators/mutators_reward")
|
||||
local set_lobby_data = dmf:io_dofile("dmf/scripts/mods/dmf/modules/core/mutators/mutators_info")
|
||||
local reward_manager = dmf:dofile("dmf/scripts/mods/dmf/modules/core/mutators/mutators_reward")
|
||||
local set_lobby_data = dmf:dofile("dmf/scripts/mods/dmf/modules/core/mutators/mutators_info")
|
||||
|
||||
-- Get default configuration
|
||||
local _default_config = dmf:io_dofile("dmf/scripts/mods/dmf/modules/core/mutators/mutators_default_config")
|
||||
local _default_config = dmf:dofile("dmf/scripts/mods/dmf/modules/core/mutators/mutators_default_config")
|
||||
|
||||
-- List of enabled mutators in case DMF is reloaded in the middle of the game
|
||||
local _enabled_mutators = dmf:persistent_table("enabled_mutators")
|
||||
|
@ -505,4 +505,4 @@ end
|
|||
-- #####################################################################################################################
|
||||
|
||||
-- Testing
|
||||
--dmf:io_dofile("dmf/scripts/mods/dmf/modules/core/mutators/test/mutators_test")
|
||||
--dmf:dofile("dmf/scripts/mods/dmf/modules/core/mutators/test/mutators_test")
|
||||
|
|
|
@ -65,7 +65,7 @@ end
|
|||
-- Handles the swap to io for registered files and the application of file hooks
|
||||
dmf:hook(_G, "require", function (func, path, ...)
|
||||
if _io_requires[path] then
|
||||
return dmf:io_dofile(path)
|
||||
return dmf:dofile(path)
|
||||
else
|
||||
local result = func(path, ...)
|
||||
|
||||
|
@ -85,4 +85,4 @@ end)
|
|||
|
||||
-- #####################################################################################################################
|
||||
-- ##### Script ########################################################################################################
|
||||
-- #####################################################################################################################
|
||||
-- #####################################################################################################################
|
||||
|
|
|
@ -91,16 +91,6 @@ function dmf.safe_call_dofile(mod, error_prefix_data, file_path)
|
|||
end
|
||||
|
||||
|
||||
-- Safe Call [io_dofile]
|
||||
function dmf.safe_call_io_dofile(mod, error_prefix_data, file_path)
|
||||
if type(file_path) ~= "string" then
|
||||
show_error(mod, error_prefix_data, "file path should be a string.")
|
||||
return false
|
||||
end
|
||||
return dmf.safe_call(mod, error_prefix_data, mod.io_dofile_unsafe, mod, file_path)
|
||||
end
|
||||
|
||||
|
||||
-- Format error message and throw error.
|
||||
function dmf.throw_error(error_message, ...)
|
||||
error(string.format(error_message, ...), 0)
|
||||
|
|
|
@ -50,7 +50,7 @@ local function resolve_resource(mod, error_prefix_data, resource, resource_value
|
|||
local type_value = type(resource_value)
|
||||
|
||||
if type_value == "string" then
|
||||
return dmf.safe_call_io_dofile(mod, error_prefix_data, resource_value)
|
||||
return dmf.safe_call_dofile(mod, error_prefix_data, resource_value)
|
||||
elseif type_value == "function" then
|
||||
return dmf.safe_call(mod, error_prefix_data, resource_value, mod)
|
||||
elseif type_value == "table" then
|
||||
|
|
|
@ -33,7 +33,7 @@ local _queued_command
|
|||
|
||||
local function initialize_drawing_function()
|
||||
if not _commands_list_gui_draw then
|
||||
local commands_list_gui = dmf:io_dofile("dmf/scripts/mods/dmf/modules/ui/chat/commands_list_gui")
|
||||
local commands_list_gui = dmf:dofile("dmf/scripts/mods/dmf/modules/ui/chat/commands_list_gui")
|
||||
_commands_list_gui_draw = commands_list_gui.draw
|
||||
_commands_list_gui_destroy = commands_list_gui.destroy
|
||||
end
|
||||
|
@ -310,4 +310,4 @@ if _chat_history_save then
|
|||
_chat_history = dmf:get("chat_history") or _chat_history
|
||||
end
|
||||
|
||||
initialize_drawing_function()
|
||||
initialize_drawing_function()
|
||||
|
|
|
@ -30,8 +30,8 @@ end
|
|||
-- ##### DMF Options View Class #######################################################################################
|
||||
-- ####################################################################################################################
|
||||
|
||||
local _content_blueprints = dmf:io_dofile("dmf/scripts/mods/dmf/modules/ui/options/dmf_options_view_content_blueprints")
|
||||
local _view_settings = dmf:io_dofile("dmf/scripts/mods/dmf/modules/ui/options/dmf_options_view_settings")
|
||||
local _content_blueprints = dmf:dofile("dmf/scripts/mods/dmf/modules/ui/options/dmf_options_view_content_blueprints")
|
||||
local _view_settings = dmf:dofile("dmf/scripts/mods/dmf/modules/ui/options/dmf_options_view_settings")
|
||||
|
||||
local InputUtils = require("scripts/managers/input/input_utils")
|
||||
local ScriptWorld = require("scripts/foundation/utilities/script_world")
|
||||
|
@ -51,7 +51,7 @@ local _last_selected_category_widget
|
|||
local DMFOptionsView = class("DMFOptionsView", "BaseView")
|
||||
|
||||
DMFOptionsView.init = function (self, settings)
|
||||
local definitions = dmf:io_dofile("dmf/scripts/mods/dmf/modules/ui/options/dmf_options_view_definitions")
|
||||
local definitions = dmf:dofile("dmf/scripts/mods/dmf/modules/ui/options/dmf_options_view_definitions")
|
||||
|
||||
DMFOptionsView.super.init(self, definitions, settings)
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
local dmf = get_mod("DMF")
|
||||
|
||||
local _view_settings = dmf:io_dofile("dmf/scripts/mods/dmf/modules/ui/options/dmf_options_view_settings")
|
||||
local _view_settings = dmf:dofile("dmf/scripts/mods/dmf/modules/ui/options/dmf_options_view_settings")
|
||||
|
||||
local ButtonPassTemplates = require("scripts/ui/pass_templates/button_pass_templates")
|
||||
local CheckboxPassTemplates = require("scripts/ui/pass_templates/checkbox_pass_templates")
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
local dmf = get_mod("DMF")
|
||||
|
||||
local _view_settings = dmf:io_dofile("dmf/scripts/mods/dmf/modules/ui/options/dmf_options_view_settings")
|
||||
local _view_settings = dmf:dofile("dmf/scripts/mods/dmf/modules/ui/options/dmf_options_view_settings")
|
||||
|
||||
local ScrollbarPassTemplates = require("scripts/ui/pass_templates/scrollbar_pass_templates")
|
||||
local UIFontSettings = require("scripts/managers/ui/ui_font_settings")
|
||||
|
|
|
@ -607,7 +607,7 @@ dmf.initialize_dmf_options_view = function ()
|
|||
}
|
||||
})
|
||||
|
||||
dmf:io_dofile("dmf/scripts/mods/dmf/modules/ui/options/dmf_options_view")
|
||||
dmf:dofile("dmf/scripts/mods/dmf/modules/ui/options/dmf_options_view")
|
||||
end
|
||||
|
||||
-- ####################################################################################################################
|
||||
|
|
Loading…
Add table
Reference in a new issue