239 lines
7.0 KiB
Dart
239 lines
7.0 KiB
Dart
import 'package:flame_lua_runtime/runtime/packages/game_package_manifest.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
|
|
void main() {
|
|
group('GamePackageManifest', () {
|
|
test('parses manifest with resources', () {
|
|
final manifest = GamePackageManifest.fromMap({
|
|
'gameId': 'ludo',
|
|
'name': 'Ludo',
|
|
'version': '0.1.0',
|
|
'runtimeApiVersion': 1,
|
|
'entry': 'scripts/main.lua',
|
|
'assetsBase': 'assets',
|
|
'defaultLocale': 'zh-Hans',
|
|
'supportedLocales': ['zh-Hans', 'en'],
|
|
'display': {
|
|
'designWidth': 720,
|
|
'designHeight': 1280,
|
|
'scaleMode': 'fit',
|
|
},
|
|
'modules': {
|
|
'runtime_ui': 'runtime:runtime_ui.lua',
|
|
'theme': 'scripts/theme.lua',
|
|
},
|
|
'resources': {
|
|
'board': {
|
|
'type': 'image',
|
|
'path': 'assets/board.png',
|
|
'atlas': 'assets/board.json',
|
|
'preload': 'lazy',
|
|
'group': 'board',
|
|
},
|
|
'roll': {'type': 'audio', 'path': 'assets/roll.mp3'},
|
|
'hero': {
|
|
'type': 'spine',
|
|
'atlas': 'assets/hero.atlas',
|
|
'skeleton': 'assets/hero.skel',
|
|
'preload': 'lazy',
|
|
'group': 'actors',
|
|
},
|
|
},
|
|
});
|
|
|
|
expect(manifest.gameId, 'ludo');
|
|
expect(manifest.name, 'Ludo');
|
|
expect(manifest.version, '0.1.0');
|
|
expect(manifest.runtimeApiVersion, 1);
|
|
expect(manifest.entry, 'scripts/main.lua');
|
|
expect(manifest.assetsBase, 'assets');
|
|
expect(manifest.defaultLocale, 'zh-Hans');
|
|
expect(manifest.supportedLocales, ['zh-Hans', 'en']);
|
|
expect(manifest.display.designWidth, 720);
|
|
expect(manifest.display.designHeight, 1280);
|
|
expect(manifest.display.scaleMode, 'fit');
|
|
expect(manifest.resources['board']?.type, 'image');
|
|
expect(manifest.resources['board']?.path, 'assets/board.png');
|
|
expect(manifest.resources['board']?.atlas, 'assets/board.json');
|
|
expect(manifest.resources['board']?.preload, GameResourcePreload.lazy);
|
|
expect(manifest.resources['board']?.group, 'board');
|
|
expect(manifest.resources['roll']?.type, GameResourceType.audio);
|
|
expect(manifest.resources['roll']?.preload, GameResourcePreload.required);
|
|
expect(manifest.resources['hero']?.type, GameResourceType.spine);
|
|
expect(manifest.resources['hero']?.atlas, 'assets/hero.atlas');
|
|
expect(manifest.resources['hero']?.skeleton, 'assets/hero.skel');
|
|
expect(manifest.resources['hero']?.path, isEmpty);
|
|
expect(manifest.modules, {
|
|
'runtime_ui': 'runtime:runtime_ui.lua',
|
|
'theme': 'scripts/theme.lua',
|
|
});
|
|
});
|
|
|
|
test('defaults assetsBase to assets', () {
|
|
final manifest = GamePackageManifest.fromMap({
|
|
'gameId': 'ludo',
|
|
'name': 'Ludo',
|
|
'version': '0.1.0',
|
|
'runtimeApiVersion': 1,
|
|
'entry': 'scripts/main.lua',
|
|
});
|
|
|
|
expect(manifest.assetsBase, 'assets');
|
|
expect(manifest.defaultLocale, 'en');
|
|
expect(manifest.supportedLocales, ['en']);
|
|
expect(manifest.display.designWidth, 720);
|
|
expect(manifest.display.designHeight, 720);
|
|
expect(manifest.display.scaleMode, 'fit');
|
|
expect(manifest.resources, isEmpty);
|
|
expect(manifest.modules, isEmpty);
|
|
});
|
|
|
|
test('rejects invalid required fields and resources', () {
|
|
expect(
|
|
() => GamePackageManifest.fromMap({
|
|
'gameId': '',
|
|
'name': 'Ludo',
|
|
'version': '0.1.0',
|
|
'runtimeApiVersion': 1,
|
|
'entry': 'scripts/main.lua',
|
|
}),
|
|
throwsFormatException,
|
|
);
|
|
|
|
expect(
|
|
() => GamePackageManifest.fromMap({
|
|
'gameId': 'ludo',
|
|
'name': 'Ludo',
|
|
'version': '0.1.0',
|
|
'runtimeApiVersion': '1',
|
|
'entry': 'scripts/main.lua',
|
|
}),
|
|
throwsFormatException,
|
|
);
|
|
|
|
expect(
|
|
() => GamePackageManifest.fromMap({
|
|
'gameId': 'ludo',
|
|
'name': 'Ludo',
|
|
'version': '0.1.0',
|
|
'runtimeApiVersion': 1,
|
|
'entry': 'scripts/main.lua',
|
|
'resources': {
|
|
'board': {'type': '', 'path': 'assets/board.png'},
|
|
},
|
|
}),
|
|
throwsFormatException,
|
|
);
|
|
|
|
expect(
|
|
() => GamePackageManifest.fromMap({
|
|
'gameId': 'ludo',
|
|
'name': 'Ludo',
|
|
'version': '0.1.0',
|
|
'runtimeApiVersion': 1,
|
|
'entry': 'scripts/main.lua',
|
|
'resources': {
|
|
'roll': {'type': 'sound', 'path': 'assets/roll.mp3'},
|
|
},
|
|
}),
|
|
throwsFormatException,
|
|
);
|
|
|
|
expect(
|
|
() => GamePackageManifest.fromMap({
|
|
'gameId': 'ludo',
|
|
'name': 'Ludo',
|
|
'version': '0.1.0',
|
|
'runtimeApiVersion': 1,
|
|
'entry': 'scripts/main.lua',
|
|
'modules': {'theme': 1},
|
|
}),
|
|
throwsFormatException,
|
|
);
|
|
|
|
expect(
|
|
() => GamePackageManifest.fromMap({
|
|
'gameId': 'ludo',
|
|
'name': 'Ludo',
|
|
'version': '0.1.0',
|
|
'runtimeApiVersion': 1,
|
|
'entry': 'scripts/main.lua',
|
|
'resources': {
|
|
'board': {
|
|
'type': 'image',
|
|
'path': 'assets/board.png',
|
|
'preload': 'eager',
|
|
},
|
|
},
|
|
}),
|
|
throwsFormatException,
|
|
);
|
|
|
|
expect(
|
|
() => GamePackageManifest.fromMap({
|
|
'gameId': 'ludo',
|
|
'name': 'Ludo',
|
|
'version': '0.1.0',
|
|
'runtimeApiVersion': 1,
|
|
'entry': 'scripts/main.lua',
|
|
'resources': {
|
|
'board': {'type': 'image', 'path': 'assets/board.png', 'group': ''},
|
|
},
|
|
}),
|
|
throwsFormatException,
|
|
);
|
|
|
|
expect(
|
|
() => GamePackageManifest.fromMap({
|
|
'gameId': 'ludo',
|
|
'name': 'Ludo',
|
|
'version': '0.1.0',
|
|
'runtimeApiVersion': 1,
|
|
'entry': 'scripts/main.lua',
|
|
'resources': {
|
|
'hero': {'type': 'spine', 'atlas': 'assets/hero.atlas'},
|
|
},
|
|
}),
|
|
throwsFormatException,
|
|
);
|
|
|
|
expect(
|
|
() => GamePackageManifest.fromMap({
|
|
'gameId': 'ludo',
|
|
'name': 'Ludo',
|
|
'version': '0.1.0',
|
|
'runtimeApiVersion': 1,
|
|
'entry': 'scripts/main.lua',
|
|
'defaultLocale': 'zh-Hans',
|
|
'supportedLocales': ['en'],
|
|
}),
|
|
throwsFormatException,
|
|
);
|
|
|
|
expect(
|
|
() => GamePackageManifest.fromMap({
|
|
'gameId': 'ludo',
|
|
'name': 'Ludo',
|
|
'version': '0.1.0',
|
|
'runtimeApiVersion': 1,
|
|
'entry': 'scripts/main.lua',
|
|
'display': {'designWidth': 0},
|
|
}),
|
|
throwsFormatException,
|
|
);
|
|
|
|
expect(
|
|
() => GamePackageManifest.fromMap({
|
|
'gameId': 'ludo',
|
|
'name': 'Ludo',
|
|
'version': '0.1.0',
|
|
'runtimeApiVersion': 1,
|
|
'entry': 'scripts/main.lua',
|
|
'display': {'scaleMode': 'zoom'},
|
|
}),
|
|
throwsFormatException,
|
|
);
|
|
});
|
|
});
|
|
}
|