foxygit / fake-08-xbox360 Log in
commit 14084657a54835ba20f8bf486af713044008a379
Author:     jtothebell <j.to.the.bell@gmail.com>
AuthorDate: Sun Sep 6 17:34:12 2020 -0600
Commit:     jtothebell <j.to.the.bell@gmail.com>
CommitDate: Tue Sep 15 17:09:08 2020 -0600

    Add tests and fix bug for pget respecting camera
---
 source/graphics.cpp    |  2 ++
 test/graphicstests.cpp | 24 ++++++++++++++++++++++++
 2 files changed, 26 insertions(+)

diff --git a/source/graphics.cpp b/source/graphics.cpp
index 4aae104..1525951 100644
--- a/source/graphics.cpp
+++ b/source/graphics.cpp
@@ -381,6 +381,8 @@ void Graphics::pset(int x, int y, uint8_t col){
 }

 uint8_t Graphics::pget(int x, int y){
+	applyCameraToPoint(&x, &y);
+
 	if (isOnScreen(x, y)){
 		return _pico8_fb[(x * 128) + y];
 	}
diff --git a/test/graphicstests.cpp b/test/graphicstests.cpp
index 28f3ee9..4f2f5f1 100644
--- a/test/graphicstests.cpp
+++ b/test/graphicstests.cpp
@@ -982,6 +982,30 @@ TEST_CASE("graphics class behaves as expected") {
        CHECK_EQ(picoRam._gfxState_camera_x, 0);
        CHECK_EQ(picoRam._gfxState_camera_y, 0);
    }
+   //TODO: check drawing calls to make sure these values honored
+   SUBCASE("camera values applies to pget")
+   {
+       uint8_t col = 13;
+       picoRam._gfxState_camera_x = -44;
+       picoRam._gfxState_camera_y = -3;
+       graphics->pset(14, 32, 13);
+
+       auto result = graphics->pget(14, 32);
+
+       CHECK_EQ(result, col);
+   }
+   SUBCASE("camera values applies to pset")
+   {
+       uint8_t col = 13;
+       picoRam._gfxState_camera_x = -44;
+       picoRam._gfxState_camera_y = -3;
+       graphics->pset(14, 32, 13);
+       graphics->camera();
+
+       auto result = graphics->pget(58, 35);
+
+       CHECK_EQ(result, col);
+   }