Module:Sandbox/Moxian: Difference between revisions

From Dustloop Wiki
mNo edit summary
No edit summary
Line 63: Line 63:
   appendFrames(atkFrames, specialRecovery, "specialRecovery")
   appendFrames(atkFrames, specialRecovery, "specialRecovery")


  local totalRecovery = #atkFrames
   -- now deal with projectiles
   -- now deal with projectiles
   if isProjectile then
   if isProjectile then
Line 68: Line 69:
   end
   end


   wikitext = wikitext .. framesToWikitext(atkFrames, isProjectile, projOffset)
   wikitext = wikitext .. framesToWikitext(atkFrames, isProjectile, startup+projOffset)


   wikitext = wikitext .. "<span style=\"font-size: 90%\">  '''Total: '''" .. currentFrame .. "</span></div>"
   wikitext = wikitext .. "<span style=\"font-size: 90%\">  '''Total: '''" .. totalRecovery .. "</span></div>"


   return wikitext
   return wikitext

Revision as of 00:23, 22 December 2022

random thing: Lua error at line 71: attempt to perform arithmetic on local 'projOffset' (a nil value).

Baiken's tatami (presumably):

Total: 48

Millia's H disk:

Total: 65

Testament S reaper (uncharged)

Total: 46

Anji's butterfly

Total: 51

local p = {}

local currentFrame
local wikitext

function p.drawFrameData(frame)
  currentFrame = 0
  wikitext = "<div class=\"frameChart\">"

  -- Startup is the first active frame. Sets to true if empty. Otherwise it's false.
  local startupIsFirstActive
  if frame.args['startupIsFirstActive'] == nil then
    startupIsFirstActive = true
  else
    startupIsFirstActive = false
  end
  
  -- Startup of move, substract 1 if startupIsFirstActive
  local startup = frame.args['startup']
  if tonumber(startup) ~= nil then
    if startupIsFirstActive and tonumber(startup) > 0 then
      startup = tonumber(startup) - 1
    end
  end
  
  -- Active of move
  local active = frame.args['active']
  -- Inactive of move
  local inactive = frame.args['inactive']
  -- Recovery of move
  local recovery = frame.args['recovery']
  -- Special Recovery of move
  local specialRecovery = frame.args['specialRecovery']
  -- Display projectile spawn bar after startup?
  local isProjectile = frame.args['isProjectile']
  -- FRC window
  frcStart = frame.args['frcStart']
  frcEnd = frame.args['frcEnd']
  -- projectile thingies
  local projOffset = frame.args['projOffset']
  local projInactive = frame.args['projInactive']
  local projActive = frame.args['projActive']

  local atkFrames = {}
 
--   drawFrame(startup,  "startup")
  appendFrames(atkFrames, startup, "startup")
--   drawFrame(active,   "active")
  appendFrames(atkFrames, active, "active")
  
  local index = 2
  while tonumber(frame.args['active' .. index]) ~= nil or tonumber(frame.args['inactive' .. index]) ~= nil do
    -- drawFrame(frame.args['active' .. index], "active")
    -- drawFrame(frame.args['inactive' .. index], "inactive")
    appendFrames(atkFrames, frame.args['active' .. index], "active")
    appendFrames(atkFrames, frame.args['inactive' .. index], "inactive")
    index = index + 1
  end
  
--   drawFrame(recovery, "recovery")
--   drawFrame(specialRecovery, "specialRecovery")
  appendFrames(atkFrames, recovery, "recovery")
  appendFrames(atkFrames, specialRecovery, "specialRecovery")

  local totalRecovery = #atkFrames
  -- now deal with projectiles
  if isProjectile then
    appendProjFrames(atkFrames, startup, projOffset, projInactive, projActive)
  end

  wikitext = wikitext .. framesToWikitext(atkFrames, isProjectile, startup+projOffset)

  wikitext = wikitext .. "<span style=\"font-size: 90%\">  '''Total: '''" .. totalRecovery .. "</span></div>"

  return wikitext
end

function appendFrames(atkFrames, amt, typ)
    if amt == nil then return end
    for i=1, amt do
        table.insert(atkFrames, {typ})
    end
end
function appendProjFrames(atkFrames, startup, projOffset, projInactive, projActive)
    local frameNo = 0
    startup = tonumber(startup) or 0
    projOffset = tonumber(projOffset) or 0
    projInactive = tonumber(projInactive) or 0
    projActive = tonumber(projActive) or 0
    for i=1, startup + projOffset do
        frameNo = frameNo + 1
        if #atkFrames < frameNo then
            table.insert(atkFrames, {"dummy"})
        end
    end
    for i=1,projInactive do
        frameNo = frameNo + 1
        if #atkFrames < frameNo then
            table.insert(atkFrames, {"dummy"})
        end
        table.insert(atkFrames[frameNo], "inactive")
    end
    for i=1,projActive do
        frameNo = frameNo + 1
        if #atkFrames < frameNo then
            table.insert(atkFrames, {"dummy"})
        end
        table.insert(atkFrames[frameNo], "active")
    end
end

function framesToWikitext(atkFrames, isProjectile, projOffset)
    local out = ""
    if not isProjectile then
        for _, frame in ipairs(atkFrames) do
            out = out .. "<div class=\"frame-data-" .. frame[1] .. "\"></div>"
        end
    else
        for i, frame in ipairs(atkFrames) do
            out = out .. "<div style='display:inline-block'>"
            out = out .. "<div class=\"frame-data-" .. frame[1] .. "\" style='display:inline-block'></div>"
            if frame[2] ~= nil then
                out = out .. "<div class=\"frame-data-" .. frame[2] .. "\" style='display:block'></div>"
            end
            out = out .. "</div>"
            if i == projOffset then
                out = out .. "<div class=\"spawn-projectile\" style='height:28px; vertical-align:bottom'></div>"
            end
        end
    end
    return out
end

function drawFrame(frames, frameType)
  local builderString = ""

  if tonumber(frames) ~= nil then
    for i=1, tonumber(frames) do
      currentFrame = currentFrame + 1

      builderString = builderString .. "<div class=\"frame-data-" .. frameType
      if frcStart ~= nil and frcEnd ~= nil then
        if currentFrame <= tonumber(frcEnd) and currentFrame >= tonumber(frcStart) then
          builderString = builderString .. " frame-data-frc"
        end
      end
      builderString = builderString .. "\"></div>"
    end
  end

  wikitext = wikitext .. builderString
end

return p

-- local f=mw.getCurrentFrame():newChild{args={startup=2, active=2, recovery=3}}; mw.log(p.drawFrameData(f))
-- local f=mw.getCurrentFrame():newChild{args={startup=2, active=2, recovery=3, isProjectile=true, projOffset=1,projInactive=2, projActive=3}}; mw.log(p.drawFrameData(f))