<commit_before>
local bitdown=require("wetgenes.gamecake.fun.bitdown")
local chatdown=require("wetgenes.gamecake.fun.chatdown")
local wstr=require("wetgenes.string")
function ls(s) print(wstr.dump(s))end

hardware,main=system.configurator({
	mode="fun64", -- select the standard 320x240 screen using the swanky32 palette.
	update=function() -- called at a steady 60fps
		if setup then setup() setup=nil end -- call an optional setup function *once*
		entities.systems.call("update")
		entities.call("update")
	end,
	draw=function() -- called at actual display frame rate
		entities.systems.call("draw")
		entities.call("draw")
	end,
	hx=440,hy=240, -- wide screen
})

hardware.screen.zxy={0,-1}

hardware.insert{
	component="overmap",
	name="map",					-- same name so will replace the foreground tilemap
	tiles="tiles",
	tilemap_size={48,32},
	tile_size={16,32,16},
	over_size={0,16},
	sort={-1,-1},
	mode="xz",
	layer=2,
}

entities=require("wetgenes.gamecake.fun.entities").create({
	sortby={
	},
})

-- setup all entities
setup=function() entities.systems.call("setup") end




local chat_text=[[

#example A chance meeting

	A rare bread of NPC who will fulfil all your conversational desires for 
	a very good price.

	=sir Madam
	=portrait portrait_1

	>convo

		Is this the right room for a conversation?
		
	>welcome
	
		...ERROR...EOF...PLEASE...RESTART...

<welcome

	Good morning,{sir}!
	
	>morning

		Good morning to you too.

	>afternoon

		I think you will find it is now afternoon.

	>sir

		How dare you call me {sir}!

<sir

	My apologies, I am afraid that I am but an NPC with very little 
	brain, how might I address you?
	
	>welcome.1?sir!=madam

		You may address me as Madam.

		=sir madam
		=portrait portrait_2


	>welcome.2?sir!=God

		You may address me as God.

		=sir God
		=portrait portrait_3

	>welcome.3?sir!=sir

		You may address me as Sir.

		=sir sir
		=portrait portrait_4

<afternoon
	
	Then good afternoon, {sir}.
	
	>convo

<morning
	
	And how may I help {sir} today?
	
	>convo


<convo

	Indeed it is, would you like the full conversation or just the 
	quick natter?

	>convo_full
	
		How long is the full conversation?

	>convo_quick

		A quick natter sounds just perfect.

<convo_full

	The full conversation is very full and long so much so that you 
	will have to page through many pages before you get to make a 
	decision.
	
	>
		Like this?
	<
	
	Yes, just like this. In fact I think you can see that we are already 
	doing it.
			
	
	>exit
		
		EXIT

<convo_quick

	...
	
	>exit

		EXIT
]]





local combine_legends=function(...)
	local legend={}
	for _,t in ipairs{...} do -- merge all
		for n,v in pairs(t) do -- shallow copy, right side values overwrite left
			legend[n]=v
		end
	end
	return legend
end

local default_legend={
	[   0]={ items={"floor_tile"},			},
	[". "]={ items={"floor_tile"}			},
	["x "]={ items={"floor_tile"}			},
	["S "]={ items={"floor_spawn"}			},
	["T "]={ items={"talker"}				},
	["T2"]={ items={"talker2"}				},
	["T3"]={ items={"talker3"}				},
	["T4"]={ items={"talker4"}				},
	["T5"]={ items={"talker5"}				},
	["T6"]={ items={"talker6"}				},
	["T7"]={ items={"talker7"}				},
	["T8"]={ items={"talker8"}				},
	["T9"]={ items={"talker9"}				},
	["T0"]={ items={"talker0"}				},
	["# "]={ items={"wall_full"}			},
	["= "]={ items={"wall_half"}			},
}
	
levels={
 {
 name="page_zero",
 legend=combine_legends(default_legend,{
 }),
 map=[[
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # 
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # 
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # 
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # 
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # 
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # 
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # 
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # 
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # 
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # 
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # 
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # 
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # 
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # 
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # 
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # 
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # 
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # 
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # 
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # 
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # 
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # 
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # 
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # 
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # 
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # 
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # 
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # 
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # 
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # 
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # 
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # 
]],
 },
 {
 name="page_town",
 pages={0x80008000},
 legend=combine_legends(default_legend,{
 }),
 map=[[
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . T7. . . . . . . . . . . . . . . . 
. . . . . = = = = = . . . . . . . . . . . . . . . . . . . . . . 
. . . . . # . . . # . . . . . . . . . . . . . . . . . . . . . . 
. . . . . # . S . # . . . . . . . . . . . . . . . . . . . . . . 
. . . . . # . . . # . . . . . . . . . . . . . . . . . . . . . . 
. . . . . # = . = # T8. . . . . . . . . . . . . T . . . . . . . 
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 
. . . . . . . . . . . . T3. . . . . . . . . . . . . . . . . . . 
. . . . . . . T5. . . . . . . . . . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . . . . # # # # T8. . . . . . . . 
. . . . . . . . . . . . . . T4. . . . # . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . . . . # . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . . . . # . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . . . . . . . # . . . . . . . . . 
. . . . . = = = = = . . . . . . . . . . . . # . . . . . . . . . 
. . . . . # . T2. # . . . . . . . . . # . . # . . . T6. . . . . 
. . . . . # . . . # . . . . . . . . . # . . . . . . . . . . . . 
. . . . . # = . = S = . = = . . . . . # . . # . . . . . . . . . 
. . . . . . . . . # . . . . . . . . . # . . # . . . . . . . . . 
. . . . . . . . . # . S . . . . . . . # . . # . . . . . . . . . 
. . . . . . . . . # . . . . . . . # . # . . . . . . S . . . . . 
. . . . . . . . . T7. . . . . . # # . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . . # . # # # # . . . . . . . . . 
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 
]],
 },
}




entities.systems.insert{ caste="map",

	loads=function()

		hardware.graphics.loads{

{nil,"test_empty",[[
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
]]},

{nil,"test_none",[[
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 
1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 
0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 
1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 
0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 
1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 
0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 
1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 
0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 
1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 
0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 
1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 
0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 
1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 
0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 
1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 
]]},

{nil,"test_tile",[[
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 
0 1 1 1 1 1 1 0 1 0 0 0 0 0 0 1 
0 1 0 0 0 0 1 0 1 0 1 1 1 1 0 1 
0 1 0 0 0 0 1 0 1 0 1 1 1 1 0 1 
0 1 0 0 0 0 1 0 1 0 1 1 1 1 0 1 
0 1 0 0 0 0 1 0 1 0 1 1 1 1 0 1 
0 1 1 1 1 1 1 0 1 0 0 0 0 0 0 1 
0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 
1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 
1 0 0 0 0 0 0 1 0 1 1 1 1 1 1 0 
1 0 1 1 1 1 0 1 0 1 0 0 0 0 1 0 
1 0 1 1 1 1 0 1 0 1 0 0 0 0 1 0 
1 0 1 1 1 1 0 1 0 1 0 0 0 0 1 0 
1 0 1 1 1 1 0 1 0 1 0 0 0 0 1 0 
1 0 0 0 0 0 0 1 0 1 1 1 1 1 1 0 
1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 
]]},

{nil,"test_wall1",[[
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
4 3 2 F F F F F F F F F F 2 3 4 
2 f F F F F F F F F F F F F f 2 
F f F F j j j F F j j j F F f F 
F f F F j f f F F j f f F F f F 
F f F F j f f F F j f f F F f F 
F f F F j f f F F j f f F F f F 
2 f F F F F F F F F F F F F f 2 
4 3 2 F F F F F F F F F F 2 3 4 
3 j f f j j j j j j f f j j j 3 
2 j F f j j f f j j F f j j j 2 
j g F f j j F F j j F f j j f j 
j j f f g j F F j j f f j j F f 
j g j g j j F F j j j j j j F F 
j j f f g j F f j j f f j j F f 
j g F F j j F f j g F F j j F f 
j j F F j j F f g j F F j j f f 
j j F F j j j g j g F F j j j j 
j j F f j j f f g j F f j j f f 
j j F f j j F F j g F f j j F F 
j j f f j j F F j j f f j j F F 
j j j j j j F F j j j g j j F F 
j j f f j j F f j j f f g j F f 
2 j F f j j F f j j F f j g f 2 
3 2 f f j j f f j j f f j j 2 3 
]]},

{nil,"test_wall2",[[
4 3 2 F F F F F F F F F F 2 3 4 
3 f f f f f f f f f f f f f f 3 
2 f F F F F F F F F F F F F f 2 
F f F F j j j F F j j j F F f F 
F f F F j f f F F j f f F F f F 
F f F F j f f F F j f f F F f F 
F f F F j f f F F j f f F F f F 
F f F F j f f F F j f f F F f F 
F f F F j f f F F j f f F F f F 
F f F F j f f F F j f f F F f F 
F f F F j f f F F j f f F F f F 
F f F F j f f F F j f f F F f F 
F f F F j f f F F j f f F F f F 
2 f F F F F F F F F F F F F f 2 
3 f f f f f f f f f f f f f f 3 
4 3 2 F F F F F F F F F F 2 3 4 
3 j f f j j j j j j f f j j j 3 
2 j F f j j f f j j F f j j j 2 
j g F f j j F F j j F f j j f j 
j j f f g j F F j j f f j j F f 
j g j g j j F F j j j j j j F F 
j j f f g j F f j j f f j j F f 
j g F F j j F f j g F F j j F f 
j j F F j j F f g j F F j j f f 
j j F F j j j g j g F F j j j j 
j j F f j j f f g j F f j j f f 
j j F f j j F F j g F f j j F F 
j j f f j j F F j j f f j j F F 
j j j j j j F F j j j g j j F F 
j j f f j j F f j j f f g j F f 
2 j F f j j F f j j F f j g f 2 
3 2 f f j j f f j j f f j j 2 3 
]]},

{nil,"test_spawn",[[
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
. . r . . . . . . . . . . r . . 
. . R . . . . . . . . . . R . . 
0 0 4 0 1 1 1 1 1 1 1 1 0 4 0 0 
0 0 4 1 1 1 0 0 0 0 1 1 1 4 0 0 
0 0 1 0 1 1 0 0 0 0 1 1 0 1 0 0 
0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 
1 1 1 1 0 0 1 1 1 1 0 0 1 1 1 1 
1 0 1 1 0 0 1 1 1 1 0 0 1 1 0 1 
1 0 0 1 1 1 1 0 0 1 1 1 1 0 0 1 
1 0 0 1 1 0 0 0 0 0 0 1 1 0 0 1 
r 0 1 1 1 0 0 0 0 0 0 1 1 1 0 r 
R 1 1 0 1 1 0 0 0 0 1 1 0 1 1 R 
4 1 0 0 0 1 1 1 1 1 1 0 0 0 1 4 
4 1 1 1 1 1 1 0 0 1 1 1 1 1 1 4 
0 1 1 0 0 0 1 0 r 1 0 0 0 1 1 0 
0 0 1 1 0 0 1 0 R 1 0 0 1 1 0 0 
0 0 0 1 1 1 1 1 4 1 1 1 1 0 0 0 
0 0 0 0 0 0 1 1 4 1 0 0 0 0 0 0 
]]},

		}
	end,
	
	setup=function()

		local legend={}
		for n,v in pairs( levels[1].legend ) do -- build tilemap from legend
			if v.name then -- convert name to tile
				legend[n]=system.components.tiles.names[v.name]
			end
		end
		local cx=system.components.map.tile_hx/8
		local cy=system.components.map.tile_hy/8
		
		
		system.components.map.ax=0
		system.components.sprites.ax=0

	end,

	draw=function()
	
	end,

}


entities.systems.insert{ caste="menu",

	loads=function()

		hardware.graphics.loads{

{nil,"portrait_1",[[
o o o o 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 o o o o 
o 1 y 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 y 1 o 
o y y 0 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 0 y y o 
o 0 0 y 0 2 0 0 0 0 0 0 0 0 0 0 0 0 R 0 0 0 0 0 0 0 2 0 y 0 0 o 
2 0 2 0 0 0 0 0 0 0 R 0 0 0 R R R R 0 0 0 0 0 0 0 0 0 0 0 2 0 2 
2 0 0 2 0 0 0 0 R 0 0 R R R R R R R R R R 0 0 0 0 0 0 0 2 0 0 2 
2 0 0 0 0 0 0 0 0 R R R R R R R R R R R R R R 0 0 0 0 0 0 0 0 2 
2 0 0 0 0 0 0 0 R R R R R R R R R R R R R R R R 0 0 0 0 0 0 0 2 
2 0 0 0 0 0 0 0 R R R R R R R R s R R R R R R R 0 0 0 0 0 0 0 2 
2 0 0 0 0 0 0 R R R s s s s s s s s s s s s R R R 0 0 0 0 0 0 2 
2 0 0 0 R 0 R R R s B B B B s s s s B B B B s R R R 0 R 0 0 0 2 
2 0 0 0 0 R 0 R s B D D D D B s s B D D D D B s R 0 R 0 0 0 0 2 
2 0 0 0 0 0 0 R s s f f f f s s s s f f f f s s R 0 0 0 0 0 0 2 
2 0 0 0 0 0 R R s f 7 i i 7 s 6 6 s 7 i i 7 f s R R 0 0 0 0 0 2 
2 0 0 0 0 R 0 R s s f 7 7 f s 6 6 s f 7 7 f s s R 0 R 0 0 0 0 2 
2 0 0 0 R 0 0 R S s s f f s s 6 6 s s f f s s S R 0 0 R 0 0 0 2 
2 0 0 0 0 0 R 0 S s s s s s S F F S s s s s s S 0 R 0 0 0 0 0 2 
2 0 0 0 0 0 0 0 S S s s s S F F F F S s s s S S 0 0 0 0 0 0 0 2 
2 0 0 0 0 0 0 0 R S S S S S S F F S S S S S S R 0 0 0 0 0 0 0 2 
2 0 0 0 0 0 R 0 R S S S S S S S S S S S S S S R 0 0 0 0 0 0 0 2 
2 0 0 0 0 0 0 R 0 0 S S S I I I I I I S S S R 0 R 0 0 0 0 0 0 2 
2 0 0 0 0 0 0 0 0 0 R S S S S 3 3 S S S S R 0 0 0 R 0 0 0 0 0 2 
2 0 0 0 0 0 0 0 0 R 0 R S S S S S S S S R 0 R 0 0 0 0 0 0 0 0 2 
2 0 0 0 0 0 0 0 0 0 0 0 R F S S S S F R 0 0 0 0 0 0 0 0 0 0 0 2 
2 0 0 0 0 0 0 0 0 0 0 0 0 F F F F F F 0 0 0 0 0 0 0 0 0 0 0 0 2 
2 0 0 0 0 0 0 0 0 0 c I 2 2 2 F F 2 2 2 I c 0 0 0 0 0 0 0 0 0 2 
2 0 0 2 0 0 0 0 0 c c c I 2 2 2 2 2 2 I c c c 0 0 0 0 0 2 0 0 2 
2 0 2 0 0 0 0 0 c c B c c I I 1 1 I I c c B c c 0 0 0 0 0 2 0 2 
o 0 0 y 0 2 0 c B B B B B c c I I c c B B B B B c 0 2 0 y 0 0 o 
o y y 1 2 1 c B B o B o B o B c c B B B O B O B B c 1 2 1 y y o 
o 1 y 1 1 B B B B B o B o B B B B B B B B O B B B B B 1 1 y 1 o 
o o o o 2 B B B B B B B B B B B B B B B B B B B B B B 2 o o o o 
]]},
{nil,"portrait_2",[[
y y y y f f f f f f f f f f f f f f f f f f f f f f f f y y y y 
y j 3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 j y 
y 3 3 0 f 0 0 0 0 0 0 0 d d d d d d d d 0 0 0 0 0 0 0 f 0 3 3 y 
y 0 0 y 0 f 0 0 0 0 G G 1 1 1 1 1 1 1 1 G G 0 0 0 0 f 0 y 0 0 y 
f 0 f 0 0 0 0 0 G G 1 1 1 1 i i i i 1 1 1 1 G G 0 0 0 0 0 f 0 f 
f 0 0 f 0 0 0 G 1 1 1 i i i i i i i i i i 1 1 1 G 0 0 0 f 0 0 f 
f 0 0 0 0 0 G 1 1 i i i i i i i i i i i i i i 1 1 G 0 0 0 0 0 f 
f 0 0 0 0 g 1 1 i i i 2 i 2 i 2 2 i 2 i 2 i i i 1 1 g 0 0 0 0 f 
f 0 0 0 0 g 1 i i 2 2 2 2 2 2 2 2 2 2 2 2 2 2 i i 1 g 0 0 0 0 f 
f 0 0 0 g 1 1 i 2 2 j j j j 2 2 2 2 j j j j 2 2 i 1 1 g 0 0 0 f 
f 0 0 0 g 1 1 i 2 2 2 5 5 2 2 2 2 2 2 5 5 2 2 2 i 1 1 g 0 0 0 f 
f 0 0 0 g 1 1 i 2 2 5 i i 5 2 3 3 2 5 i i 5 2 2 i 1 1 g 0 0 0 f 
f 0 0 G 1 1 j j 2 2 5 i i 5 2 3 3 2 5 i i 5 2 2 j j 1 1 G 0 0 f 
f 0 0 G 1 1 1 j F F f 7 7 f 2 3 3 2 f 7 7 f F F j 1 1 1 G 0 0 f 
f 0 0 G 1 1 1 1 j F F f f F F 3 3 F F f f F F j 1 1 1 1 G 0 0 f 
f 0 0 G 1 1 1 j F F F F F F F s s F F F F F F F j 1 1 1 G 0 0 f 
f 0 0 G 1 1 j F F f F F F F F m m F F F F F F F F j 1 1 G 0 0 f 
f 0 0 0 G 1 1 F F F F F F F m m m m F F R F R F F 1 1 G 0 0 0 f 
f 0 0 0 G 1 1 F F F F F F F F m m F F F F R F F F 1 1 G 0 0 0 f 
f 0 0 0 G 1 1 j F F F F F j F F F F j F F F F F j 1 1 G 0 0 0 f 
f 0 0 0 0 g 1 1 F F F F F F j j j j F F F F F F 1 1 g 0 0 0 0 f 
f 0 0 0 0 g 1 1 1 F F F f f f f f f f f F F F 1 1 1 g 0 0 0 0 f 
f 0 0 0 0 0 g 1 1 1 j f f f f i i f f f f j 1 1 1 g 0 0 0 0 0 f 
f 0 0 0 0 0 0 g 1 1 1 1 f f f f f f f f 1 1 1 1 g 0 0 0 0 0 0 f 
f 0 0 0 0 0 0 0 g 1 1 g j j f f f f j j g 1 1 g 0 0 0 0 0 0 0 f 
f 0 0 0 0 0 0 0 0 g 2 g j j j j j j j j g 2 g 0 0 0 0 0 0 0 0 f 
f 0 0 f 0 0 0 0 0 g 2 2 g j j j j j j g 2 2 g 0 0 0 0 0 f 0 0 f 
f 0 f 0 0 0 0 0 g 2 2 2 2 g g j j g g 2 2 2 2 g 0 0 0 0 0 f 0 f 
y 0 0 y 0 f 0 g 2 2 2 G 2 2 2 g g 2 2 2 G 2 2 2 g 0 f 0 y 0 0 y 
y 3 3 j f j g 2 2 2 G 2 2 2 2 2 2 2 2 2 2 G 2 2 2 g j f j 3 3 y 
y j 3 j j 2 2 2 2 G 2 2 2 2 2 2 2 2 2 2 2 2 G 2 2 2 2 j j 3 j y 
y y y y f 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 f y y y y 
]]},
{nil,"portrait_3",[[
o o o o 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 o o o o 
o 0 y 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 y 0 o 
o y y 0 2 0 0 0 0 0 0 0 0 0 5 5 5 5 0 0 0 0 0 0 0 0 0 2 0 y y o 
o 0 0 y 0 2 0 0 0 0 0 5 5 5 4 4 4 4 5 5 5 0 0 0 0 0 2 0 y 0 0 o 
2 0 2 0 0 0 0 0 0 5 5 4 4 4 4 4 4 4 4 4 4 5 5 0 0 0 0 0 0 2 0 2 
2 0 0 2 0 0 0 0 5 4 4 4 4 4 s s s s 4 4 4 4 4 5 0 0 0 0 2 0 0 2 
2 0 0 0 0 0 0 0 4 4 5 5 s s s s s s s s 5 5 4 4 0 0 0 0 0 0 0 2 
2 0 0 0 0 0 0 5 4 5 s s s s s s s s s s s s 5 4 5 0 0 0 0 0 0 2 
2 0 0 0 0 0 0 4 5 s s f f s s s s s s f f s s 5 4 0 0 0 0 0 0 2 
2 0 0 0 0 0 0 4 s s f 7 7 f s s s s f 7 7 f s s 4 0 0 0 0 0 0 2 
2 0 0 0 0 0 S 4 s s 7 i i 7 s 7 7 s 7 i i 7 s s 4 S 0 0 0 0 0 2 
2 0 0 0 0 0 s S s s 7 i i 7 s 7 7 s 7 i i 7 s s S s 0 0 0 0 0 2 
2 0 0 0 0 0 0 S s s f 7 7 f s 7 7 s f 7 7 f s s S 0 0 0 0 0 0 2 
2 0 0 0 1 0 0 F s s s f f s s 7 7 s s f f s s s F 0 0 1 0 0 0 2 
2 0 0 0 0 0 0 0 s s s s s s s S S s s s s s s s 0 0 0 0 0 0 0 2 
2 0 0 0 1 0 0 0 s s S s s s S S S S s s s S s s 0 0 0 1 0 0 0 2 
2 0 0 1 0 1 0 0 0 s s S s F F S S F F s S s s 0 0 0 1 0 1 0 0 2 
2 0 0 0 1 0 0 0 0 s s S s s s F F s s s S s s 0 0 0 0 1 0 0 0 2 
2 0 0 0 0 0 0 0 0 0 s s s s 4 4 4 4 s s s s 0 0 0 0 0 0 0 0 0 2 
2 0 0 0 1 0 0 0 0 0 s s 4 4 f f f f 4 4 s s 0 0 0 0 0 1 0 0 0 2 
2 0 0 1 0 1 0 0 0 0 s 4 4 f 4 4 4 4 f 4 4 s 0 0 0 0 1 0 1 0 0 2 
2 0 1 0 1 0 1 0 0 0 0 4 4 4 4 4 4 4 4 4 4 0 0 0 0 1 0 1 0 1 0 2 
2 0 0 1 0 1 0 0 0 0 0 0 4 4 4 4 4 4 4 4 0 0 0 0 0 0 1 0 1 0 0 2 
2 0 0 0 1 0 0 0 0 0 0 0 0 F 4 4 4 4 F 0 0 0 0 0 0 0 0 1 0 0 0 2 
2 0 0 0 0 0 0 0 0 0 0 0 0 F F F F F F 0 0 0 0 0 0 0 0 0 0 0 0 2 
2 0 0 0 0 0 0 0 0 0 m o I I I F F I I I o m 0 0 0 0 0 0 0 0 0 2 
2 0 0 2 0 0 0 0 0 m m m o I I I I I I o m m m 0 0 0 0 0 2 0 0 2 
2 0 2 0 0 0 0 0 m m o m m o o o o o o m m o m m 0 0 0 0 0 2 0 2 
o 0 0 y 0 2 0 m R R o R R m m o o m m R R o R R m 0 2 0 y 0 0 o 
o y y 0 2 0 m R R R o R R R R m m R R R R o R R R m 0 2 0 y y o 
o 0 y 0 0 R R R R R o R R R R R R R R R R o R R R R R 0 0 y 0 o 
o o o o 2 R R R R R M R R R R M M R R R R M R R R R R 2 o o o o 
]]},
{nil,"portrait_4",[[
d d d d 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 d d d d 
d 0 y 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 y 0 d 
d y y 0 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 0 y y d 
d 0 0 y 0 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 0 y 0 0 d 
2 0 2 0 0 0 0 0 0 0 0 0 0 0 F F F F 0 0 0 0 0 0 0 0 0 0 0 2 0 2 
2 0 0 2 0 0 0 0 0 0 0 F F F f f f f F F F 0 0 0 0 0 0 0 2 0 0 2 
2 0 0 0 0 0 0 0 0 F F f f f f f f f f f f F F 0 0 0 0 0 0 0 0 2 
2 0 0 0 0 0 0 0 F f f f f f f f f f f f f f f F 0 0 0 0 0 0 0 2 
2 0 0 0 0 0 0 0 f f f S f f S f f S f f S f f f 0 0 0 0 0 0 0 2 
2 0 0 0 0 0 0 F f f S S S S S S S S S S S S f f F 0 0 0 0 0 0 2 
2 0 0 0 0 0 0 f f S S f f S S S S S S f f S S f f 0 0 0 0 0 0 2 
2 0 0 0 0 0 F f S S f 7 7 f s S S s f 7 7 f S S f F 0 0 0 0 0 2 
2 0 0 0 0 0 f f S f 7 1 1 7 s s s s 7 1 1 7 f S f f 0 0 0 0 0 2 
2 0 0 0 1 0 f f s s 7 1 1 7 s S S s 7 1 1 7 s s f f 0 1 0 0 0 2 
2 0 0 0 0 0 f f s f f 7 7 f s S S s f 7 7 f f s f f 0 0 0 0 0 2 
2 0 0 0 1 0 f f s s s f f s s S S s s f f s s s f f 0 1 0 0 0 2 
2 0 0 1 0 f 0 0 s s m m m s F 7 7 F s m m m s s 0 0 f 0 1 0 0 2 
2 0 0 0 1 0 0 0 s s m m m s s F F s s m m m s s 0 0 0 1 0 0 0 2 
2 0 0 0 0 0 0 0 0 s s s s s s s s s s s s s s 0 0 0 0 0 0 0 0 2 
2 0 0 0 1 0 0 0 0 s s s s s f s s f s s s s s 0 0 0 0 1 0 0 0 2 
2 0 0 1 0 1 0 0 0 0 s s s s s f f s s s s s 0 0 0 0 1 0 1 0 0 2 
2 0 1 0 1 0 1 0 0 0 0 s s s s s s s s s s 0 0 0 0 1 0 1 0 1 0 2 
2 0 0 1 0 1 0 0 0 0 0 0 s s s s s s s s 0 0 0 0 0 0 1 0 1 0 0 2 
2 0 0 0 1 0 0 0 0 0 0 0 0 F s s s s F 0 0 0 0 0 0 0 0 1 0 0 0 2 
2 0 0 0 0 0 0 0 0 0 0 I b F F F F F F b I 0 0 0 0 0 0 0 0 0 0 2 
2 0 0 0 0 0 0 0 0 0 Y I I b F F F F b I I Y 0 0 0 0 0 0 0 0 0 2 
2 0 0 2 0 0 0 0 0 Y O Y I I b F F b I I Y O Y 0 0 0 0 0 2 0 0 2 
2 0 2 0 0 0 0 0 O O Y Y m I I b b I I m Y Y O O 0 0 0 0 0 2 0 2 
d 0 0 y 0 2 0 O O Y O Y m m I I I I m m Y O Y O O 0 2 0 y 0 0 d 
d y y 0 2 0 0 O O O Y Y m m m I I m m m Y Y O O O 0 0 2 0 y y d 
d 0 y 0 0 0 I I O O O O Y m m I I m m Y O O O O I I 0 0 0 y 0 d 
d d d d 2 2 I I I O O O Y m m I I m m Y O O O I I I 2 2 d d d d 
]]},
{nil, "border",[[
g g . . . . . . . . . . . . . . . . . . . . g g 
g . g g g g . . . . . . . . . . . . g g g g . g 
g . . . . . g g . . . . . . . . g g . . . . . g 
g . . . . . . . g g g . . g g g . . . . . . . g 
g . . . . . . . . . . g g . . . . . . . . . . g 
. g . . . . . . . . . . . . . . . . . . . . g . 
. g . . . . g . . 1 . . . . 1 . . g . . . . g . 
. g . . . . . g g 1 1 . . 1 1 g g . . . . . g . 
. . g . . . . g 1 1 1 1 1 1 1 1 g . . . . g . . 
. . g . . . . . 1 1 1 1 1 1 1 1 . . . . . g . . 
. . g . . . . . 1 1 1 1 1 1 1 1 . . . . . g . . 
. . . g . . 1 1 1 1 1 1 1 1 1 1 1 . . . g . . . 
. . . g . . . 1 1 1 1 1 1 1 1 1 1 1 . . g . . . 
. . g . . . . . 1 1 1 1 1 1 1 1 . . . . . g . . 
. . g . . . . . 1 1 1 1 1 1 1 1 . . . . . g . . 
. . g . . . . g 1 1 1 1 1 1 1 1 g . . . . g . . 
. g . . . . . g g 1 1 . . . 1 1 g . . . . . g . 
. g . . . . g . . 1 . . . . . 1 . g . . . . g . 
. g . . . . . . . . . . . . . . . . . . . . g . 
g . . . . . . . . . . g g . . . . . . . . . . g 
g . . . . . . . g g g . . g g g . . . . . . . g 
g . . . . . g g . . . . . . . . g g . . . . . g 
g . g g g g . . . . . . . . . . . . g g g g . g 
g g . . . . . . . . . . . . . . . . . . . . g g  
]]},

		}
	end,

	setup=function(menu)

		menu.stack={}

		menu.screen_hx=math.floor(hardware.opts.hx/4)
		menu.screen_hy=math.floor(hardware.opts.hy/8)
		menu.width=menu.screen_hx/2
		menu.cursor=0
		menu.cx=math.floor((math.floor(hardware.opts.hx/4)-menu.width))
		menu.cy=0
	
		menu.chats=chatdown.setup(chat_text)<commit_msg>changes<commit_after>
local bitdown=require("wetgenes.gamecake.fun.bitdown")
local chatdown=require("wetgenes.gamecake.fun.chatdown")
local wstr=require("wetgenes.string")
function ls(s) print(wstr.dump(s))end

hardware,main=system.configurator({
	mode="fun64", -- select the standard 320x240 screen using the swanky32 palette.
	update=function() -- called at a steady 60fps
		if setup then setup() setup=nil end -- call an optional setup function *once*
		entities.systems.call("update")
		entities.call("update")
	end,
	draw=function() -- called at actual display frame rate
		entities.systems.call("draw")
		entities.call("draw")
	end,
	hx=440,hy=240, -- wide screen
})

hardware.screen.zxy={0,-1}

hardware.insert{
	component="overmap",
	name="map",					-- same name so will replace the foreground tilemap
	tiles="tiles",
	tilemap_size={48,32},
	tile_size={16,32,16},
	over_size={0,16},
	sort={-1,-1},
	mode="xz",
	layer=2,
}

entities=require("wetgenes.gamecake.fun.entities").create({
	sortby={
	},
})

-- setup all entities
setup=function() entities.systems.call("setup") end




local chat_text=[[

#example A chance meeting

	A rare bread of NPC who will fulfil all your conversational desires for 
	a very good price.

	=sir Madam
	=portrait portrait_1

	>convo

		Is this the right room for a conversation?
		
	>welcome
	
		...ERROR...EOF...PLEASE...RESTART...

<welcome

	Good morning,{sir}!
	
	>morning

		Good morning to you too.

	>afternoon

		I think you will find it is now afternoon.

	>sir

		How dare you call me {sir}!

<sir

	My apologies, I am afraid that I am but an NPC with very little 
	brain, how might I address you?
	
	>welcome.1?sir!=madam

		You may address me as Madam.

		=sir madam
		=portrait portrait_2


	>welcome.2?sir!=God

		You may address me as God.

		=sir God
		=portrait portrait_3

	>welcome.3?sir!=sir

		You may address me as Sir.

		=sir sir
		=portrait portrait_4

<afternoon
	
	Then good afternoon, {sir}.
	
	>convo

<morning
	
	And how may I help {sir} today?
	
	>convo


<convo

	Indeed it is, would you like the full conversation or just the 
	quick natter?

	>convo_full
	
		How long is the full conversation?

	>convo_quick

		A quick natter sounds just perfect.

<convo_full

	The full conversation is very full and long so much so that you 
	will have to page through many pages before you get to make a 
	decision.
	
	>
		Like this?
	<
	
	Yes, just like this. In fact I think you can see that we are already 
	doing it.
			
	
	>exit
		
		EXIT

<convo_quick

	...
	
	>exit

		EXIT
]]





local combine_legends=function(...)
	local legend={}
	for _,t in ipairs{...} do -- merge all
		for n,v in pairs(t) do -- shallow copy, right side values overwrite left
			legend[n]=v
		end
	end
	return legend
end

local default_legend={
	[   0]={ items={"floor_tile"},			},
	[". "]={ items={"floor_tile"}			},
	["x "]={ items={"floor_tile"}			},
	["S "]={ items={"floor_spawn"}			},
	["T "]={ items={"talker"}				},
	["T2"]={ items={"talker2"}				},
	["T3"]={ items={"talker3"}				},
	["T4"]={ items={"talker4"}				},
	["T5"]={ items={"talker5"}				},
	["T6"]={ items={"talker6"}				},
	["T7"]={ items={"talker7"}				},
	["T8"]={ items={"talker8"}				},
	["T9"]={ items={"talker9"}				},
	["T0"]={ items={"talker0"}				},
	["# "]={ items={"wall_full"}			},
	["= "]={ items={"wall_half"}			},
}
	
levels={
 {
 name="page_zero",
 legend=combine_legends(default_legend,{
 }),
 map=[[
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # 
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # 
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # 
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # 
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # 
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # 
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # 
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # 
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # 
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # 
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # 
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # 
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # 
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # 
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # 
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # 
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # 
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # 
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # 
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # 
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # 
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # 
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # 
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # 
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # 
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # 
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # 
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # 
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # 
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # 
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # 
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # 
]],
 },
 {
 name="page_town",
 pages={0x80008000},
 legend=combine_legends(default_legend,{
 }),
 map=[[
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . T7. . . . . . . . . . . . . . . . 
. . . . . = = = = = . . . . . . . . . . . . . . . . . . . . . . 
. . . . . # . . . # . . . . . . . . . . . . . . . . . . . . . . 
. . . . . # . S . # . . . . . . . . . . . . . . . . . . . . . . 
. . . . . # . . . # . . . . . . . . . . . . . . . . . . . . . . 
. . . . . # = . = # T8. . . . . . . . . . . . . T . . . . . . . 
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 
. . . . . . . . . . . . T3. . . . . . . . . . . . . . . . . . . 
. . . . . . . T5. . . . . . . . . . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . . . . # # # # T8. . . . . . . . 
. . . . . . . . . . . . . . T4. . . . # . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . . . . # . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . . . . # . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . . . . . . . # . . . . . . . . . 
. . . . . = = = = = . . . . . . . . . . . . # . . . . . . . . . 
. . . . . # . T2. # . . . . . . . . . # . . # . . . T6. . . . . 
. . . . . # . . . # . . . . . . . . . # . . . . . . . . . . . . 
. . . . . # = . = S = . = = . . . . . # . . # . . . . . . . . . 
. . . . . . . . . # . . . . . . . . . # . . # . . . . . . . . . 
. . . . . . . . . # . S . . . . . . . # . . # . . . . . . . . . 
. . . . . . . . . # . . . . . . . # . # . . . . . . S . . . . . 
. . . . . . . . . T7. . . . . . # # . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . . # . # # # # . . . . . . . . . 
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 
]],
 },
}




entities.systems.insert{ caste="map",

	loads=function()

		hardware.graphics.loads{

{nil,"test_empty",[[
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
]]},

{nil,"test_none",[[
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 
1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 
0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 
1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 
0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 
1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 
0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 
1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 
0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 
1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 
0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 
1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 
0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 
1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 
0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 
1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 
]]},

{nil,"test_tile",[[
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 
0 1 1 1 1 1 1 0 1 0 0 0 0 0 0 1 
0 1 0 0 0 0 1 0 1 0 1 1 1 1 0 1 
0 1 0 0 0 0 1 0 1 0 1 1 1 1 0 1 
0 1 0 0 0 0 1 0 1 0 1 1 1 1 0 1 
0 1 0 0 0 0 1 0 1 0 1 1 1 1 0 1 
0 1 1 1 1 1 1 0 1 0 0 0 0 0 0 1 
0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 
1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 
1 0 0 0 0 0 0 1 0 1 1 1 1 1 1 0 
1 0 1 1 1 1 0 1 0 1 0 0 0 0 1 0 
1 0 1 1 1 1 0 1 0 1 0 0 0 0 1 0 
1 0 1 1 1 1 0 1 0 1 0 0 0 0 1 0 
1 0 1 1 1 1 0 1 0 1 0 0 0 0 1 0 
1 0 0 0 0 0 0 1 0 1 1 1 1 1 1 0 
1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 
]]},

{nil,"test_wall1",[[
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
4 3 2 F F F F F F F F F F 2 3 4 
2 f F F F F F F F F F F F F f 2 
F f F F j j j F F j j j F F f F 
F f F F j f f F F j f f F F f F 
F f F F j f f F F j f f F F f F 
F f F F j f f F F j f f F F f F 
2 f F F F F F F F F F F F F f 2 
4 3 2 F F F F F F F F F F 2 3 4 
3 j f f j j j j j j f f j j j 3 
2 j F f j j f f j j F f j j j 2 
j g F f j j F F j j F f j j f j 
j j f f g j F F j j f f j j F f 
j g j g j j F F j j j j j j F F 
j j f f g j F f j j f f j j F f 
j g F F j j F f j g F F j j F f 
j j F F j j F f g j F F j j f f 
j j F F j j j g j g F F j j j j 
j j F f j j f f g j F f j j f f 
j j F f j j F F j g F f j j F F 
j j f f j j F F j j f f j j F F 
j j j j j j F F j j j g j j F F 
j j f f j j F f j j f f g j F f 
2 j F f j j F f j j F f j g f 2 
3 2 f f j j f f j j f f j j 2 3 
]]},

{nil,"test_wall2",[[
4 3 2 F F F F F F F F F F 2 3 4 
3 f f f f f f f f f f f f f f 3 
2 f F F F F F F F F F F F F f 2 
F f F F j j j F F j j j F F f F 
F f F F j f f F F j f f F F f F 
F f F F j f f F F j f f F F f F 
F f F F j f f F F j f f F F f F 
F f F F j f f F F j f f F F f F 
F f F F j f f F F j f f F F f F 
F f F F j f f F F j f f F F f F 
F f F F j f f F F j f f F F f F 
F f F F j f f F F j f f F F f F 
F f F F j f f F F j f f F F f F 
2 f F F F F F F F F F F F F f 2 
3 f f f f f f f f f f f f f f 3 
4 3 2 F F F F F F F F F F 2 3 4 
3 j f f j j j j j j f f j j j 3 
2 j F f j j f f j j F f j j j 2 
j g F f j j F F j j F f j j f j 
j j f f g j F F j j f f j j F f 
j g j g j j F F j j j j j j F F 
j j f f g j F f j j f f j j F f 
j g F F j j F f j g F F j j F f 
j j F F j j F f g j F F j j f f 
j j F F j j j g j g F F j j j j 
j j F f j j f f g j F f j j f f 
j j F f j j F F j g F f j j F F 
j j f f j j F F j j f f j j F F 
j j j j j j F F j j j g j j F F 
j j f f j j F f j j f f g j F f 
2 j F f j j F f j j F f j g f 2 
3 2 f f j j f f j j f f j j 2 3 
]]},

{nil,"test_spawn",[[
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
. . . . . . . . . . . . . . . . 
. . r . . . . . . . . . . r . . 
. . R . . . . . . . . . . R . . 
0 0 4 0 1 1 1 1 1 1 1 1 0 4 0 0 
0 0 4 1 1 1 0 0 0 0 1 1 1 4 0 0 
0 0 1 0 1 1 0 0 0 0 1 1 0 1 0 0 
0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 
1 1 1 1 0 0 1 1 1 1 0 0 1 1 1 1 
1 0 1 1 0 0 1 1 1 1 0 0 1 1 0 1 
1 0 0 1 1 1 1 0 0 1 1 1 1 0 0 1 
1 0 0 1 1 0 0 0 0 0 0 1 1 0 0 1 
r 0 1 1 1 0 0 0 0 0 0 1 1 1 0 r 
R 1 1 0 1 1 0 0 0 0 1 1 0 1 1 R 
4 1 0 0 0 1 1 1 1 1 1 0 0 0 1 4 
4 1 1 1 1 1 1 0 0 1 1 1 1 1 1 4 
0 1 1 0 0 0 1 0 r 1 0 0 0 1 1 0 
0 0 1 1 0 0 1 0 R 1 0 0 1 1 0 0 
0 0 0 1 1 1 1 1 4 1 1 1 1 0 0 0 
0 0 0 0 0 0 1 1 4 1 0 0 0 0 0 0 
]]},

		}
	end,
	
	setup=function()

		local legend={}
		for n,v in pairs( levels[1].legend ) do -- build tilemap from legend
			if v.name then -- convert name to tile
				legend[n]=system.components.tiles.names[v.name]
			end
		end
		local cx=system.components.map.tile_hx/8
		local cy=system.components.map.tile_hy/8
		
		
		system.components.map.ax=0
		system.components.sprites.ax=0

	end,

	draw=function()
	
	end,

}


entities.systems.insert{ caste="menu",

	loads=function()

		hardware.graphics.loads{

{nil,"portrait_1",[[
o o o o 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 o o o o 
o 1 y 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 y 1 o 
o y y 0 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 0 y y o 
o 0 0 y 0 2 0 0 0 0 0 0 0 0 0 0 0 0 R 0 0 0 0 0 0 0 2 0 y 0 0 o 
2 0 2 0 0 0 0 0 0 0 R 0 0 0 R R R R 0 0 0 0 0 0 0 0 0 0 0 2 0 2 
2 0 0 2 0 0 0 0 R 0 0 R R R R R R R R R R 0 0 0 0 0 0 0 2 0 0 2 
2 0 0 0 0 0 0 0 0 R R R R R R R R R R R R R R 0 0 0 0 0 0 0 0 2 
2 0 0 0 0 0 0 0 R R R R R R R R R R R R R R R R 0 0 0 0 0 0 0 2 
2 0 0 0 0 0 0 0 R R R R R R R R s R R R R R R R 0 0 0 0 0 0 0 2 
2 0 0 0 0 0 0 R R R s s s s s s s s s s s s R R R 0 0 0 0 0 0 2 
2 0 0 0 R 0 R R R s B B B B s s s s B B B B s R R R 0 R 0 0 0 2 
2 0 0 0 0 R 0 R s B D D D D B s s B D D D D B s R 0 R 0 0 0 0 2 
2 0 0 0 0 0 0 R s s f f f f s s s s f f f f s s R 0 0 0 0 0 0 2 
2 0 0 0 0 0 R R s f 7 i i 7 s 6 6 s 7 i i 7 f s R R 0 0 0 0 0 2 
2 0 0 0 0 R 0 R s s f 7 7 f s 6 6 s f 7 7 f s s R 0 R 0 0 0 0 2 
2 0 0 0 R 0 0 R S s s f f s s 6 6 s s f f s s S R 0 0 R 0 0 0 2 
2 0 0 0 0 0 R 0 S s s s s s S F F S s s s s s S 0 R 0 0 0 0 0 2 
2 0 0 0 0 0 0 0 S S s s s S F F F F S s s s S S 0 0 0 0 0 0 0 2 
2 0 0 0 0 0 0 0 R S S S S S S F F S S S S S S R 0 0 0 0 0 0 0 2 
2 0 0 0 0 0 R 0 R S S S S S S S S S S S S S S R 0 0 0 0 0 0 0 2 
2 0 0 0 0 0 0 R 0 0 S S S I I I I I I S S S R 0 R 0 0 0 0 0 0 2 
2 0 0 0 0 0 0 0 0 0 R S S S S 3 3 S S S S R 0 0 0 R 0 0 0 0 0 2 
2 0 0 0 0 0 0 0 0 R 0 R S S S S S S S S R 0 R 0 0 0 0 0 0 0 0 2 
2 0 0 0 0 0 0 0 0 0 0 0 R F S S S S F R 0 0 0 0 0 0 0 0 0 0 0 2 
2 0 0 0 0 0 0 0 0 0 0 0 0 F F F F F F 0 0 0 0 0 0 0 0 0 0 0 0 2 
2 0 0 0 0 0 0 0 0 0 c I 2 2 2 F F 2 2 2 I c 0 0 0 0 0 0 0 0 0 2 
2 0 0 2 0 0 0 0 0 c c c I 2 2 2 2 2 2 I c c c 0 0 0 0 0 2 0 0 2 
2 0 2 0 0 0 0 0 c c B c c I I 1 1 I I c c B c c 0 0 0 0 0 2 0 2 
o 0 0 y 0 2 0 c B B B B B c c I I c c B B B B B c 0 2 0 y 0 0 o 
o y y 1 2 1 c B B o B o B o B c c B B B O B O B B c 1 2 1 y y o 
o 1 y 1 1 B B B B B o B o B B B B B B B B O B B B B B 1 1 y 1 o 
o o o o 2 B B B B B B B B B B B B B B B B B B B B B B 2 o o o o 
]]},
{nil,"portrait_2",[[
y y y y f f f f f f f f f f f f f f f f f f f f f f f f y y y y 
y j 3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 j y 
y 3 3 0 f 0 0 0 0 0 0 0 d d d d d d d d 0 0 0 0 0 0 0 f 0 3 3 y 
y 0 0 y 0 f 0 0 0 0 G G 1 1 1 1 1 1 1 1 G G 0 0 0 0 f 0 y 0 0 y 
f 0 f 0 0 0 0 0 G G 1 1 1 1 i i i i 1 1 1 1 G G 0 0 0 0 0 f 0 f 
f 0 0 f 0 0 0 G 1 1 1 i i i i i i i i i i 1 1 1 G 0 0 0 f 0 0 f 
f 0 0 0 0 0 G 1 1 i i i i i i i i i i i i i i 1 1 G 0 0 0 0 0 f 
f 0 0 0 0 g 1 1 i i i 2 i 2 i 2 2 i 2 i 2 i i i 1 1 g 0 0 0 0 f 
f 0 0 0 0 g 1 i i 2 2 2 2 2 2 2 2 2 2 2 2 2 2 i i 1 g 0 0 0 0 f 
f 0 0 0 g 1 1 i 2 2 j j j j 2 2 2 2 j j j j 2 2 i 1 1 g 0 0 0 f 
f 0 0 0 g 1 1 i 2 2 2 5 5 2 2 2 2 2 2 5 5 2 2 2 i 1 1 g 0 0 0 f 
f 0 0 0 g 1 1 i 2 2 5 i i 5 2 3 3 2 5 i i 5 2 2 i 1 1 g 0 0 0 f 
f 0 0 G 1 1 j j 2 2 5 i i 5 2 3 3 2 5 i i 5 2 2 j j 1 1 G 0 0 f 
f 0 0 G 1 1 1 j F F f 7 7 f 2 3 3 2 f 7 7 f F F j 1 1 1 G 0 0 f 
f 0 0 G 1 1 1 1 j F F f f F F 3 3 F F f f F F j 1 1 1 1 G 0 0 f 
f 0 0 G 1 1 1 j F F F F F F F s s F F F F F F F j 1 1 1 G 0 0 f 
f 0 0 G 1 1 j F F f F F F F F m m F F F F F F F F j 1 1 G 0 0 f 
f 0 0 0 G 1 1 F F F F F F F m m m m F F R F R F F 1 1 G 0 0 0 f 
f 0 0 0 G 1 1 F F F F F F F F m m F F F F R F F F 1 1 G 0 0 0 f 
f 0 0 0 G 1 1 j F F F F F j F F F F j F F F F F j 1 1 G 0 0 0 f 
f 0 0 0 0 g 1 1 F F F F F F j j j j F F F F F F 1 1 g 0 0 0 0 f 
f 0 0 0 0 g 1 1 1 F F F f f f f f f f f F F F 1 1 1 g 0 0 0 0 f 
f 0 0 0 0 0 g 1 1 1 j f f f f i i f f f f j 1 1 1 g 0 0 0 0 0 f 
f 0 0 0 0 0 0 g 1 1 1 1 f f f f f f f f 1 1 1 1 g 0 0 0 0 0 0 f 
f 0 0 0 0 0 0 0 g 1 1 g j j f f f f j j g 1 1 g 0 0 0 0 0 0 0 f 
f 0 0 0 0 0 0 0 0 g 2 g j j j j j j j j g 2 g 0 0 0 0 0 0 0 0 f 
f 0 0 f 0 0 0 0 0 g 2 2 g j j j j j j g 2 2 g 0 0 0 0 0 f 0 0 f 
f 0 f 0 0 0 0 0 g 2 2 2 2 g g j j g g 2 2 2 2 g 0 0 0 0 0 f 0 f 
y 0 0 y 0 f 0 g 2 2 2 G 2 2 2 g g 2 2 2 G 2 2 2 g 0 f 0 y 0 0 y 
y 3 3 j f j g 2 2 2 G 2 2 2 2 2 2 2 2 2 2 G 2 2 2 g j f j 3 3 y 
y j 3 j j 2 2 2 2 G 2 2 2 2 2 2 2 2 2 2 2 2 G 2 2 2 2 j j 3 j y 
y y y y f 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 f y y y y 
]]},
{nil,"portrait_3",[[
o o o o 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 o o o o 
o 0 y 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 y 0 o 
o y y 0 2 0 0 0 0 0 0 0 0 0 5 5 5 5 0 0 0 0 0 0 0 0 0 2 0 y y o 
o 0 0 y 0 2 0 0 0 0 0 5 5 5 4 4 4 4 5 5 5 0 0 0 0 0 2 0 y 0 0 o 
2 0 2 0 0 0 0 0 0 5 5 4 4 4 4 4 4 4 4 4 4 5 5 0 0 0 0 0 0 2 0 2 
2 0 0 2 0 0 0 0 5 4 4 4 4 4 s s s s 4 4 4 4 4 5 0 0 0 0 2 0 0 2 
2 0 0 0 0 0 0 0 4 4 5 5 s s s s s s s s 5 5 4 4 0 0 0 0 0 0 0 2 
2 0 0 0 0 0 0 5 4 5 s s s s s s s s s s s s 5 4 5 0 0 0 0 0 0 2 
2 0 0 0 0 0 0 4 5 s s f f s s s s s s f f s s 5 4 0 0 0 0 0 0 2 
2 0 0 0 0 0 0 4 s s f 7 7 f s s s s f 7 7 f s s 4 0 0 0 0 0 0 2 
2 0 0 0 0 0 S 4 s s 7 i i 7 s 7 7 s 7 i i 7 s s 4 S 0 0 0 0 0 2 
2 0 0 0 0 0 s S s s 7 i i 7 s 7 7 s 7 i i 7 s s S s 0 0 0 0 0 2 
2 0 0 0 0 0 0 S s s f 7 7 f s 7 7 s f 7 7 f s s S 0 0 0 0 0 0 2 
2 0 0 0 1 0 0 F s s s f f s s 7 7 s s f f s s s F 0 0 1 0 0 0 2 
2 0 0 0 0 0 0 0 s s s s s s s S S s s s s s s s 0 0 0 0 0 0 0 2 
2 0 0 0 1 0 0 0 s s S s s s S S S S s s s S s s 0 0 0 1 0 0 0 2 
2 0 0 1 0 1 0 0 0 s s S s F F S S F F s S s s 0 0 0 1 0 1 0 0 2 
2 0 0 0 1 0 0 0 0 s s S s s s F F s s s S s s 0 0 0 0 1 0 0 0 2 
2 0 0 0 0 0 0 0 0 0 s s s s 4 4 4 4 s s s s 0 0 0 0 0 0 0 0 0 2 
2 0 0 0 1 0 0 0 0 0 s s 4 4 f f f f 4 4 s s 0 0 0 0 0 1 0 0 0 2 
2 0 0 1 0 1 0 0 0 0 s 4 4 f 4 4 4 4 f 4 4 s 0 0 0 0 1 0 1 0 0 2 
2 0 1 0 1 0 1 0 0 0 0 4 4 4 4 4 4 4 4 4 4 0 0 0 0 1 0 1 0 1 0 2 
2 0 0 1 0 1 0 0 0 0 0 0 4 4 4 4 4 4 4 4 0 0 0 0 0 0 1 0 1 0 0 2 
2 0 0 0 1 0 0 0 0 0 0 0 0 F 4 4 4 4 F 0 0 0 0 0 0 0 0 1 0 0 0 2 
2 0 0 0 0 0 0 0 0 0 0 0 0 F F F F F F 0 0 0 0 0 0 0 0 0 0 0 0 2 
2 0 0 0 0 0 0 0 0 0 m o I I I F F I I I o m 0 0 0 0 0 0 0 0 0 2 
2 0 0 2 0 0 0 0 0 m m m o I I I I I I o m m m 0 0 0 0 0 2 0 0 2 
2 0 2 0 0 0 0 0 m m o m m o o o o o o m m o m m 0 0 0 0 0 2 0 2 
o 0 0 y 0 2 0 m R R o R R m m o o m m R R o R R m 0 2 0 y 0 0 o 
o y y 0 2 0 m R R R o R R R R m m R R R R o R R R m 0 2 0 y y o 
o 0 y 0 0 R R R R R o R R R R R R R R R R o R R R R R 0 0 y 0 o 
o o o o 2 R R R R R M R R R R M M R R R R M R R R R R 2 o o o o 
]]},
{nil,"portrait_4",[[
d d d d 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 d d d d 
d 0 y 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 y 0 d 
d y y 0 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 0 y y d 
d 0 0 y 0 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 0 y 0 0 d 
2 0 2 0 0 0 0 0 0 0 0 0 0 0 F F F F 0 0 0 0 0 0 0 0 0 0 0 2 0 2 
2 0 0 2 0 0 0 0 0 0 0 F F F f f f f F F F 0 0 0 0 0 0 0 2 0 0 2 
2 0 0 0 0 0 0 0 0 F F f f f f f f f f f f F F 0 0 0 0 0 0 0 0 2 
2 0 0 0 0 0 0 0 F f f f f f f f f f f f f f f F 0 0 0 0 0 0 0 2 
2 0 0 0 0 0 0 0 f f f S f f S f f S f f S f f f 0 0 0 0 0 0 0 2 
2 0 0 0 0 0 0 F f f S S S S S S S S S S S S f f F 0 0 0 0 0 0 2 
2 0 0 0 0 0 0 f f S S f f S S S S S S f f S S f f 0 0 0 0 0 0 2 
2 0 0 0 0 0 F f S S f 7 7 f s S S s f 7 7 f S S f F 0 0 0 0 0 2 
2 0 0 0 0 0 f f S f 7 1 1 7 s s s s 7 1 1 7 f S f f 0 0 0 0 0 2 
2 0 0 0 1 0 f f s s 7 1 1 7 s S S s 7 1 1 7 s s f f 0 1 0 0 0 2 
2 0 0 0 0 0 f f s f f 7 7 f s S S s f 7 7 f f s f f 0 0 0 0 0 2 
2 0 0 0 1 0 f f s s s f f s s S S s s f f s s s f f 0 1 0 0 0 2 
2 0 0 1 0 f 0 0 s s m m m s F 7 7 F s m m m s s 0 0 f 0 1 0 0 2 
2 0 0 0 1 0 0 0 s s m m m s s F F s s m m m s s 0 0 0 1 0 0 0 2 
2 0 0 0 0 0 0 0 0 s s s s s s s s s s s s s s 0 0 0 0 0 0 0 0 2 
2 0 0 0 1 0 0 0 0 s s s s s f s s f s s s s s 0 0 0 0 1 0 0 0 2 
2 0 0 1 0 1 0 0 0 0 s s s s s f f s s s s s 0 0 0 0 1 0 1 0 0 2 
2 0 1 0 1 0 1 0 0 0 0 s s s s s s s s s s 0 0 0 0 1 0 1 0 1 0 2 
2 0 0 1 0 1 0 0 0 0 0 0 s s s s s s s s 0 0 0 0 0 0 1 0 1 0 0 2 
2 0 0 0 1 0 0 0 0 0 0 0 0 F s s s s F 0 0 0 0 0 0 0 0 1 0 0 0 2 
2 0 0 0 0 0 0 0 0 0 0 I b F F F F F F b I 0 0 0 0 0 0 0 0 0 0 2 
2 0 0 0 0 0 0 0 0 0 Y I I b F F F F b I I Y 0 0 0 0 0 0 0 0 0 2 
2 0 0 2 0 0 0 0 0 Y O Y I I b F F b I I Y O Y 0 0 0 0 0 2 0 0 2 
2 0 2 0 0 0 0 0 O O Y Y m I I b b I I m Y Y O O 0 0 0 0 0 2 0 2 
d 0 0 y 0 2 0 O O Y O Y m m I I I I m m Y O Y O O 0 2 0 y 0 0 d 
d y y 0 2 0 0 O O O Y Y m m m I I m m m Y Y O O O 0 0 2 0 y y d 
d 0 y 0 0 0 I I O O O O Y m m I I m m Y O O O O I I 0 0 0 y 0 d 
d d d d 2 2 I I I O O O Y m m I I m m Y O O O I I I 2 2 d d d d 
]]},
{nil, "border",[[
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 
1 1 j 1 1 1 1 1 1 1 1 1 1 1 1 F 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 F 1 1 1 1 1 1 1 1 1 1 1 1 j 1 1 
1 j 1 j F F 1 F 1 f f f f 1 F 1 F 1 F 1 f 1 f f f f 1 f 1 F 1 F 1 F 1 f f f f 1 F 1 F F j 1 j 1 
1 1 j 1 1 1 F 1 F 1 1 1 1 F 1 1 1 F 1 F 1 f 1 1 1 1 f 1 F 1 F 1 1 1 F 1 1 1 1 F 1 F 1 1 1 j 1 1 
1 j F j F F i F i f f f f i F 1 F i F i f i f f f f i f i F i F 1 F i f f f f i F i F F j F j 1 
1 1 j 1 j i f i f i i i i i i F i i i 1 i i i i i i i i 1 i i i F i i i i i i f i f i j 1 j 1 1 
1 1 j 1 j i i f i i i i i i i i i 1 i i i i i i i i i i i i 1 i i i i i i i i i f i i j 1 j 1 1 
1 1 j 1 j i F i i 1 i i i i i i i i i 1 i i i i i i i i 1 i i i i i i i i i 1 i i F i j 1 j 1 1 
1 1 1 F i F i F 1 i 1 1 1 i 1 i i i 1 i 1 i i i i i i 1 i 1 i i i 1 i 1 1 1 i 1 F i F i F 1 1 1 
1 1 f 1 f i F i i 1 i i i 1 i 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 i 1 i i i 1 i i F i f 1 f 1 1 
1 1 f 1 f i i i 1 1 1 1 1 i 1 i 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 i 1 i 1 1 1 1 1 i i i f 1 f 1 1 
1 1 f 1 f i f i 1 i 1 i i i i i 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 i i i i i 1 i 1 i f i f 1 f 1 1 
1 1 f 1 f i i i 1 i 1 i 1 i i 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 i i 1 i 1 i 1 i i i f 1 f 1 1 
1 1 1 F i i i i 1 i 1 i i 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 i i 1 i 1 i i i i F 1 1 1 
1 1 j 1 j i i i i 1 i i i 1 i i 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 i i 1 i i i 1 i i i i j 1 j 1 1 
1 1 1 j 1 j i i 1 i 1 i 1 1 i 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 i 1 1 i 1 i 1 i i j 1 j 1 1 1 
1 1 j 1 j i i i i 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 i i i i j 1 j 1 1 
1 1 1 F i i i i i 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 i i i i i F 1 1 1 
1 1 F 1 F i i i 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 i i i F 1 F 1 1 
1 1 1 F i 1 i 1 i 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 i 1 i 1 i F 1 1 1 
1 1 f 1 f i i i 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 i i i f 1 f 1 1 
1 1 1 f i i i 1 i 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 i 1 i i i f 1 1 1 
1 1 f 1 f i i i 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 i i i f 1 f 1 1 
1 1 f 1 f i i i i 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 i i i i f 1 f 1 1 
1 1 f 1 f i i i i 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 i i i i f 1 f 1 1 
1 1 f 1 f i i i 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 i i i f 1 f 1 1 
1 1 1 f i i i 1 i 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 i 1 i i i f 1 1 1 
1 1 f 1 f i i i 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 i i i f 1 f 1 1 
1 1 1 F i 1 i 1 i 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 i 1 i 1 i F 1 1 1 
1 1 F 1 F i i i 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 i i i F 1 F 1 1 
1 1 1 F i i i i i 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 i i i i i F 1 1 1 
1 1 j 1 j i i i i 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 i i i i j 1 j 1 1 
1 1 1 j 1 j i i 1 i 1 i 1 1 i 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 i 1 1 i 1 i 1 i i j 1 j 1 1 1 
1 1 j 1 j i i i i 1 i i i 1 i i 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 i i 1 i i i 1 i i i i j 1 j 1 1 
1 1 1 F i i i i 1 i 1 i i 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 i i 1 i 1 i i i i F 1 1 1 
1 1 f 1 f i i i 1 i 1 i 1 i i 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 i i 1 i 1 i 1 i i i f 1 f 1 1 
1 1 f 1 f i f i 1 i 1 i i i i i 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 i i i i i 1 i 1 i f i f 1 f 1 1 
1 1 f 1 f i i i 1 1 1 1 1 i 1 i 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 i 1 i 1 1 1 1 1 i i i f 1 f 1 1 
1 1 f 1 f i F i i 1 i i i 1 i 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 i 1 i i i 1 i i F i f 1 f 1 1 
1 1 1 F i F i F 1 i 1 1 1 i 1 i 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 i 1 i 1 1 1 i 1 F i F i F 1 1 1 
1 1 j 1 j i F i i 1 i i i i i i i i 1 i 1 i 1 i i 1 i 1 i 1 i i i i i i i i 1 i i F i j 1 j 1 1 
1 1 j 1 j i i f i i i i i i i i i i i 1 i 1 i i i i 1 i 1 i i i i i i i i i i i f i i j 1 j 1 1 
1 1 j 1 j i f i f i i i i i i F i 1 i i i i i i i i i i i i 1 i F i i i i i i f i f i j 1 j 1 1 
1 j F j F F i F i f f f f i F 1 F i F i f i f f f f i f i F i F 1 F i f f f f i F i F F j F j 1 
1 1 j 1 1 1 F 1 F 1 1 1 1 F 1 1 1 F 1 F 1 f 1 1 1 1 f 1 F 1 F 1 1 1 F 1 1 1 1 F 1 F 1 1 1 j 1 1 
1 j 1 j F F 1 F 1 f f f f 1 F 1 F 1 F 1 f 1 f f f f 1 f 1 F 1 F 1 F 1 f f f f 1 F 1 F F j 1 j 1 
1 1 j 1 1 1 1 1 1 1 1 1 1 1 1 F 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 F 1 1 1 1 1 1 1 1 1 1 1 1 j 1 1 
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1  
]]},

		}
	end,

	setup=function(menu)

		menu.stack={}

		menu.screen_hx=math.floor(hardware.opts.hx/4)
		menu.screen_hy=math.floor(hardware.opts.hy/8)
		menu.width=menu.screen_hx/2
		menu.cursor=0
		menu.cx=math.floor((math.floor(hardware.opts.hx/4)-menu.width))
		menu.cy=0
	
		menu.chats=chatdown.setup(chat_text)
{'fraction_non_alphanumeric': 0.16783124339024022, 'fraction_numerical': 0.15217555521982173, 'mean_word_length': 0.8098639688290382, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2318, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2183885', 'n_tokens_mistral': 34631, 'n_tokens_neox': 26629, 'n_words': 14902}