Initial flame_lua_runtime package

This commit is contained in:
gem
2026-06-07 22:53:58 +08:00
commit 733b2fb798
262 changed files with 28439 additions and 0 deletions

View File

@@ -0,0 +1,72 @@
import 'package:flame_lua_runtime/runtime/diagnostics/runtime_diagnostics.dart';
import 'package:flame_lua_runtime/runtime/game/flame_lua_game.dart';
import 'package:flame_lua_runtime/runtime/models/game_diff.dart';
import 'package:flame_lua_runtime/runtime/models/runtime_event.dart';
import 'package:flame_lua_runtime/runtime/packages/game_package.dart';
import 'package:flame_lua_runtime/runtime/packages/game_package_manifest.dart';
import 'package:flame_lua_runtime/runtime/packages/game_package_repository.dart';
import 'package:flame_lua_runtime/runtime/scripting/script_engine.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
group('FlameLuaGame diagnostics debug access', () {
test('exposes diagnostics entries, dump text and debug json', () {
final diagnostics = RuntimeDiagnostics()
..record(
type: RuntimeDiagnosticType.commandError,
message: 'command failed',
context: {'command': 'play_bgm'},
);
final game = FlameLuaGame(
scriptEngine: _FakeScriptEngine(),
packageRepository: _FakePackageRepository(),
gameId: 'ludo',
diagnostics: diagnostics,
);
expect(game.diagnosticEntries, hasLength(1));
expect(game.diagnosticsDumpText(), contains('command failed'));
expect(game.diagnosticsDebugJson()['count'], 1);
expect(game.resourcesDebugJson(), {'initialized': false});
});
});
}
class _FakeScriptEngine implements ScriptEngine {
@override
Future<void> loadPackage(GamePackage package) {
throw UnimplementedError();
}
@override
GameDiff dispatchEvent(RuntimeEvent event) {
throw UnimplementedError();
}
@override
GameDiff init(Map<String, Object?> context) {
throw UnimplementedError();
}
@override
bool smokeTest(Map<String, Object?> context) {
throw UnimplementedError();
}
}
class _FakePackageRepository implements GamePackageRepository {
@override
Future<GamePackage> load(String gameId) async {
return GamePackage.asset(
rootPath: 'example/assets/games/$gameId',
manifest: GamePackageManifest(
gameId: gameId,
name: gameId,
version: 'test',
runtimeApiVersion: 1,
entry: 'scripts/main.lua',
assetsBase: 'assets',
),
);
}
}

View File

@@ -0,0 +1,63 @@
import 'dart:ui' show Locale;
import 'package:flame_lua_runtime/runtime/game/runtime_locale.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
group('RuntimeLocaleResolver', () {
test('normalizes locale tags', () {
expect(RuntimeLocaleResolver.normalizeTag('zh_hans_cn'), 'zh-Hans-CN');
expect(RuntimeLocaleResolver.normalizeTag('EN-us'), 'en-US');
expect(RuntimeLocaleResolver.tagOf(const Locale('zh', 'CN')), 'zh-CN');
});
test('resolves exact, language and fallback locales', () {
expect(
RuntimeLocaleResolver.resolve(
requested: const Locale.fromSubtags(
languageCode: 'zh',
scriptCode: 'Hans',
),
defaultLocale: 'en',
supportedLocales: const ['zh-Hans', 'en'],
).resolved,
'zh-Hans',
);
expect(
RuntimeLocaleResolver.resolve(
requested: const Locale('en', 'US'),
defaultLocale: 'zh-Hans',
supportedLocales: const ['zh-Hans', 'en'],
).resolved,
'en',
);
expect(
RuntimeLocaleResolver.resolve(
requested: const Locale('fr', 'FR'),
defaultLocale: 'zh-Hans',
supportedLocales: const ['zh-Hans', 'en'],
).resolved,
'zh-Hans',
);
});
test('exports locale context for Lua', () {
final info = RuntimeLocaleResolver.resolve(
requested: const Locale('en', 'US'),
defaultLocale: 'zh-Hans',
supportedLocales: const ['zh-Hans', 'en'],
);
expect(info.toMap(), {
'requested': 'en-US',
'resolved': 'en',
'default': 'zh-Hans',
'supported': ['zh-Hans', 'en'],
'languageCode': 'en',
'countryCode': 'US',
});
});
});
}