mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2024-11-14 22:04:53 +00:00
Move raw data parsing to paintutils.drawImage
This commit is contained in:
parent
260bb2e4e1
commit
71d024a76c
@ -9,14 +9,6 @@ for n=1,16 do
|
|||||||
tColourLookup[ string.byte( "0123456789abcdef",n,n ) ] = 2^(n-1)
|
tColourLookup[ string.byte( "0123456789abcdef",n,n ) ] = 2^(n-1)
|
||||||
end
|
end
|
||||||
|
|
||||||
function loadImage( sPath, bLoadRawData )
|
|
||||||
if type( sPath ) ~= "string" then
|
|
||||||
error( "bad argument #1 (expected string, got " .. type( sPath ) .. ")", 2 )
|
|
||||||
end
|
|
||||||
if bLoadRawData ~= nil and type(bLoadRawData) ~= "boolean" then
|
|
||||||
error( "bad argument #2 (expected nil or boolean, got " .. type( sPath ) .. ")" )
|
|
||||||
end
|
|
||||||
|
|
||||||
local function parseLine( tImageArg, sLine )
|
local function parseLine( tImageArg, sLine )
|
||||||
local tLine = {}
|
local tLine = {}
|
||||||
for x=1,sLine:len() do
|
for x=1,sLine:len() do
|
||||||
@ -26,18 +18,10 @@ function loadImage( sPath, bLoadRawData )
|
|||||||
return tImageArg
|
return tImageArg
|
||||||
end
|
end
|
||||||
|
|
||||||
if fs.exists( sPath ) and not bLoadRawData then
|
function parseImage( sRawData )
|
||||||
local tImage = {}
|
if type( sRawData ) ~= "string" then
|
||||||
local file = io.open( sPath, "r" )
|
error ( "bad argument #1 (expected string, got " .. type( sRawData ) .. ")" )
|
||||||
local sLine = file:read()
|
|
||||||
while sLine do
|
|
||||||
tImage = parseLine( tImage, sLine )
|
|
||||||
sLine = file:read()
|
|
||||||
end
|
end
|
||||||
file:close()
|
|
||||||
return tImage
|
|
||||||
else
|
|
||||||
if bLoadRawData then
|
|
||||||
local function split( str, delim ) -- modified split function from https://codea.io/talk/discussion/2118/split-a-string-by-return-newline
|
local function split( str, delim ) -- modified split function from https://codea.io/talk/discussion/2118/split-a-string-by-return-newline
|
||||||
if string.find( str, delim ) == nil then return { str } end
|
if string.find( str, delim ) == nil then return { str } end
|
||||||
local result, pat, lastpos = {}, "(.-)" .. delim .. "()", nil
|
local result, pat, lastpos = {}, "(.-)" .. delim .. "()", nil
|
||||||
@ -51,6 +35,23 @@ function loadImage( sPath, bLoadRawData )
|
|||||||
end
|
end
|
||||||
return tImage
|
return tImage
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function loadImage( sPath )
|
||||||
|
if type( sPath ) ~= "string" then
|
||||||
|
error( "bad argument #1 (expected string, got " .. type( sPath ) .. ")", 2 )
|
||||||
|
end
|
||||||
|
|
||||||
|
if fs.exists( sPath ) and not bLoadRawData then
|
||||||
|
local tImage = {}
|
||||||
|
local file = io.open( sPath, "r" )
|
||||||
|
local sLine = file:read()
|
||||||
|
local sContent = ""
|
||||||
|
while sLine do
|
||||||
|
sContent = sContent .. sLine .. "\n"
|
||||||
|
sLine = file:read()
|
||||||
|
end
|
||||||
|
file:close()
|
||||||
|
return parseImage( sContent ) -- delegate parsing of images to parseImage function as suggested by @SquidDev in discussion of PR #378
|
||||||
end
|
end
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user