tsc = {}

--[[ -- Original Cave Story-like values.
local FAST = 1
local SLOW = 5
]] -- Faster values for English. (English words are a little longer!)
local FAST = 0
local SLOW = 3


function tsc.think()
	if tsc.mna
		tsc.mna[1] = tsc.mna[1] - 1/50
		if tsc.mna[1] <= 0.0
			tsc.mna = nil
		end
	end
	if tsc.addtext and tsc.addtext[1] ~= #tsc.addtext[2]
		if tsc.addtext[3] == 0
			tsc.addtext[1] = tsc.addtext[1] + 1
			if input.buttons & 1<<BTN.OK ~= 0
				tsc.addtext[3] = FAST
			else
				tsc.addtext[3] = SLOW
			end
			local char = tsc.addtext[2]:sub(tsc.addtext[1],tsc.addtext[1])
			if char == '\n'
				table.insert(tsc.msgtext,1,"")
				tsc.msgtext[msgbox.lines+1] = nil
			else
				-- Crazy-ass word-wrappin' shit.
				if font.string_width(tsc.msgtext[1] .. '_') > 244-16
					local s,e,word = tsc.msgtext[1]:find("^.*%s(.-)$")
					if not s
						table.insert(tsc.msgtext,1,"")
					else
						tsc.msgtext[1] = tsc.msgtext[1]:sub(1,e-#word)
						table.insert(tsc.msgtext,1,word)
					end
					tsc.msgtext[msgbox.lines+1] = nil
				end
				tsc.msgtext[1] = (tsc.msgtext[1] or "") .. char
			end
		else
			tsc.addtext[3] = tsc.addtext[3] - 1
		end
		if tsc.addtext[1] == #tsc.addtext[2]
			tsc.addtext = nil
			if not tsc.nod
				net.tsc_text()
			end
		end
	elseif tsc.ynj
		local cursor = tsc.ynjcursor or 0
		if input.btn_start & 1<<BTN.LEFT ~= 0
			cursor = 0
		elseif input.btn_start & 1<<BTN.RIGHT ~= 0
			cursor = 1
		end
		tsc.ynjcursor = cursor
		if input.btn_start & 1<<BTN.OK ~= 0
			if cursor == 0
				net.tsc_nod()
			else
				net.tsc_ynj()
			end
			tsc.ynj = nil
			tsc.ynjcursor = nil
		end
	elseif tsc.nod and input.btn_start & 1<<BTN.OK ~= 0
		tsc.nod = false
		net.tsc_nod()
	end
end

function tsc.close()
	tsc.msgbox = nil
	tsc.msgtext = {}
	tsc.nod = false
	tsc.addtext = nil
end

function tsc.reset()
	tsc.close()
	tsc.keylock = nil
end
