feat: add Lua runtime storage API

This commit is contained in:
gem
2026-06-10 11:31:17 +08:00
parent 8ddc3be3a7
commit 6608d0a975
5 changed files with 162 additions and 1 deletions

View File

@@ -24,6 +24,7 @@ import '../display/runtime_viewport.dart';
import '../resources/game_resource_manager.dart';
import '../scripting/runtime_script_services.dart';
import '../scripting/script_engine.dart';
import '../storage/runtime_storage_manager.dart';
import 'runtime_locale.dart';
import 'runtime_options.dart';
@@ -73,6 +74,7 @@ class FlameLuaGame extends FlameGame with PanDetector, ScrollDetector {
late final PositionComponent _viewportRoot;
RuntimeNetworkManager? _network;
RuntimeHostBridgeManager? _hostBridgeManager;
RuntimeStorageManager? _storage;
RuntimeViewportConfig? _viewportConfig;
late final CommandExecutor _commands;
RuntimeSession? _session;
@@ -117,6 +119,7 @@ class FlameLuaGame extends FlameGame with PanDetector, ScrollDetector {
'initialized': true,
'images': _resources.imagesDebugJson(),
'audio': _audio.audioDebugJson(),
'storage': _storage?.debugJson() ?? const {},
};
}
@@ -142,6 +145,8 @@ class FlameLuaGame extends FlameGame with PanDetector, ScrollDetector {
diagnostics: diagnostics,
);
_hostBridgeManager = hostBridgeManager;
final storage = await RuntimeStorageManager.create(gameId: gameId);
_storage = storage;
final activation =
await PackageActivationController(
repository: _packageRepository,
@@ -155,6 +160,7 @@ class FlameLuaGame extends FlameGame with PanDetector, ScrollDetector {
scriptServices: RuntimeScriptServices(
network: network,
hostBridge: hostBridgeManager,
storage: storage,
),
store: StablePackageStore(runtimeOptions: runtimeOptions),
assetFallback: AssetGamePackageRepository(