Initial flame_lua_runtime package
This commit is contained in:
98
test/runtime/rendering/runtime_viewport_test.dart
Normal file
98
test/runtime/rendering/runtime_viewport_test.dart
Normal file
@@ -0,0 +1,98 @@
|
||||
import 'package:flame/components.dart';
|
||||
import 'package:flame_lua_runtime/runtime/display/runtime_viewport.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
group('RuntimeViewport', () {
|
||||
test('fits design size inside screen with letterboxing', () {
|
||||
final transform = RuntimeViewport.compute(
|
||||
screenSize: Vector2(1280, 720),
|
||||
config: const RuntimeViewportConfig(
|
||||
designWidth: 720,
|
||||
designHeight: 720,
|
||||
),
|
||||
);
|
||||
|
||||
expect(transform.x, 280);
|
||||
expect(transform.y, 0);
|
||||
expect(transform.width, 720);
|
||||
expect(transform.height, 720);
|
||||
expect(transform.scaleX, 1);
|
||||
expect(transform.scaleY, 1);
|
||||
});
|
||||
|
||||
test('fills screen by preserving aspect ratio and cropping', () {
|
||||
final transform = RuntimeViewport.compute(
|
||||
screenSize: Vector2(1280, 720),
|
||||
config: const RuntimeViewportConfig(
|
||||
designWidth: 720,
|
||||
designHeight: 720,
|
||||
scaleMode: RuntimeScaleMode.fill,
|
||||
),
|
||||
);
|
||||
|
||||
expect(transform.x, 0);
|
||||
expect(transform.y, -280);
|
||||
expect(transform.width, 1280);
|
||||
expect(transform.height, 1280);
|
||||
expect(transform.scaleX, closeTo(1.777777, 0.00001));
|
||||
expect(transform.scaleY, closeTo(1.777777, 0.00001));
|
||||
});
|
||||
|
||||
test('stretches design independently on both axes', () {
|
||||
final transform = RuntimeViewport.compute(
|
||||
screenSize: Vector2(1440, 720),
|
||||
config: const RuntimeViewportConfig(
|
||||
designWidth: 720,
|
||||
designHeight: 720,
|
||||
scaleMode: RuntimeScaleMode.stretch,
|
||||
),
|
||||
);
|
||||
|
||||
expect(transform.x, 0);
|
||||
expect(transform.y, 0);
|
||||
expect(transform.width, 1440);
|
||||
expect(transform.height, 720);
|
||||
expect(transform.scaleX, 2);
|
||||
expect(transform.scaleY, 1);
|
||||
});
|
||||
|
||||
test('centers design without scaling', () {
|
||||
final transform = RuntimeViewport.compute(
|
||||
screenSize: Vector2(1000, 800),
|
||||
config: const RuntimeViewportConfig(
|
||||
designWidth: 720,
|
||||
designHeight: 720,
|
||||
scaleMode: RuntimeScaleMode.none,
|
||||
),
|
||||
);
|
||||
|
||||
expect(transform.x, 140);
|
||||
expect(transform.y, 40);
|
||||
expect(transform.width, 720);
|
||||
expect(transform.height, 720);
|
||||
expect(transform.scaleX, 1);
|
||||
expect(transform.scaleY, 1);
|
||||
});
|
||||
|
||||
test('applies transform to root component', () {
|
||||
final root = PositionComponent();
|
||||
RuntimeViewport.apply(
|
||||
root,
|
||||
const RuntimeViewportTransform(
|
||||
x: 10,
|
||||
y: 20,
|
||||
width: 300,
|
||||
height: 400,
|
||||
scaleX: 2,
|
||||
scaleY: 3,
|
||||
scaleMode: RuntimeScaleMode.stretch,
|
||||
),
|
||||
);
|
||||
|
||||
expect(root.position, Vector2(10, 20));
|
||||
expect(root.size, Vector2(300, 400));
|
||||
expect(root.scale, Vector2(2, 3));
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user