From 47baf20ac794246790d441b9dc69b1c55d87d2a5 Mon Sep 17 00:00:00 2001 From: Lukas Klingsbo Date: Thu, 5 Oct 2023 12:50:42 +0200 Subject: [PATCH] Add golden tests --- doc/flame/camera_component.md | 1 + .../camera_component_prescale_test.png | Bin 0 -> 604 bytes .../camera_component_prescale_zoom_test.png | Bin 0 -> 614 bytes .../test/camera/camera_component_test.dart | 83 ++++++++++++++++++ 4 files changed, 84 insertions(+) create mode 100644 packages/flame/test/_goldens/camera_component_prescale_test.png create mode 100644 packages/flame/test/_goldens/camera_component_prescale_zoom_test.png diff --git a/doc/flame/camera_component.md b/doc/flame/camera_component.md index d11c261bbca..bbb88a04fd4 100644 --- a/doc/flame/camera_component.md +++ b/doc/flame/camera_component.md @@ -188,6 +188,7 @@ you want to have a static `ParallaxComponent` beneath a world that you can move around it. Example: + ```dart camera.backdrop.add(MyStaticBackground()); ``` diff --git a/packages/flame/test/_goldens/camera_component_prescale_test.png b/packages/flame/test/_goldens/camera_component_prescale_test.png new file mode 100644 index 0000000000000000000000000000000000000000..240ae845150bec9824e0e9e8ea2bd24be5eaefb3 GIT binary patch literal 604 zcmV-i0;BzjP)Px#1am@3R0s$N2z&@+hyVZr21!IgRA_2-rUHh;bj8$e!yWxDi0|UJ8JX#%bMSwoS($IdY7@dvBcuW zQqTCu+yJCR+*3iLbd#97BK*bLuC{1bTRr1%w~NgaHh=vk6B(l{lL(R`;>_*&g~ewV zD}1@M+SQi6+ixnBBA?Iq?T^J`V8PdgUECFc_~hOhlgs6B9B24U??LG~@(?~;bossZ z>ax-80PuY(0$2Akm1D}ye?!L|O2ly-;_-Oj{#vc(ABg=5yO>yp+2=zidLPPX#5?zB zlRS?@5dNn!udwBNf@2U0~|nTgu{GI+mFc z-LO#gM^83QayJ&C{oypesfX^(F^9xoEou>w;gMnpG^h;A4W q-7q4$VMKHzFe2(6<3~(jX5>FXHow`tqhK8X0000Px#1am@3R0s$N2z&@+hyVZr5J^NqRA_a+lm|-(Fsh z_kkDQOI|*CAKv%<-d!dDK?=At?g^;Ei0Fn9(G4S_8%9JoQX_I#RZw;*hqYM(ptIxP zp7c~j$3mINYj?cRZx;C z)1<0ab}1KGk+S!5q5XgHJ^xlpvy_OnSqe(*sBuwT9$v8bYFFlGV=>;tUa!LT7OX^z z$3<#IIy=trt+n=doO>L;eSFWCn_*0(MB?sk_qfMp=VIizR`;CByD!wHGT1T`2_ZH2 z5vdg^m&-Jp&Cu^M(-{_K7690_KQOo&gpO-88noMO$!U&8*+XMoUjFoWzxL$!h1Un* z&FmEX`K;y~VRyeu=T4yLpT@jZ;9zebf#BilqsTMTDix{B-;2!oUy;ODWWzZM`mN_r zsd#;A{cG%xpKp|_OvLwmeq0Seh+8YM!%!yTp7i+M{e}=C@wY=5bNStvUu1Uu1@?7# zg_9vQ_mR|yC@a6zt2};I2H;coTuJ0mUcZF{C%9BveiIQGLgH_8L915<+gpN_(v7oH zb4HAaZWs~WFe18PM0CT5=tgQp)IG+JnbfSvFZ1>Bb&c+iMgRZ+07*qoM6N<$f&-=? A+yDRo literal 0 HcmV?d00001 diff --git a/packages/flame/test/camera/camera_component_test.dart b/packages/flame/test/camera/camera_component_test.dart index ac14b48dbcf..9d63508358f 100644 --- a/packages/flame/test/camera/camera_component_test.dart +++ b/packages/flame/test/camera/camera_component_test.dart @@ -345,6 +345,89 @@ void main() { ); }); + testGolden( + 'Correct scale of rendering', + (game) async { + final world = World(); + final resolution = Vector2(40, 60); + final camera = CameraComponent.withFixedResolution( + world: world, + width: resolution.x, + height: resolution.y, + ); + game.addAll([world, camera]); + camera.viewfinder.position = Vector2.all(4); + camera.backdrop.add( + CrossHair( + size: Vector2.all(28), + position: resolution / 2 + Vector2.all(4), + color: Colors.teal, + ), + ); + camera.viewfinder.add( + CrossHair( + size: Vector2.all(20), + position: resolution / 2 + Vector2(-6, 0), + color: Colors.white, + ), + ); + world.add( + CrossHair(size: Vector2.all(14), color: Colors.green), + ); + camera.viewport.add( + CrossHair( + size: Vector2.all(8), + position: resolution / 2 + Vector2(4, -4), + color: Colors.red, + ), + ); + }, + goldenFile: '../_goldens/camera_component_prescale_test.png', + size: Vector2(50, 50), + ); + + testGolden( + 'Correct scale of rendering after zoom', + (game) async { + final world = World(); + final resolution = Vector2(40, 60); + final camera = CameraComponent.withFixedResolution( + world: world, + width: resolution.x, + height: resolution.y, + ); + game.addAll([world, camera]); + camera.viewfinder.position = Vector2.all(4); + camera.viewfinder.zoom = 1.5; + camera.backdrop.add( + CrossHair( + size: Vector2.all(28), + position: resolution / 2 + Vector2.all(4), + color: Colors.teal, + ), + ); + camera.viewfinder.add( + CrossHair( + size: Vector2.all(20), + position: resolution / 2 + Vector2(-6, 0), + color: Colors.white, + ), + ); + world.add( + CrossHair(size: Vector2.all(14), color: Colors.green), + ); + camera.viewport.add( + CrossHair( + size: Vector2.all(8), + position: resolution / 2 + Vector2(4, -4), + color: Colors.red, + ), + ); + }, + goldenFile: '../_goldens/camera_component_prescale_zoom_test.png', + size: Vector2(50, 50), + ); + group('CameraComponent.canSee', () { testWithFlameGame('null world', (game) async { final player = PositionComponent();