--1 + 1 + x3 + x2 Images 480x272 => 7 Big Images Total :D (yay, Ram optimization coming)

CanvasIMG = {
	a480x272 = Image.load("Game Resources/Canvases/480x272.png"), -- just for initialization
	a155x272 = Image.load("Game Resources/Canvases/155x272.png"), -- just for initialization
}

Canvas = {
	Update = {
		Panel = true,
		Numbers = {
			Pop = true,
			Score = true
		},
		Debug = true
	},
	
	Result = CanvasIMG.a480x272,--1

	Panel = {
		Result = CanvasIMG.a480x272,--2
		
		Rebuild = function()
			Canvas.Panel.Result = CanvasIMG.a480x272
			Canvas.Panel.Result:blit(0, 0, spr.assets.GamePanel, true)
			Canvas.Panel.Result:blit(338, 200, spr.assets.MiniMap) -- 330, 197  or  338, 200
			Canvas.Panel.Result:pixel(338 + 20, 200 + 20, Blue)
			return true;
		end
	},
	Numbers = {
		Result = CanvasIMG.a480x272,--2
		
		Pop = {
			Result = CanvasIMG.a480x272,--3
		
			Rebuild = function()
				Canvas.Numbers.Pop.Result = CanvasIMG.a480x272
				
				Canvas.Numbers.Pop.Result:fontPrint(Arial,288,13,Global.Player.Pop.."/"..Global.Player.MaxPop,White)
				return true;
			end
		},
		Score = {
			Result = CanvasIMG.a480x272,--3
		
			Rebuild = function()
				Canvas.Numbers.Score.Result = CanvasIMG.a480x272
				
				Canvas.Numbers.Score.Result:fontPrint(Arial,27,13,Global.Player.Wood,White)
				Canvas.Numbers.Score.Result:fontPrint(Arial,94,13,Global.Player.Food,White)
				Canvas.Numbers.Score.Result:fontPrint(Arial,160,13,Global.Player.Gold,White)
				Canvas.Numbers.Score.Result:fontPrint(Arial,220,13,Global.Player.Stone,White)
				
				Canvas.Numbers.Score.Result:fontPrint(Arial,380-1,13-1,Global.Player.Age,Black)
				Canvas.Numbers.Score.Result:fontPrint(Arial,380,13,Global.Player.Age,White)
				
				Canvas.Numbers.Score.Result:fontPrint(Arial,360-1,190-1,Global.Player.Nick.." ("..Global.Player.Score.."/"..Global.Player.TeamScore..")",Black)
				Canvas.Numbers.Score.Result:fontPrint(Arial,360,190,    Global.Player.Nick.." ("..Global.Player.Score.."/"..Global.Player.TeamScore..")",Global.Player.NickCol)
				return true;
			end
		},
		
		Rebuild = function()
			local NeedUpdate = false
			if Canvas.Update.Numbers.Pop then
				Canvas.Numbers.Pop.Rebuild()
				NeedUpdate = true
			end
			if Canvas.Update.Numbers.Score then
				Canvas.Numbers.Score.Rebuild()
				NeedUpdate = true
			end
			
			if not NeedUpdate then return false; end
			Canvas.Numbers.Result = CanvasIMG.a480x272
			Canvas.Numbers.Result:blit(0, 0, Canvas.Numbers.Pop.Result, true)
			Canvas.Numbers.Result:blit(0, 0, Canvas.Numbers.Score.Result, true)
			
			Canvas.Update.Numbers = {Pop = false, Score = false}
			return true;
		end
	},
	
	Debug = {
		Result = CanvasIMG.a480x272,--2
		
		Rebuild = function()
			Canvas.Debug.Result = CanvasIMG.a480x272
			
			--[[
			Canvas.Debug.Result:fontPrint(Arial,10-1,35-1,"Tick: "..tick,Black)
			Canvas.Debug.Result:fontPrint(Arial,10,35,"Tick: "..tick,White)
			
			Canvas.Debug.Result:fontPrint(Arial,10-1,35+ 15*1 -1,"KTick: "..KTick,Black)
			Canvas.Debug.Result:fontPrint(Arial,10,35+ 15*1,"KTick: "..KTick,White)
			
			Canvas.Debug.Result:fontPrint(Arial,10-1,35+ 15*2 -1,"MTick: "..MTick,Black)
			Canvas.Debug.Result:fontPrint(Arial,10,35+ 15*2,"MTick: "..MTick,White)
			
			Canvas.Debug.Result:fontPrint(Arial,10-1,35+ 15*3 -1,"STick: "..STick,Black)
			Canvas.Debug.Result:fontPrint(Arial,10,35+ 15*3,"STick: "..STick,White)
			
			Canvas.Debug.Result:fontPrint(Arial,10-1,35+ 15*4 -1,"",Black)
			Canvas.Debug.Result:fontPrint(Arial,10,35+ 15*4,"",White)
			--]]
			
			
			return true;
		end
	},
	
	Rebuild = function()
		local NeedUpdate = false
		if Canvas.Update.Panel then
			Canvas.Panel.Rebuild()
			NeedUpdate = true
		end
		if Canvas.Update.Numbers.Pop or Canvas.Update.Numbers.Score then
			Canvas.Numbers.Rebuild()
			NeedUpdate = true
		end
		if Canvas.Update.Debug then
			Canvas.Debug.Rebuild()
			NeedUpdate = true
		end
		
		if not NeedUpdate then return false; end
		Canvas.Result = CanvasIMG.a480x272
		Canvas.Result:blit(0, 0, Canvas.Panel.Result)
		Canvas.Result:blit(0, 0, Canvas.Numbers.Result)
		--Canvas.Result:blit(0, 0, Canvas.Debug.Result)
		
		Canvas.Update = {Panel = false, Numbers = {Pop = false, Score = false}, Debug = false}
		
		return true;
	end
}

Canvas.Rebuild()