From 7fdae891d908daa6d58ccecd7cc27fc93866ba79 Mon Sep 17 00:00:00 2001 From: Firew0lf Date: Sun, 27 Mar 2016 20:43:03 +0200 Subject: [PATCH] Fixed maps, scrollmaps, images rotation, paths correction and screen background --- uCompat/Image.lua | 2 +- uCompat/Map.lua | 32 +++++++++++++++++++++++++++++--- uCompat/ScrollMap.lua | 4 +++- uCompat/System.lua | 10 ++++++++-- uCompat/screen.lua | 1 + 5 files changed, 42 insertions(+), 7 deletions(-) diff --git a/uCompat/Image.lua b/uCompat/Image.lua index 26a9a9c..1d5e730 100644 --- a/uCompat/Image.lua +++ b/uCompat/Image.lua @@ -9,7 +9,7 @@ local texture = require("ctr.gfx.texture") -- Constants RAM = texture.PLACE_RAM -VRAM = texture.PLACE_VRAM +VRAM = texture.PLACE_VRAM -- has to be "PLACE_RAM" on hardware -- Module diff --git a/uCompat/Map.lua b/uCompat/Map.lua index 21eeb7f..9bd7206 100644 --- a/uCompat/Map.lua +++ b/uCompat/Map.lua @@ -6,14 +6,40 @@ map = require("ctr.gfx.map") +-- Interface +Map = {} + +function Map.mapToTable(filename, w, h) + local f = io.open(filename, "r") + local data = f:read("a") + f:close() + + local buff = {} + local word + for word in string.gmatch(data, "(%d)|\n*") do + buff[#buff+1] = tonumber(word) + if #buff == w*h then break end + end + + local t = {} + local x,y + for y=1, h do + t[y] = {} + for x=1, w do + t[y][x] = buff[x+((y-1)*w)] + end + end + + return t +end + -- Module require("uCompat.screen") -Map = {} - function Map.new(image, mapFile, width, height, tileWidth, tileHeight) - local m = map.load(mapFile, image.texture, tileWidth, tileHeight) + local tiles = mapToTable(mapFile, width, height) + local m = map.load(tiles, image.texture, tileWidth, tileHeight) return { map = m, diff --git a/uCompat/ScrollMap.lua b/uCompat/ScrollMap.lua index 51510e7..d9e606e 100644 --- a/uCompat/ScrollMap.lua +++ b/uCompat/ScrollMap.lua @@ -9,11 +9,13 @@ map = require("ctr.gfx.map") -- Module require("uCompat.screen") +require("uCompat.Map") ScrollMap = {} function ScrollMap.new(image, mapFile, width, height, tileWidth, tileHeight) - local m = map.load(mapFile, image.texture, tileWidth, tileHeight) + local tiles = Map.mapToTable(mapFile, width, height) + local m = map.load(tiles, image.texture, tileWidth, tileHeight) return { map = m, scrollX = 0, diff --git a/uCompat/System.lua b/uCompat/System.lua index 07af3da..d70c638 100644 --- a/uCompat/System.lua +++ b/uCompat/System.lua @@ -12,10 +12,14 @@ local gfx = require("ctr.gfx") -- µ -> ctrµ local function fixPath(DSpath) local path - if DSpath:sub(1, 1) == "/" or DSpath:sub(1, 5) == "fat:/" then -- fix root + if DSpath:sub(1, 5) == "fat:/" then -- fix root path = ("sdmc:/"..DSpath:sub(6, -1)) + elseif DSpath:sub(1, 1) == "/" then + path = ("sdmc:"..DSpath) elseif DSpath:sub(1, 5) == "efs:/" then path = ("romfs:/"..DSpath:sub(6,-1)) + else + path = DSpath end return path @@ -24,8 +28,10 @@ end -- ctrµ -> µ local function unfixPath(path) local DSpath - if path:sub(1, 6) == "sdmc:/" or path.sub(1, 1) == "/" then + if path:sub(1, 6) == "sdmc:/" then DSpath = ("fat:/"..path:sub(7, -1)) + elseif path.sub(1, 1) == "/" then + DSpath = ("fat:"..path) elseif path:sub(1, 7) == "romfs:/" then DSpath = ("efs:/"..path:sub(8, -1)) end diff --git a/uCompat/screen.lua b/uCompat/screen.lua index acae02d..cef0b82 100644 --- a/uCompat/screen.lua +++ b/uCompat/screen.lua @@ -200,6 +200,7 @@ end function screen.endDrawing() gfx.start(drawScreen) + gfx.rectangle(offsetX, offsetY, SCREEN_WIDTH, SCREEN_HEIGHT, 0, color.RGBA8(0,0,0,255)) for i=1, #videoStack[drawScreen] do local e = videoStack[drawScreen][i] if e[1] == "img" then