Changes

Jump to navigation Jump to search
disable beta fields (beta no longer in progress)
Line 3: Line 3:     
-- whether to handle Stardew Valley beta fields (don't forget to comment or uncomment the beta fields in /doc)
 
-- whether to handle Stardew Valley beta fields (don't forget to comment or uncomment the beta fields in /doc)
local enableBeta = true
+
local enableBeta = false
    
--##########
 
--##########
Line 21: Line 21:  
function p.footer()
 
function p.footer()
 
   return '</table>'
 
   return '</table>'
 +
end
 +
 +
--- Render the SMAPI compatibility table based on JSON input.
 +
-- @param frame The arguments passed to the script.
 +
-- @test mw.log(p.table({ args = { [1]='[  { "name":  "24h Clock", "author": "Lajna", // test\n"id":  "Lajna.24hClock", "nexus": 1695, "github": "LajnaLegenden/Stardew_Valley_Mods", "brokeIn": "SMAPI 3.0", "unofficial": [ "1.0.1-unofficial.1-pathoschild", "https://community.playstarbound.com/threads/updating-mods-for-stardew-valley-1-3.142524/page-76#post-3342641" ] } ]' }}))
 +
function p.table(frame)
 +
  -- parse data
 +
  local json = string.gsub(frame.args[1], '%s*//[^"\n]+', '')
 +
  local data = mw.text.jsonDecode(json, mw.text.JSON_TRY_FIXING)
 +
 +
  -- start table
 +
  local table = mw.html.create("table")
 +
  table:addClass("wikitable sortable plainlinks")
 +
  table:attr("id", "mod-list")
 +
  table:wikitext("<tr><th>mod name</th><th>author</th><th><abbr title=\"This only shows whether a mod is *compatible*; it may have bugs unrelated to SMAPI compatibility.\">compatibility</abbr></th><th>broke in</th><th>source</th><th>&nbsp;</th></tr>")
 +
 +
  -- add mod rows
 +
  for index,mod in pairs(data) do
 +
    -- temporarily passthrough args to avoid duplicating code until we migrate fully to JSON
 +
    -- (We need tostring on numeric fields since the previous code doesn't support numbers)
 +
    mod.chucklefish = private.toSafeString(mod.chucklefish)
 +
    mod.curse = private.toSafeString(mod.curse)
 +
    mod.moddrop = private.toSafeString(mod.moddrop)
 +
    mod.nexus = private.toSafeString(mod.nexus)
 +
 +
    local row = p.entry({ args = mod })
 +
    table:node(row)
 +
  end
 +
 +
  -- return output
 +
  return private.style(frame) .. tostring(table)
 
end
 
end
   Line 55: Line 86:  
   local betaUnofficialUrl    = nil
 
   local betaUnofficialUrl    = nil
 
   if enableBeta then
 
   if enableBeta then
     local betaSummary = private.emptyToNil(frame.args["beta summary"])
+
     betaSummary = private.emptyToNil(frame.args["beta summary"])
     local betaBrokeIn = private.emptyToNil(frame.args["beta broke in"])
+
     betaBrokeIn = private.emptyToNil(frame.args["beta broke in"])
     local betaStatus  = private.emptyToNil(frame.args["beta status"])
+
     betaStatus  = private.emptyToNil(frame.args["beta status"])
     local betaUnofficialVersion = private.emptyToNil(frame.args["beta unofficial version"])
+
     betaUnofficialVersion = private.emptyToNil(frame.args["beta unofficial version"])
     local betaUnofficialUrl    = private.emptyToNil(frame.args["beta unofficial url"])
+
     betaUnofficialUrl    = private.emptyToNil(frame.args["beta unofficial url"])
 
   end
 
   end
   Line 336: Line 367:  
     unofficialUrl = unofficialUrl
 
     unofficialUrl = unofficialUrl
 
   }
 
   }
 +
end
 +
 +
-- Call tostring() on the value if it's not nil, else return the value as-is.
 +
-- @param value The value to format.
 +
function private.toSafeString(value)
 +
  if value then
 +
    return tostring(value)
 +
  else
 +
    return nil
 +
  end
 
end
 
end
    
-- Get a nil value if the specified value is an empty string, else return the value unchanged.
 
-- Get a nil value if the specified value is an empty string, else return the value unchanged.
-- @param value The string to check.
+
-- @param value The string to format.
 
function private.emptyToNil(value)
 
function private.emptyToNil(value)
 
   if value ~= "" then
 
   if value ~= "" then
translators
8,437

edits

Navigation menu