feat: multi-package loading with base framework support

- Add RuntimeOptions.basePackages for loading framework packages before game package
- Add ScriptEngine.loadPackages() for multi-package module merging
- LuaDardoScriptEngine merges modules from all packages, game overrides framework
- PackageActivationController loads base packages first, then game package
- GamePackageManifest parses optional 'base' field
- Update docs: README, quick-start, lua-package-format, architecture
- Update all test mocks with loadPackages() implementation
This commit is contained in:
gem
2026-06-10 00:04:00 +08:00
parent 0d4fbd030c
commit 8ddc3be3a7
13 changed files with 255 additions and 7 deletions

View File

@@ -1,4 +1,5 @@
import '../audio/runtime_audio_manager.dart';
import '../game/runtime_options.dart';
import '../models/game_diff.dart';
import '../resources/game_resource_manager.dart';
import '../scripting/runtime_script_services.dart';
@@ -15,6 +16,7 @@ class PackageActivationController {
required this.scriptEngine,
this.audio,
this.runtimeApiVersion = 1,
this.runtimeOptions = const RuntimeOptions(),
this.store = const StablePackageStore(),
this.assetFallback = const AssetGamePackageRepository(),
this.resourceManagerFactory,
@@ -28,6 +30,7 @@ class PackageActivationController {
final ScriptEngine scriptEngine;
final RuntimeAudioManager? audio;
final int runtimeApiVersion;
final RuntimeOptions runtimeOptions;
final StablePackageStore store;
final GamePackageRepository assetFallback;
final GameResourceManager Function()? resourceManagerFactory;
@@ -143,12 +146,34 @@ class PackageActivationController {
try {
await verifier.verify(candidate);
_ensureContinue(shouldContinue);
// 加载 base packages框架包按 runtimeOptions.basePackages 顺序。
final basePackages = <GamePackage>[];
for (final baseId in runtimeOptions.basePackages) {
final baseCandidates = await _candidatePackages(
baseId,
shouldContinue,
);
for (final baseCandidate in baseCandidates) {
try {
await verifier.verify(baseCandidate);
basePackages.add(baseCandidate);
break;
} catch (_) {
// Try next candidate.
}
}
}
await preparedResources.mount(candidate);
_ensureContinue(shouldContinue);
await preparedAudio?.mount(candidate);
_ensureContinue(shouldContinue);
await preparedScriptEngine.loadPackage(
candidate,
// 合并 base + game 包,传给脚本引擎。
final allPackages = [...basePackages, candidate];
await preparedScriptEngine.loadPackages(
allPackages,
services: scriptServices,
);
_ensureContinue(shouldContinue);