foxygit / fake-08-xbox360 Log in
commit b9fc559caea15192098699523d46deb1a7ed938d
Author:     Jon Bell <jondbell@protonmail.com>
AuthorDate: Thu Apr 23 12:34:38 2020 -0600
Commit:     Jon Bell <jondbell@protonmail.com>
CommitDate: Thu Apr 23 12:34:38 2020 -0600

    Honor spr default values
---
 source/graphics.cpp   | 10 +++++++++-
 source/graphics.h     |  9 ++++++++-
 source/picoluaapi.cpp | 38 +++++++++++++++++++++++++++++---------
 3 files changed, 46 insertions(+), 11 deletions(-)

diff --git a/source/graphics.cpp b/source/graphics.cpp
index 83683a8..bd2f562 100644
--- a/source/graphics.cpp
+++ b/source/graphics.cpp
@@ -427,7 +427,15 @@ short Graphics::print(std::string str, short x, short y, uint16_t c) {
 	return x;
 }

-void Graphics::spr(short n, short x, short y, short w, short h, bool flip_x, bool flip_y) {
+void Graphics::spr(
+	short n,
+	short x,
+	short y,
+	double w,
+	double h,
+	bool flip_x,
+	bool flip_y)
+{
 	short spr_x = (n % 16) * 8;
 	short spr_y = (n / 16) * 8;
 	copySpriteToScreen(spriteSheetData, x, y, spr_x, spr_y, w * 8, h * 8, flip_x, flip_y);
diff --git a/source/graphics.h b/source/graphics.h
index e9fb2e4..edb3167 100644
--- a/source/graphics.h
+++ b/source/graphics.h
@@ -121,7 +121,14 @@ class Graphics {
 	short print(std::string str, short x, short y);
 	short print(std::string str, short x, short y, uint16_t c);

-	void spr(short n, short x, short y, short w, short h, bool flip_x, bool flip_y);
+	void spr(
+		short n,
+		short x,
+		short y,
+		double w = 1.0,
+		double h = 1.0,
+		bool flip_x = false,
+		bool flip_y = false);

 	void sspr(
         short sx,
diff --git a/source/picoluaapi.cpp b/source/picoluaapi.cpp
index 9761087..013e9e3 100644
--- a/source/picoluaapi.cpp
+++ b/source/picoluaapi.cpp
@@ -195,6 +195,7 @@ int rectfill(lua_State *L){

     return 0;
 }
+
 int print(lua_State *L){
     if (lua_gettop(L) == 0){
         return 0;
@@ -237,16 +238,35 @@ int print(lua_State *L){

     return 0;
 }
+
 int spr(lua_State *L) {
-    double n = lua_tonumber(L,1);
-    double x = lua_tonumber(L,2);
-    double y = lua_tonumber(L,3);
-    double w = lua_tonumber(L,4);
-    double h = lua_tonumber(L,5);
-    bool flip_x = lua_toboolean(L,6);
-    bool flip_y = lua_toboolean(L,7);
-
-    _graphicsForLuaApi->spr((short)n, (short)x, (short)y, (short)w, (short)h, flip_x, flip_y);
+    if (lua_gettop(L) < 3) {
+        return 0;
+    }
+
+    short n = lua_tonumber(L,1);
+    short x = lua_tonumber(L,2);
+    short y = lua_tonumber(L,3);
+    double w = 1.0;
+    double h = 1.0;
+    bool flip_x = false;
+    bool flip_y = false;
+
+
+    if (lua_gettop(L) > 3){
+        w = lua_tonumber(L,4);
+    }
+    if (lua_gettop(L) > 4) {
+        h = lua_tonumber(L,5);
+    }
+    if (lua_gettop(L) > 5) {
+        flip_x = lua_toboolean(L,6);
+    }
+    if (lua_gettop(L) > 6) {
+        flip_y = lua_toboolean(L,7);
+    }
+
+    _graphicsForLuaApi->spr((short)n, (short)x, (short)y, w, h, flip_x, flip_y);

     return 0;
 }