--[[
  Copyright Tom Lukeywood 2018
    This file is part of Forest2D

    Forest2D is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Forest2D is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Forest2D.  If not, see <http://www.gnu.org/licenses/>.
]]--

--THIS FILE IS CURRENTLY JUST TESTING!
-- Need to update all the Putchar code!!

Text = {}

local function TrySDL(func, ...)
local t = { func(...) }
if not t[1] then
error(t[#t])
end
return table.unpack(t)
end

function Text.PrintText(Renderer, String, x, y, w, h)
  local Rect = {}

  StringLength = string.len(String)

  local i

  for i = 1, StringLength do
    Text.PutChar(Renderer, string.sub(String, i, i), x, y, w, h)
    x = x + w
  end

end

function Text.PutChar(Renderer, Char, x, y, w, h)   --Ill Add things like lower case letters later...
  local Rect = {}

  Rect.x = x
  Rect.y = y
  Rect.w = w
  Rect.h = h

  Char = string.upper(Char)

  if string.len(Char) > 1 then
  print("Text.PutChar Error: More than one character has been passed.")
  return
  end

  if Char == "A" then
    Renderer:copy(Renderer:createTextureFromSurface(Image.load("../../Assets/Font/A")), nil, Rect)
  elseif Char == "B" then
    Renderer:copy(Renderer:createTextureFromSurface(Image.load("../../Assets/Font/B")), nil, Rect)
  elseif Char == "C" then
    Renderer:copy(Renderer:createTextureFromSurface(Image.load("../../Assets/Font/C")), nil, Rect)
  elseif Char == "D" then
    Renderer:copy(Renderer:createTextureFromSurface(Image.load("../../Assets/Font/D")), nil, Rect)
  elseif Char == "E" then
    Renderer:copy(Renderer:createTextureFromSurface(Image.load("../../Assets/Font/E")), nil, Rect)
  elseif Char == "F" then
    Renderer:copy(Renderer:createTextureFromSurface(Image.load("../../Assets/Font/F")), nil, Rect)
  elseif Char == "G" then
    Renderer:copy(Renderer:createTextureFromSurface(Image.load("../../Assets/Font/G")), nil, Rect)
  elseif Char == "H" then
    Renderer:copy(Renderer:createTextureFromSurface(Image.load("../../Assets/Font/H")), nil, Rect)
  elseif Char == "I" then
    Renderer:copy(Renderer:createTextureFromSurface(Image.load("../../Assets/Font/I")), nil, Rect)
  elseif Char == "J" then
    Renderer:copy(Renderer:createTextureFromSurface(Image.load("../../Assets/Font/J")), nil, Rect)
  elseif Char == "K" then
    Renderer:copy(Renderer:createTextureFromSurface(Image.load("../../Assets/Font/K")), nil, Rect)
  elseif Char == "L" then
    Renderer:copy(Renderer:createTextureFromSurface(Image.load("../../Assets/Font/L")), nil, Rect)
  elseif Char == "M" then
    Renderer:copy(Renderer:createTextureFromSurface(Image.load("../../Assets/Font/M")), nil, Rect)
  elseif Char == "N" then
    Renderer:copy(Renderer:createTextureFromSurface(Image.load("../../Assets/Font/N")), nil, Rect)
  elseif Char == "O" then
    Renderer:copy(Renderer:createTextureFromSurface(Image.load("../../Assets/Font/O")), nil, Rect)
  elseif Char == "P" then
    Renderer:copy(Renderer:createTextureFromSurface(Image.load("../../Assets/Font/P")), nil, Rect)
  elseif Char == "Q" then
    Renderer:copy(Renderer:createTextureFromSurface(Image.load("../../Assets/Font/Q")), nil, Rect)
  elseif Char == "R" then
    Renderer:copy(Renderer:createTextureFromSurface(Image.load("../../Assets/Font/R")), nil, Rect)
  elseif Char == "S" then
    Renderer:copy(Renderer:createTextureFromSurface(Image.load("../../Assets/Font/S")), nil, Rect)
  elseif Char == "T" then
    Renderer:copy(Renderer:createTextureFromSurface(Image.load("../../Assets/Font/T")), nil, Rect)
  elseif Char == "U" then
    Renderer:copy(Renderer:createTextureFromSurface(Image.load("../../Assets/Font/U")), nil, Rect)
  elseif Char == "V" then
    Renderer:copy(Renderer:createTextureFromSurface(Image.load("../../Assets/Font/V")), nil, Rect)
  elseif Char == "W" then
    Renderer:copy(Renderer:createTextureFromSurface(Image.load("../../Assets/Font/W")), nil, Rect)
  elseif Char == "X" then
    Renderer:copy(Renderer:createTextureFromSurface(Image.load("../../Assets/Font/X")), nil, Rect)
  elseif Char == "Y" then
    Renderer:copy(Renderer:createTextureFromSurface(Image.load("../../Assets/Font/Y")), nil, Rect)
  elseif Char == "Z" then
    Renderer:copy(Renderer:createTextureFromSurface(Image.load("../../Assets/Font/Z")), nil, Rect)
  elseif Char == "0" then
    Renderer:copy(Renderer:createTextureFromSurface(Image.load("../../Assets/Font/0")), nil, Rect)
  elseif Char == "1" then
    Renderer:copy(Renderer:createTextureFromSurface(Image.load("../../Assets/Font/1")), nil, Rect)
  elseif Char == "2" then
    Renderer:copy(Renderer:createTextureFromSurface(Image.load("../../Assets/Font/2")), nil, Rect)
  elseif Char == "3" then
    Renderer:copy(Renderer:createTextureFromSurface(Image.load("../../Assets/Font/3")), nil, Rect)
  elseif Char == "4" then
    Renderer:copy(Renderer:createTextureFromSurface(Image.load("../../Assets/Font/4")), nil, Rect)
  elseif Char == "5" then
    Renderer:copy(Renderer:createTextureFromSurface(Image.load("../../Assets/Font/5")), nil, Rect)
  elseif Char == "6" then
    Renderer:copy(Renderer:createTextureFromSurface(Image.load("../../Assets/Font/6")), nil, Rect)
  elseif Char == "7" then
    Renderer:copy(Renderer:createTextureFromSurface(Image.load("../../Assets/Font/7")), nil, Rect)
  elseif Char == "8" then
    Renderer:copy(Renderer:createTextureFromSurface(Image.load("../../Assets/Font/8")), nil, Rect)
  elseif Char == "9" then
    Renderer:copy(Renderer:createTextureFromSurface(Image.load("../../Assets/Font/9")), nil, Rect)
  elseif Char == " " then
    Renderer:copy(Renderer:createTextureFromSurface(Image.load("../../Assets/Font/WhiteSpace")), nil, Rect)
  elseif Char == "-" then
    Renderer:copy(Renderer:createTextureFromSurface(Image.load("../../Assets/Font/Dash")), nil, Rect)
  elseif Char == ":" then
    Renderer:copy(Renderer:createTextureFromSurface(Image.load("../../Assets/Font/Colon")), nil, Rect)
  elseif Char == "/" then
    Renderer:copy(Renderer:createTextureFromSurface(Image.load("../../Assets/Font/ForwardSlash")), nil, Rect)
  elseif Char == "." then
    Renderer:copy(Renderer:createTextureFromSurface(Image.load("../../Assets/Font/Period")), nil, Rect)
  else
    return
  end

end

return Text
