Module:InputsMBTL

From Mizuumi Wiki
Jump to navigation Jump to search

Documentation for this module may be created at Module:InputsMBTL/doc

local p = {}

-- List of valid inputs to be used for p.toIcons
local validInputs = {
  -- Connectors
  ["~"] = " > Add", -- Follow-up
  ["%+"]  = "+", -- Plus
  ["/"] = "/", -- Or
  
  -- Motions
  ["360"] = "[[File:UNI_Input_360.png|x22px|360]]",
  ["41236"] = "[[File:UNI_Input_4.png|x22px|4]][[File:UNI_Input_1.png|x22px|1]][[File:UNI_Input_2.png|x22px|2]][[File:UNI_Input_3.png|x22px|3]][[File:UNI_Input_6.png|x22px|6]]",
  ["63214"] = "[[File:UNI_Input_6.png|x22px|6]][[File:UNI_Input_3.png|x22px|3]][[File:UNI_Input_2.png|x22px|2]][[File:UNI_Input_1.png|x22px|1]][[File:UNI_Input_4.png|x22px|4]]",
  ["236"]   = "[[File:UNI_Input_2.png|x22px|2]][[File:UNI_Input_3.png|x22px|3]][[File:UNI_Input_6.png|x22px|6]]",
  ["214"]   = "[[File:UNI_Input_2.png|x22px|2]][[File:UNI_Input_1.png|x22px|1]][[File:UNI_Input_4.png|x22px|4]]",
  ["623"]   = "[[File:UNI_Input_6.png|x22px|6]][[File:UNI_Input_2.png|x22px|2]][[File:UNI_Input_3.png|x22px|3]]",
  ["421"]   = "[[File:UNI_Input_4.png|x22px|4]][[File:UNI_Input_2.png|x22px|2]][[File:UNI_Input_1.png|x22px|1]]",
  ["22"]    = "[[File:UNI_Input_2.png|x22px|2]][[File:UNI_Input_2.png|x22px|2]]",
  ["66"]    = "[[File:UNI_Input_66.png|x22px|66]]",
  ["[4]6"]  = "[[File:UNI_Input_Hold.png|x22px|]][[File:UNI_Input_4.png|x22px|[4]]][[File:UNI_Input_Then.png|x22px|]][[File:UNI_Input_6.png|x22px|6]]",
  ["[6]4"]  = "[[File:UNI_Input_Hold.png|x22px|]][[File:UNI_Input_6.png|x22px|[6]]][[File:UNI_Input_Then.png|x22px|]][[File:UNI_Input_4.png|x22px|4]]",
  ["[2]8"]  = "[[File:UNI_Input_Hold.png|x22px|]][[File:UNI_Input_2.png|x22px|[2]]][[File:UNI_Input_Then.png|x22px|]][[File:UNI_Input_8.png|x22px|8]]",
  ["[8]2"]  = "[[File:UNI_Input_Hold.png|x22px|]][[File:UNI_Input_8.png|x22px|[8]]][[File:UNI_Input_Then.png|x22px|]][[File:UNI_Input_2.png|x22px|2]]",
  
  -- Directions
  ["5"] = "", -- Neutral (No image needed)
  ["6"] = "[[File:UNI_Input_6.png|x22px|6]]", -- Forward
  ["3"] = "[[File:UNI_Input_3.png|x22px|3]]", -- Down-foward
  ["2"] = "[[File:UNI_Input_2.png|x22px|2]]", -- Down
  ["1"] = "[[File:UNI_Input_1.png|x22px|1]]", -- Down-back
  ["4"] = "[[File:UNI_Input_4.png|x22px|4]]", -- Back
  ["9"] = "[[File:UNI_Input_9.png|x22px|9]]", -- Up-Forward
  ["8"] = "[[File:UNI_Input_8.png|x22px|8]]", -- Up
  ["7"] = "[[File:UNI_Input_7.png|x22px|7]]", -- Up-back
  
  -- Special Buttons
  ["throw"] = "[[File:UNI_Input_throw.png  |x22px|throw]]",
  ["assault"] = "[[File:UNI_Input_assault.png|x22px|assault]]",
  ["cvo"] = "[[File:UNI_Input_cvo.png|x22px|cvo]]", -- Cross cast veil off
  ["cs"]  = "[[File:UNI_Input_cs.png |x22px|cs]]", -- Chain shift
  
  -- Special Notation
  ["land"] = "[[File:UNI_Input_land.png|x22px|land]]", -- Land
  ["jc"]   = "[[File:UNI_Input_jc.png  |x22px|jc]]", -- Jump cancel
  
  -- Prefixes
  ["d"] = "dl", -- Delay
  ["j"] = "Aerial", -- Jump
  ["w"] = "[[File:UNI_Input_Whiff.png|x22px|w]]", -- Whiff
  
  -- Buttons with '5' in alt text
  ["5A"]  = "[[File:MBTL_Input_A.png|x22px|5A]]",
  ["5B"]  = "[[File:MBTL_Input_B.png|x22px|5B]]",
  ["5C"]  = "[[File:MBTL_Input_C.png|x22px|5C]]",
  ["5D"]  = "[[File:MBTL_Input_D.png|x22px|5D]]",
  ["5E"]  = "[[File:MBTL_Input_E.png|x22px|5E]]",
  ["5X"]  = "[[File:UNI_Input_X.png|x22px|5X]]",
  
  -- Buttons
  ["A"] = "[[File:MBTL_Input_A.png |x22px|A]]",
  ["B"] = "[[File:MBTL_Input_B.png |x22px|B]]",
  ["C"] = "[[File:MBTL_Input_C.png |x22px|C]]",
  ["D"] = "[[File:MBTL_Input_D.png |x22px|D]]",
  ["E"] = "[[File:MBTL_Input_E.png |x22px|E]]",
  ["X"] = "[[File:UNI_Input_X.png |x22px|X]]",
  ["vo"]  = "[[File:UNI_Input_vo.png|x22px|vo]]", -- Veil off
  ["ff"]  = "[[File:UNI_Input_ff.png|x22px|ff]]", -- Force function
  -- Hold Buttons
  ["[A]"] = "[[File:UNI_Input_Hold.png|x22px|]][[File:UNI_Input_A.png|x22px|[A]]]",
  ["[B]"] = "[[File:UNI_Input_Hold.png|x22px|]][[File:UNI_Input_B.png|x22px|[B]]]",
  ["[C]"] = "[[File:UNI_Input_Hold.png|x22px|]][[File:UNI_Input_C.png|x22px|[C]]]",
  ["[D]"] = "[[File:UNI_Input_Hold.png|x22px|]][[File:UNI_Input_D.png|x22px|[D]]]",
  ["[X]"] = "[[File:UNI_Input_Hold.png|x22px|]][[File:UNI_Input_X.png|x22px|[X]]]",
  ["[vo]"]  = "[[File:UNI_Input_vo_Hold.png|x22px|[vo]]]", -- Veil off
  ["[ff]"]  = "[[File:UNI_Input_ff_Hold.png|x22px|[ff]]]", -- Force function
  -- Release Buttons
  ["]A["] = "[[File:UNI_Input_A_Release.png|x22px|]A[]]",
  ["]B["] = "[[File:UNI_Input_B_Release.png|x22px|]B[]]",
  ["]C["] = "[[File:UNI_Input_C_Release.png|x22px|]C[]]",
  ["]D["] = "[[File:UNI_Input_D_Release.png|x22px|]D[]]",
  ["]X["] = "[[File:UNI_Input_X_Release.png|x22px|]X[]]",
  ["]vo["]  = "[[File:UNI_Input_vo_Release.png|x22px|]vo[]]", -- Veil off
  ["]ff["]  = "[[File:UNI_Input_ff_Release.png|x22px|]ff[]]", -- Force function
  
  [" "]   = "[[File:UNI_Input_next.png|x22px|>]]" -- Next Input
}

-- Change a string of characters to a list of images in wikitext format (reference above table)
function p.toIcons(frame)
  -- Get string
  local inputText = frame.args[1]
  local ret = ""
  
  -- Check if current inputText is matching with any validInputs
  local checkInputText = type(validInputs[inputText]) == "function" and validInputs[inputText]() or validInputs[inputText] or nil
  
  -- If it doesn't match, then keep checking down
  if checkInputText==nil then
    -- If text contains spaces, split it down
    if string.find(inputText, " ") then
      local inputTextAsList = splitKeepDelimiter(inputText, " ")
      for i,v in ipairs(inputTextAsList) do
        ret = ret..p.toIcons({args={v}})
      end
    -- If text contains '~', split it down
    elseif string.find(inputText,"~") then
      local inputTextAsList = splitKeepDelimiter(inputText, "~")
      for i,v in ipairs(inputTextAsList) do
        ret = ret..p.toIcons({args={v}})
      end
    -- If text contains '+', split it down
    elseif string.find(inputText,"%+") then
      local inputTextAsList = splitKeepDelimiter(inputText, "%+")
      for i,v in ipairs(inputTextAsList) do
        ret = ret..p.toIcons({args={v}})
      end
    -- If text contains '/', split it down
    elseif string.find(inputText,"/") then
      local inputTextAsList = splitKeepDelimiter(inputText, "/")
      for i,v in ipairs(inputTextAsList) do
        ret = ret..p.toIcons({args={v}})
      end
    -- If text contain a digit then a letter, then split at that point
    elseif string.find(inputText,"%d%a") then
      local frontEnd,backEnd = string.find(inputText,"%d%a")
      ret = ret..p.toIcons({args={string.sub(inputText,1,frontEnd)}}).."+"..p.toIcons({args={string.sub(inputText,backEnd)}})
    -- If text contain a digit then a left square bracket, then split at that point
    elseif string.find(inputText,"%d%[") then
      local frontEnd,backEnd = string.find(inputText,"%d%[")
      ret = ret..p.toIcons({args={string.sub(inputText,1,frontEnd)}}).."+"..p.toIcons({args={string.sub(inputText,backEnd)}})
    -- If text starts with d, j, w, A, B, C, D, then split after that first character
    elseif  string.sub(inputText,1,1) == "d" or
      string.sub(inputText,1,1) == "j" or
      string.sub(inputText,1,1) == "w" or
      string.sub(inputText,1,1) == "A" or
      string.sub(inputText,1,1) == "B" or
      string.sub(inputText,1,1) == "C" or
      string.sub(inputText,1,1) == "D" then
      ret = ret..p.toIcons({args={string.sub(inputText,1,1)}}).." "..p.toIcons({args={string.sub(inputText,2)}})
    -- Otherwise, return the text in parenthesis (Which I don't want to happen, because this would look bad if parsed poorly!!!)
    else
      ret = "("..inputText..")"
    end
  else
    ret = checkInputText
  end
  
  -- Return the result
  return ret
end

-- Split string 's' at every 'delimiter' into an array
function splitKeepDelimiter(s, delimiter)
  -- Array to return
  local result = {}
  
  -- Boolean to check if this is the firstSplit (only applicable when keeping delimiter)
  local firstSplit = true
  
  -- Iterate through the string finding every section split with delimiter
  for match in (s..delimiter):gmatch("(.-)"..delimiter) do
    -- Don't add the delimiter until after the first split
    if firstSplit then
      firstSplit = false
    else
      table.insert(result, delimiter)
    end
    
    -- Remove a '%' character if it's leftover from a delimiter
    local matchWithEscapedRemoved = match
    if string.find(string.sub(match,-1, string.len(match)),"%%") then
      matchWithEscapedRemoved = string.sub(match, 1, -2)
    end
    
    -- Add the match to the result array
    table.insert(result, matchWithEscapedRemoved)
  end
  
  -- Return the result
  return result
end

return p