fix: Fix initial loading
This commit is contained in:
parent
36afe1466c
commit
dcd08db47a
4 changed files with 28 additions and 20 deletions
|
@ -49,7 +49,7 @@ local function get_item(obj, func_name)
|
||||||
local item = table.clone(item_template)
|
local item = table.clone(item_template)
|
||||||
item.obj = obj
|
item.obj = obj
|
||||||
item.name = func_name
|
item.name = func_name
|
||||||
item.func = get_func(func_name)
|
item.func = get_func(obj, func_name)
|
||||||
|
|
||||||
-- Save
|
-- Save
|
||||||
table.insert(MODS_HOOKS, item)
|
table.insert(MODS_HOOKS, item)
|
||||||
|
@ -121,8 +121,8 @@ end
|
||||||
--
|
--
|
||||||
-- Set hook
|
-- Set hook
|
||||||
--
|
--
|
||||||
local function set(mod_name, func_name, hook_func)
|
local function set(mod_name, obj, func_name, hook_func)
|
||||||
local item = get_item(func_name)
|
local item = get_item(obj, func_name)
|
||||||
local item_hook = get_item_hook(item, mod_name)
|
local item_hook = get_item_hook(item, mod_name)
|
||||||
|
|
||||||
print_log_info(mod_name, "Hooking " .. func_name)
|
print_log_info(mod_name, "Hooking " .. func_name)
|
||||||
|
|
|
@ -1,10 +1,14 @@
|
||||||
|
local StateGame = require("scripts/game_states/state_game")
|
||||||
|
local StateSplash = require("scripts/game_states/game/state_splash")
|
||||||
|
local GameStateMachine = require("scripts/foundation/utilities/game_state_machine")
|
||||||
|
|
||||||
-- The loader object that is used during game boot
|
-- The loader object that is used during game boot
|
||||||
-- to initialize the modding environment.
|
-- to initialize the modding environment.
|
||||||
local loader = {}
|
local loader = {}
|
||||||
|
|
||||||
Mods = {}
|
Mods = {}
|
||||||
|
|
||||||
function loader:init(libs, mod_data, boot_gui)
|
function loader:init(mod_data, libs, boot_gui)
|
||||||
-- The metatable prevents overwriting these
|
-- The metatable prevents overwriting these
|
||||||
self._libs = setmetatable({}, { __index = libs })
|
self._libs = setmetatable({}, { __index = libs })
|
||||||
Mods.lua = self._libs
|
Mods.lua = self._libs
|
||||||
|
@ -15,18 +19,19 @@ function loader:init(libs, mod_data, boot_gui)
|
||||||
dofile("scripts/mods/dml/hook")
|
dofile("scripts/mods/dml/hook")
|
||||||
|
|
||||||
local ModLoader = dofile("scripts/mods/dml/mod_loader")
|
local ModLoader = dofile("scripts/mods/dml/mod_loader")
|
||||||
local mod_loader = ModLoader:new(boot_gui, mod_data)
|
local mod_loader = ModLoader:new(mod_data, libs, boot_gui)
|
||||||
self._mod_loader = mod_loader
|
self._mod_loader = mod_loader
|
||||||
|
Managers.mod = mod_loader
|
||||||
|
|
||||||
-- The mod loader needs to remain active during game play, to
|
-- The mod loader needs to remain active during game play, to
|
||||||
-- enable reloads
|
-- enable reloads
|
||||||
Mods.hook.set("DML", GameState, "update", function(func, dt, ...)
|
Mods.hook.set("DML", StateGame, "update", function(func, dt, ...)
|
||||||
mod_loader:update(dt)
|
mod_loader:update(dt)
|
||||||
return func(dt, ...)
|
return func(dt, ...)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
-- Skip splash view
|
-- Skip splash view
|
||||||
Mods.hook.set("Base", StateSplash, "on_enter", function(func, self, ...)
|
Mods.hook.set("DML", StateSplash, "on_enter", function(func, self, ...)
|
||||||
local result = func(self, ...)
|
local result = func(self, ...)
|
||||||
|
|
||||||
self._should_skip = true
|
self._should_skip = true
|
||||||
|
@ -36,7 +41,7 @@ function loader:init(libs, mod_data, boot_gui)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
-- Trigger state change events
|
-- Trigger state change events
|
||||||
Mods.hook.set("Base", GameStateMachine, "_change_state", function(func, self, ...)
|
Mods.hook.set("DML", GameStateMachine, "_change_state", function(func, self, ...)
|
||||||
local old_state = self._state
|
local old_state = self._state
|
||||||
local old_state_name = old_state and self:current_state_name()
|
local old_state_name = old_state and self:current_state_name()
|
||||||
|
|
||||||
|
@ -57,7 +62,7 @@ function loader:init(libs, mod_data, boot_gui)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
-- Trigger ending state change event
|
-- Trigger ending state change event
|
||||||
Mods.hook.set("Base", GameStateMachine, "destroy", function(func, self, ...)
|
Mods.hook.set("DML", GameStateMachine, "destroy", function(func, self, ...)
|
||||||
local old_state = self._state
|
local old_state = self._state
|
||||||
local old_state_name = old_state and self:current_state_name()
|
local old_state_name = old_state and self:current_state_name()
|
||||||
|
|
||||||
|
@ -75,7 +80,7 @@ function loader:update(dt)
|
||||||
|
|
||||||
local done = mod_loader:all_mods_loaded()
|
local done = mod_loader:all_mods_loaded()
|
||||||
if done then
|
if done then
|
||||||
mod_loader:_remove_gui()
|
mod_loader:remove_gui()
|
||||||
end
|
end
|
||||||
|
|
||||||
return done
|
return done
|
||||||
|
|
|
@ -3,6 +3,10 @@
|
||||||
-- the purpose of loading mods within Warhammer 40,000: Darktide.
|
-- the purpose of loading mods within Warhammer 40,000: Darktide.
|
||||||
local ModLoader = class("ModLoader")
|
local ModLoader = class("ModLoader")
|
||||||
|
|
||||||
|
local ScriptGui = require("scripts/foundation/utilities/script_gui")
|
||||||
|
|
||||||
|
local FONT_MATERIAL = "content/ui/fonts/arial"
|
||||||
|
|
||||||
local LOG_LEVELS = {
|
local LOG_LEVELS = {
|
||||||
spew = 4,
|
spew = 4,
|
||||||
info = 3,
|
info = 3,
|
||||||
|
@ -19,8 +23,9 @@ local BUTTON_INDEX_R = Keyboard.button_index("r")
|
||||||
local BUTTON_INDEX_LEFT_SHIFT = Keyboard.button_index("left shift")
|
local BUTTON_INDEX_LEFT_SHIFT = Keyboard.button_index("left shift")
|
||||||
local BUTTON_INDEX_LEFT_CTRL = Keyboard.button_index("left ctrl")
|
local BUTTON_INDEX_LEFT_CTRL = Keyboard.button_index("left ctrl")
|
||||||
|
|
||||||
ModLoader.init = function(self, boot_gui, mod_data)
|
ModLoader.init = function(self, mod_data, libs, boot_gui)
|
||||||
self._mod_data = mod_data
|
self._mod_data = mod_data
|
||||||
|
self._libs = libs
|
||||||
self._gui = boot_gui
|
self._gui = boot_gui
|
||||||
|
|
||||||
self._settings = Application.user_setting("mod_settings") or DEFAULT_SETTINGS
|
self._settings = Application.user_setting("mod_settings") or DEFAULT_SETTINGS
|
||||||
|
@ -31,10 +36,6 @@ ModLoader.init = function(self, boot_gui, mod_data)
|
||||||
self._reload_data = {}
|
self._reload_data = {}
|
||||||
self._ui_time = 0
|
self._ui_time = 0
|
||||||
|
|
||||||
if Crashify then
|
|
||||||
Crashify.print_property("modded", true)
|
|
||||||
end
|
|
||||||
|
|
||||||
self._state = "scanning"
|
self._state = "scanning"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -55,7 +56,9 @@ ModLoader._draw_state_to_gui = function(self, gui, dt)
|
||||||
status_str = string.format("Loading mod %q", mod.name)
|
status_str = string.format("Loading mod %q", mod.name)
|
||||||
end
|
end
|
||||||
|
|
||||||
Gui.text(gui, status_str .. string.rep(".", (2 * t) % 4), "materials/fonts/arial", 16, nil, Vector3(5, 10, 1))
|
local msg = status_str .. string.rep(".", (2 * t) % 4)
|
||||||
|
Log.info("ModLoader", msg)
|
||||||
|
ScriptGui.text(gui, msg, FONT_MATERIAL, 48, Vector3(20, 30, 1), Color.white())
|
||||||
end
|
end
|
||||||
|
|
||||||
ModLoader.remove_gui = function(self)
|
ModLoader.remove_gui = function(self)
|
||||||
|
@ -120,9 +123,9 @@ ModLoader.update = function(self, dt)
|
||||||
|
|
||||||
if not ok then self:print("error", "%s", object) end
|
if not ok then self:print("error", "%s", object) end
|
||||||
|
|
||||||
local name = mod.name
|
|
||||||
mod.object = object or {}
|
mod.object = object or {}
|
||||||
|
|
||||||
|
self:_run_callback(mod, "init", self._reload_data[mod.id])
|
||||||
self:print("info", "%s loaded.", name)
|
self:print("info", "%s loaded.", name)
|
||||||
|
|
||||||
self._state = self:_load_mod(self._mod_load_index + 1)
|
self._state = self:_load_mod(self._mod_load_index + 1)
|
||||||
|
@ -197,6 +200,7 @@ ModLoader._build_mod_table = function(self)
|
||||||
name = mod_data.name,
|
name = mod_data.name,
|
||||||
loaded_packages = {},
|
loaded_packages = {},
|
||||||
packages = mod_data.packages,
|
packages = mod_data.packages,
|
||||||
|
data = mod_data,
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -6,12 +6,11 @@ Mods.original_require = original_require
|
||||||
|
|
||||||
local can_insert = function(filepath, new_result)
|
local can_insert = function(filepath, new_result)
|
||||||
local store = require_store[filepath]
|
local store = require_store[filepath]
|
||||||
local num_store = #store
|
if not store or #store then
|
||||||
if not store or num_store == 0 then
|
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
if store[num_store] ~= new_result then
|
if store[#store] ~= new_result then
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue