From 5f85b92b6d31ba3d4255a95b4f98328f541bfcfa Mon Sep 17 00:00:00 2001 From: Connor Olding Date: Fri, 8 Jun 2018 23:59:55 +0200 Subject: [PATCH] simplify gameconfig button specification --- gameconfig.lua | 73 +++++++++++++++++++++++--------------------------- 1 file changed, 33 insertions(+), 40 deletions(-) diff --git a/gameconfig.lua b/gameconfig.lua index 775cae7..4a43622 100644 --- a/gameconfig.lua +++ b/gameconfig.lua @@ -1,6 +1,26 @@ -- "gameconfig" is kind of a misnomer, to be honest. -- it's more like things the end user shouldn't have to change. +local function jp_buttons(s) + s = string.lower(s or "") + local t = { + up = false, down = false, left = false, right = false, + select = false, start = false, B = false, A = false, + } + for w in s:gmatch("%a+") do + if w == 'up' then t.up = true + elseif w == 'down' then t.down = true + elseif w == 'left' then t.left = true + elseif w == 'right' then t.right = true + elseif w == 'select' then t.select = true + elseif w == 'start' then t.start = true + elseif w == 'a' then t.A = true + elseif w == 'b' then t.B = true + else error(("unknown button: %s"):format(w)) end + end + return t +end + local gcfg = { input_size = 60 + 4, -- TODO: let the script figure this out for us. tile_count = 17 * 13, @@ -25,46 +45,19 @@ local gcfg = { }, jp_lut = { - { -- none - up = false, down = false, left = false, right = false, - select = false, start = false, B = false, A = false, - }, { -- A - up = false, down = false, left = false, right = false, - select = false, start = false, B = false, A = true, - }, { -- L - up = false, down = false, left = true, right = false, - select = false, start = false, B = false, A = false, - }, { -- R - up = false, down = false, left = false, right = true, - select = false, start = false, B = false, A = false, - }, { -- L + B - up = false, down = false, left = true, right = false, - select = false, start = false, B = true, A = false, - }, { -- R + B - up = false, down = false, left = false, right = true, - select = false, start = false, B = true, A = false, - }, { -- L + A - up = false, down = false, left = true, right = false, - select = false, start = false, B = false, A = true, - }, { -- R + A - up = false, down = false, left = false, right = true, - select = false, start = false, B = false, A = true, - }, { -- L + A + B - up = false, down = false, left = true, right = false, - select = false, start = false, B = true, A = true, - }, { -- R + A + B - up = false, down = false, left = false, right = true, - select = false, start = false, B = true, A = true, - }, { -- D - up = false, down = true, left = false, right = false, - select = false, start = false, B = false, A = false, - }, { -- D + A - up = false, down = true, left = false, right = false, - select = false, start = false, B = false, A = true, - }, { -- U - up = true, down = false, left = false, right = false, - select = false, start = false, B = false, A = false, - }, + jp_buttons(), + jp_buttons("a"), + jp_buttons("left"), + jp_buttons("right"), + jp_buttons("b left"), + jp_buttons("b right"), + jp_buttons("a left"), + jp_buttons("a right"), + jp_buttons("b a left"), + jp_buttons("b a right"), + jp_buttons("down"), + jp_buttons("a down"), + jp_buttons("up"), }, }