WIP: mod_main logging and more DML specialication
DML's package needs to be added to the boot bundle as well. Current issue: Adding any package file to the bundle breaks the game's loading. But I don't know where this messes things up.
This commit is contained in:
parent
44a0b9a651
commit
b20b3c4e66
2 changed files with 49 additions and 10 deletions
|
@ -1,3 +1,4 @@
|
|||
print("[mod_main] Initializing mods...")
|
||||
-- Keep a backup of certain system libraries before
|
||||
-- Fatshark's code scrubs them.
|
||||
-- The loader can then decide to pass them on to mods, or ignore them
|
||||
|
@ -11,10 +12,14 @@ local libs = {
|
|||
loadstring = loadstring,
|
||||
}
|
||||
|
||||
require("scripts/main")
|
||||
print("[mod_main] 'scripts/main' loaded")
|
||||
|
||||
require("scripts/game_states/boot/state_boot_sub_state_base")
|
||||
local StateBootLoadMods = class("StateBootLoadMods", "StateBootSubStateBase")
|
||||
|
||||
StateBootLoadMods.on_enter = function (self, parent, params)
|
||||
print("[mod_main][StateBootLoadMods] Entered")
|
||||
StateBootLoadMods.super.on_enter(self, parent, params)
|
||||
|
||||
local state_params = self:_state_params()
|
||||
|
@ -31,6 +36,7 @@ StateBootLoadMods._state_update = function (self, dt)
|
|||
local package_manager = self._package_manager
|
||||
|
||||
if state == "load_package" and package_manager:update() then
|
||||
print("[mod_main][StateBootLoadMods] Packages loaded, loading mods")
|
||||
self._state = "load_mods"
|
||||
local mod_loader = require("scripts/mods/dml/init")
|
||||
self._mod_loader = mod_loader
|
||||
|
@ -38,18 +44,18 @@ StateBootLoadMods._state_update = function (self, dt)
|
|||
local mod_data = require("scripts/mods/mod_data")
|
||||
mod_loader:init(mod_data, libs, self._parent.gui)
|
||||
elseif state == "load_mods" and self._mod_loader:update(dt) then
|
||||
print("[mod_main][StateBootLoadMods] Mods loaded, exiting")
|
||||
return true, false
|
||||
end
|
||||
|
||||
return false, false
|
||||
end
|
||||
|
||||
require("scripts/main")
|
||||
|
||||
-- Patch `GameStateMachine.init` to add our own state for loading mods.
|
||||
-- In the future, Fatshark might provide us with a dedicated way to do this.
|
||||
local function patch_mod_loading_state()
|
||||
local GameStateMachine = require("scripts/foundations/utilities/game_state_machine")
|
||||
print("[mod_main] Adding mod loading state")
|
||||
local GameStateMachine = require("scripts/foundation/utilities/game_state_machine")
|
||||
|
||||
local GameStateMachine_init = GameStateMachine.init
|
||||
GameStateMachine.init = function(self, parent, start_state, params, ...)
|
||||
|
@ -58,18 +64,21 @@ local function patch_mod_loading_state()
|
|||
-- systems are at least loaded and can be hooked, even if they aren't
|
||||
-- running, yet.
|
||||
local pos = 4
|
||||
table.insert(params.state, pos, {
|
||||
table.insert(params.states, pos, {
|
||||
StateBootLoadMods,
|
||||
{
|
||||
package_manager = params.package_manager,
|
||||
},
|
||||
})
|
||||
|
||||
-- Clean up after us
|
||||
GameStateMachine.init = GameStateMachine_init
|
||||
|
||||
return GameStateMachine_init(self, parent, start_state, params, ...)
|
||||
end
|
||||
end
|
||||
|
||||
function init()
|
||||
Main.init()
|
||||
patch_mod_loading_state()
|
||||
Main:init()
|
||||
end
|
||||
|
|
|
@ -26,6 +26,7 @@ use crate::state::{ModInfo, PackageInfo, State};
|
|||
|
||||
const MOD_BUNDLE_NAME: &str = "packages/mods";
|
||||
const BOOT_BUNDLE_NAME: &str = "packages/boot";
|
||||
const DML_BUNDLE_NAME: &str = "packages/dml";
|
||||
const BUNDLE_DATABASE_NAME: &str = "bundle_database.data";
|
||||
const MOD_BOOT_SCRIPT: &str = "scripts/mod_main";
|
||||
const MOD_DATA_SCRIPT: &str = "scripts/mods/mod_data";
|
||||
|
@ -229,7 +230,11 @@ async fn build_bundles(state: Arc<State>) -> Result<()> {
|
|||
bundle.add_file(file);
|
||||
}
|
||||
|
||||
for mod_info in state.get_mods().iter().filter(|m| m.get_enabled()) {
|
||||
for mod_info in state
|
||||
.get_mods()
|
||||
.iter()
|
||||
.filter(|m| m.get_id() != "dml" && m.get_enabled())
|
||||
{
|
||||
let span = tracing::trace_span!("building mod packages", name = mod_info.get_name());
|
||||
let _enter = span.enter();
|
||||
|
||||
|
@ -371,6 +376,8 @@ async fn patch_boot_bundle(state: Arc<State>) -> Result<()> {
|
|||
}
|
||||
}
|
||||
|
||||
pkg.add_file(BundleFileType::Lua, MOD_DATA_SCRIPT);
|
||||
|
||||
let mut variant = BundleFileVariant::new();
|
||||
variant.set_data(pkg.to_binary()?);
|
||||
let mut f = BundleFile::new(MOD_BUNDLE_NAME.to_string(), BundleFileType::Package);
|
||||
|
@ -379,6 +386,29 @@ async fn patch_boot_bundle(state: Arc<State>) -> Result<()> {
|
|||
bundle.add_file(f);
|
||||
}
|
||||
|
||||
{
|
||||
tracing::trace!("Adding dml package file to boot bundle");
|
||||
let span = tracing::trace_span!("create dml package file");
|
||||
let _enter = span.enter();
|
||||
|
||||
let mut variant = BundleFileVariant::new();
|
||||
|
||||
let mods = state.get_mods();
|
||||
let pkg_info = mods
|
||||
.iter()
|
||||
.find(|m| m.get_id() == "dml")
|
||||
.and_then(|info| info.get_packages().get(0));
|
||||
if let Some(pkg_info) = &pkg_info {
|
||||
let pkg = make_package(pkg_info).wrap_err("failed to create package file for dml")?;
|
||||
variant.set_data(pkg.to_binary()?);
|
||||
}
|
||||
|
||||
let mut f = BundleFile::new(DML_BUNDLE_NAME.to_string(), BundleFileType::Package);
|
||||
f.add_variant(variant);
|
||||
|
||||
bundle.add_file(f);
|
||||
}
|
||||
|
||||
{
|
||||
let span = tracing::debug_span!("Importing mod main script");
|
||||
let _enter = span.enter();
|
||||
|
@ -442,10 +472,10 @@ pub(crate) async fn deploy_mods(state: State) -> Result<()> {
|
|||
state.get_game_dir().join("bundle").display()
|
||||
);
|
||||
|
||||
tracing::info!("Build mod bundles");
|
||||
build_bundles(state.clone())
|
||||
.await
|
||||
.wrap_err("failed to build mod bundles")?;
|
||||
// tracing::info!("Build mod bundles");
|
||||
// build_bundles(state.clone())
|
||||
// .await
|
||||
// .wrap_err("failed to build mod bundles")?;
|
||||
|
||||
tracing::info!("Patch boot bundle");
|
||||
patch_boot_bundle(state.clone())
|
||||
|
|
Loading…
Add table
Reference in a new issue