Module:InputsWanWan

From Mizuumi Wiki
Jump to navigation Jump to search

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

local p = {}

-- List of valid inputs to be used for p.toIcons
local validInputs = {
  -- Connectors
  ["~"] = ", then ", -- Follow-up
  ["%+"]  = " + ", -- Plus
  ["/"] = " / ", -- Or
  
  -- Motions
  ["360"] = "[[File:360.png|x22px|360]]",
  ["4123641236"] = "[[File:4.png|x22px|4]][[File:1.png|x22px|1]][[File:2.png|x22px|2]][[File:3.png|x22px|3]][[File:6.png|x22px|6]][[File:4.png|x22px|4]][[File:1.png|x22px|1]][[File:2.png|x22px|2]][[File:3.png|x22px|3]][[File:6.png|x22px|6]]",
  ["236236"]   = "[[File:2.png|x22px|2]][[File:3.png|x22px|3]][[File:6.png|x22px|6]][[File:2.png|x22px|2]][[File:3.png|x22px|3]][[File:6.png|x22px|6]]",
  ["214214"]   = "[[File:2.png|x22px|2]][[File:1.png|x22px|1]][[File:4.png|x22px|4]][[File:2.png|x22px|2]][[File:1.png|x22px|1]][[File:4.png|x22px|4]]",  
  ["41236"] = "[[File:4.png|x22px|4]][[File:1.png|x22px|1]][[File:2.png|x22px|2]][[File:3.png|x22px|3]][[File:6.png|x22px|6]]",
  ["63214"] = "[[File:6.png|x22px|6]][[File:3.png|x22px|3]][[File:2.png|x22px|2]][[File:1.png|x22px|1]][[File:4.png|x22px|4]]",
  ["2146"]   = "[[File:2.png|x22px|2]][[File:1.png|x22px|1]][[File:4.png|x22px|4]][[File:6.png|x22px|6]]",
  ["2364"]   = "[[File:2.png|x22px|2]][[File:3.png|x22px|3]][[File:6.png|x22px|6]][[File:4.png|x22px|4]]",
  ["236"]   = "[[File:2.png|x22px|2]][[File:3.png|x22px|3]][[File:6.png|x22px|6]]",
  ["214"]   = "[[File:2.png|x22px|2]][[File:1.png|x22px|1]][[File:4.png|x22px|4]]",
  ["623"]   = "[[File:6.png|x22px|6]][[File:2.png|x22px|2]][[File:3.png|x22px|3]]",
  ["421"]   = "[[File:4.png|x22px|4]][[File:2.png|x22px|2]][[File:1.png|x22px|1]]",
  ["22"]    = "[[File:2.png|x22px|2]][[File:2.png|x22px|2]]",
  ["44"]    = "[[File:4.png|x22px|4]][[File:4.png|x22px|4]]",
  ["66"]    = "[[File:6.png|x22px|6]][[File:6.png|x22px|6]]",
  ["88"]    = "[[File:8.png|x22px|8]][[File:8.png|x22px|8]]",
  ["[4]6"]    = "[[File:4.png|x22px|4]] (hold) [[File:6.png|x22px|6]]",
  ["[2]8"]    = "[[File:2.png|x22px|2]] (hold) [[File:8.png|x22px|8]]",
  ["[6]4"]    = "[[File:6.png|x22px|6]] (hold) [[File:4.png|x22px|4]]",
  ["[8]2"]    = "[[File:8.png|x22px|8]] (hold) [[File:2.png|x22px|2]]",
  ["[4]646"]    = "[[File:4.png|x22px|4]] (hold) [[File:6.png|x22px|6]][[File:4.png|x22px|4]][[File:6.png|x22px|6]]",
  ["[1]319"]    = "[[File:1.png|x22px|1]] (hold) [[File:3.png|x22px|3]][[File:1.png|x22px|1]][[File:9.png|x22px|9]]",
  
  -- Directions
  ["5"] = "", -- Neutral (No image needed)
  ["6"] = "[[File:6.png|x22px|6]]", -- Forward
  ["3"] = "[[File:3.png|x22px|3]]", -- Down-foward
  ["2"] = "[[File:2.png|x22px|2]]", -- Down
  ["1"] = "[[File:1.png|x22px|1]]", -- Down-back
  ["4"] = "[[File:4.png|x22px|4]]", -- Back
  ["9"] = "[[File:9.png|x22px|9]]", -- Up-Forward
  ["8"] = "[[File:8.png|x22px|8]]", -- Up
  ["7"] = "[[File:7.png|x22px|7]]", -- Up-back
  
  -- Special Buttons
  ["throw"] = "[[File:throw.png  |x22px|throw]]",
  ["assault"] = "[[File:assault.png|x22px|assault]]",
  ["cvo"] = "[[File:cvo.png|x22px|cvo]]", -- Cross cast veil off
  ["cs"]  = "[[File:cs.png |x22px|cs]]", -- Chain shift
  
  -- Special Notation
  ["land"] = "[[File:land.png|x22px|land]]", -- Land
  ["jc"]   = "[[File:jc.png  |x22px|jc]]", -- Jump cancel
  
  -- Prefixes
  ["d"] = "dl", -- Delay
  ["j"] = "In air, ", -- Jump
  ["j."] = "In air, ", -- Jump
  ["w"] = "[[File:Whiff.png|x22px|w]]", -- Whiff
  
  -- Buttons with '5' in alt text
  ["5P"]  = "[[File:WanWan_Inputs_P.png|x22px|5P]]",
  ["5K"]  = "[[File:WanWan_Inputs_K.png|x22px|5K]]",
  ["5S"]  = "[[File:WanWan_Inputs_S.png|x22px|5S]]",
  ["5HS"]  = "[[File:WanWan_Inputs_HS.png|x22px|5HS]]",
  ["5O"]  = "[[File:WanWan_Inputs_O.png|x22px|5O]]",
  ["5SP"]  = "[[File:WanWan_Inputs_SP.png|x22px|5SP]]",
  
  -- Buttons
  ["P"] = "[[File:WanWan_Inputs_P.png |x22px|P]]",
  ["K"] = "[[File:WanWan_Inputs_K.png |x22px|K]]",
  ["S"] = "[[File:WanWan_Inputs_S.png |x22px|S]]",
  ["HS"] = "[[File:WanWan_Inputs_HS.png |x22px|HS]]",
  ["O"] = "[[File:WanWan_Inputs_O.png |x22px|O]]",
  ["SP"] = "[[File:WanWan_Inputs_SP.png |x22px|SP]]",
  ["X"] = "[[File:X.png |x22px|X]]",
  ["vo"]  = "[[File:vo.png|x22px|vo]]", -- Veil off
  ["ff"]  = "[[File:ff.png|x22px|ff]]", -- Force function
  
  -- Hold Buttons
  ["[4]"] = "Hold [[File:4.png|x22px|[4]]], then ",
  ["[P]"] = "[[File:Hold.png|x22px|]][[File:WanWan_Inputs_P.png|x22px|[P]]]",
  ["[K]"] = "[[File:Hold.png|x22px|]][[File:WanWan_Inputs_K.png|x22px|[K]]]",
  ["[S]"] = "[[File:Hold.png|x22px|]][[File:WanWan_Inputs_S.png|x22px|[S]]]",
  ["[HS]"] = "[[File:Hold.png|x22px|]][[File:WanWan_Inputs_HS.png|x22px|[HS]]]",
  ["[O]"] = "[[File:Hold.png|x22px|]][[File:WanWan_Inputs_O.png|x22px|[O]]]",
  ["[SP]"] = "[[File:Hold.png|x22px|]][[File:WanWan_Inputs_SP.png|x22px|[SP]]]",
  ["[X]"] = "[[File:Hold.png|x22px|]][[File:X.png|x22px|[X]]]",
  ["[vo]"]  = "[[File:vo_Hold.png|x22px|[vo]]]", -- Veil off
  ["[ff]"]  = "[[File:ff_Hold.png|x22px|[ff]]]", -- Force function
  -- Release Buttons
  ["]P["] = "[[File:A_Release.png|x22px|]P[]]",
  ["]K["] = "[[File:B_Release.png|x22px|]K[]]",
  ["]S["] = "[[File:C_Release.png|x22px|]S[]]",
  ["]HS["] = "[[File:D_Release.png|x22px|]HS[]]",
  ["]O["] = "[[File:D_Release.png|x22px|]O[]]",
  ["]SP["] = "[[File:D_Release.png|x22px|]SP[]]",
  ["]X["] = "[[File:X_Release.png|x22px|]X[]]",
  ["]vo["]  = "[[File:vo_Release.png|x22px|]vo[]]", -- Veil off
  ["]ff["]  = "[[File:ff_Release.png|x22px|]ff[]]", -- Force function
  
  [" "]   = "[[File: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, P, K, S, HS, 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) == "P" or
      string.sub(inputText,1,1) == "K" or
      string.sub(inputText,1,1) == "S" or
      string.sub(inputText,1,1) == "HS" or
      string.sub(inputText,1,1) == "4" 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