foxygit / fake-08-xbox360 Log in
commit 74321b36159c1ed371fc6bbf5897696c88cc1ec3
Author:     Jon Bell <jondbell@protonmail.com>
AuthorDate: Wed Apr 15 16:12:16 2020 -0600
Commit:     Jon Bell <jondbell@protonmail.com>
CommitDate: Wed Apr 15 16:12:16 2020 -0600

    Change cart to be a class
---
 source/cart.cpp            | 31 ++++++++++++++++++++-----------
 source/cart.h              | 19 ++++++++-----------
 source/picointernals.cpp   |  4 ++--
 source/picointernals.h     |  2 +-
 source/tests/cart_test.cpp |  7 +++++++
 source/tests/cart_test.h   |  4 ++++
 6 files changed, 42 insertions(+), 25 deletions(-)

diff --git a/source/cart.cpp b/source/cart.cpp
index 27261f3..8666300 100644
--- a/source/cart.cpp
+++ b/source/cart.cpp
@@ -11,13 +11,14 @@
 #include "tests/cart_test.h"
 #endif

-void LoadCart(std::string filename){
+Cart::Cart(std::string filename){
+    Filename = filename;
     auto cartStr = get_file_contents(filename.c_str());

+    fullCartText = cartStr;
+
     std::istringstream s(cartStr);
     std::string line;
-    std::string lua = "";
-    std::string spritesheet = "";
     std::string currSec = "";

     while (std::getline(s, line)) {
@@ -27,10 +28,22 @@ void LoadCart(std::string filename){
             currSec = line;
         }
         else if (currSec == "__lua__"){
-            lua += line + "\n";
+            LuaString += line + "\n";
         }
         else if (currSec == "__gfx__"){
-            spritesheet += line + "\n";
+            SpriteSheetString += line + "\n";
+        }
+        else if (currSec == "__gff__"){
+            SpriteFlagsString += line + "\n";
+        }
+        else if (currSec == "__map__"){
+            MapString += line + "\n";
+        }
+        else if (currSec == "__sfx__"){
+             //no sound support yet
+        }
+        else if (currSec == "__sfx__"){
+             //no sound support yet
         }
 	}

@@ -39,11 +52,7 @@ void LoadCart(std::string filename){
     //run tests to make sure cart is parsed correctly
     verifyFullCartText(cartStr);

-    verifyLuaText(lua);
-
-    verifySpriteSheetText(spritesheet);
+    verifyCart(this);

     #endif
-
-    //return cart;
-}
\ No newline at end of file
+}
diff --git a/source/cart.h b/source/cart.h
index b5db05b..54cc732 100644
--- a/source/cart.h
+++ b/source/cart.h
@@ -5,23 +5,20 @@
 #include "graphics.h"


-struct PicoCart {
-    std::string Filename;
+class Cart {
+    std::string fullCartText;

-    std::string FullCartString;

-    std::string SpriteSheetString;
+    public:
+    Cart (std::string filename);

+    std::string Filename;
+    std::string LuaString;
+    std::string SpriteSheetString;
     std::string SpriteFlagsString;
-
     std::string MapString;
-
-    std::string LuaScript;
-

     //SpriteSheet CartSpriteSheet;
     //uint8_t map_data[128 * 128];
-};

-
-void LoadCart(std::string filename);
\ No newline at end of file
+};
diff --git a/source/picointernals.cpp b/source/picointernals.cpp
index cef1017..51e9824 100644
--- a/source/picointernals.cpp
+++ b/source/picointernals.cpp
@@ -14,6 +14,6 @@ void initPicoInternals() {

 void loadcart(std::string filename){
     //auto cart = LoadCart(filename);
-    LoadCart(filename);
+    Cart cart (filename);

-}
\ No newline at end of file
+}
diff --git a/source/picointernals.h b/source/picointernals.h
index 569ac2b..023cc80 100644
--- a/source/picointernals.h
+++ b/source/picointernals.h
@@ -2,4 +2,4 @@

 void initPicoInternals();

-void loadcart(std::string filename);
\ No newline at end of file
+void loadcart(std::string filename);
diff --git a/source/tests/cart_test.cpp b/source/tests/cart_test.cpp
index 6824ec1..aef7d71 100644
--- a/source/tests/cart_test.cpp
+++ b/source/tests/cart_test.cpp
@@ -105,6 +105,13 @@ bool verifyFullCartText(std::string cartText){
     return assertStringsEqual(full_cart_text, cartText, "Full Cart Text");
 }

+bool verifyCart(Cart* cart){
+    bool valid = true;
+    valid &= verifyLuaText(cart->LuaString);
+    valid &= verifySpriteSheetText(cart->SpriteSheetString);
+    return valid;
+}
+
 const char* expected_lua_text = R"(local r1x0 = 10
 local r1y0 = 10
 local r1x1 = 50
diff --git a/source/tests/cart_test.h b/source/tests/cart_test.h
index 5f1fa6a..912a846 100644
--- a/source/tests/cart_test.h
+++ b/source/tests/cart_test.h
@@ -6,7 +6,11 @@

 #include <string>

+#include "../cart.h"
+
 bool verifyFullCartText(std::string cartText);
+
+bool verifyCart(Cart* cart);
 bool verifyLuaText(std::string luaText);
 bool verifySpriteSheetText(std::string spritesheet);