Changes

Jump to navigation Jump to search
disable beta fields (beta no longer in progress)
Line 1: Line 1:  
local p = {}
 
local p = {}
 
local private = {}
 
local private = {}
 +
 +
-- whether to handle Stardew Valley beta fields (don't forget to comment or uncomment the beta fields in /doc)
 +
local enableBeta = false
    
--##########
 
--##########
Line 18: 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
    
--- Render a mod row in the SMAPI compatibility table.
 
--- Render a mod row in the SMAPI compatibility table.
 
-- @param frame The arguments passed to the script.
 
-- @param frame The arguments passed to the script.
-- @test mw.log(p.entry({ args = { name="Lookup Anything, LookupAnything", author="Pathoschild, Pathos", id="Pathoschild.LookupAnything, LookupAnything", ["nexus id"]="541", ["chucklefish id"]="4250", ["github"]="Pathoschild/StardewMods", warnings="warning A, warning B" }}))
+
-- @test mw.log(p.entry({ args = { name="Content Patcher, ContentPatcher", author="Pathoschild, Pathos", id="Pathoschild.ContentPatcher, ContentPatcher", nexus="1915", chucklefish="4250", curse="309243,content-patcher", github="Pathoschild/StardewMods", warnings="warning A, warning B" }}))
 
function p.entry(frame)
 
function p.entry(frame)
 
   -- read input args
 
   -- read input args
Line 28: Line 62:  
   local authors    = private.parseCommaDelimited(frame.args["author"] or '')
 
   local authors    = private.parseCommaDelimited(frame.args["author"] or '')
 
   local ids        = private.parseCommaDelimited(frame.args["id"] or '')
 
   local ids        = private.parseCommaDelimited(frame.args["id"] or '')
   local nexusId    = private.emptyToNil(frame.args["nexus id"])
+
   local nexusId    = private.emptyToNil(frame.args["nexus"])
 
   local github    = private.emptyToNil(frame.args["github"])
 
   local github    = private.emptyToNil(frame.args["github"])
 
   local summary    = private.emptyToNil(frame.args["summary"])
 
   local summary    = private.emptyToNil(frame.args["summary"])
Line 36: Line 70:  
   local unofficialVersion = private.emptyToNil(frame.args["unofficial version"])
 
   local unofficialVersion = private.emptyToNil(frame.args["unofficial version"])
 
   local unofficialUrl    = private.emptyToNil(frame.args["unofficial url"])
 
   local unofficialUrl    = private.emptyToNil(frame.args["unofficial url"])
   local chucklefishId  = private.emptyToNil(frame.args["chucklefish id"])
+
   local chucklefishId  = private.emptyToNil(frame.args["chucklefish"])
   local curseforgeId  = private.emptyToNil(frame.args["curseforge id"])
+
   local curseforgeId  = private.emptyToNil(frame.args["curse"])
  local curseforgeKey  = private.emptyToNil(frame.args["curseforge key"])
+
   local moddropId      = private.emptyToNil(frame.args["moddrop"])
   local moddropId      = private.emptyToNil(frame.args["moddrop id"])
   
   local customUrl      = private.emptyToNil(frame.args["url"])
 
   local customUrl      = private.emptyToNil(frame.args["url"])
 
   local customSource  = private.emptyToNil(frame.args["source"])
 
   local customSource  = private.emptyToNil(frame.args["source"])
Line 47: Line 80:  
   local contentPackFor = private.emptyToNil(frame.args["content pack for"])
 
   local contentPackFor = private.emptyToNil(frame.args["content pack for"])
   −
   local betaSummary = private.emptyToNil(frame.args["beta summary"])
+
   local betaSummary = nil
  local betaBrokeIn = private.emptyToNil(frame.args["beta broke in"])
+
  local betaBrokeIn = nil
  local betaStatus  = private.emptyToNil(frame.args["beta status"])
+
  local betaStatus  = nil
  local betaUnofficialVersion = private.emptyToNil(frame.args["beta unofficial version"])
+
  local betaUnofficialVersion = nil
  local betaUnofficialUrl    = private.emptyToNil(frame.args["beta unofficial url"])
+
  local betaUnofficialUrl    = nil
 +
  if enableBeta then
 +
    betaSummary = private.emptyToNil(frame.args["beta summary"])
 +
    betaBrokeIn = private.emptyToNil(frame.args["beta broke in"])
 +
    betaStatus  = private.emptyToNil(frame.args["beta status"])
 +
    betaUnofficialVersion = private.emptyToNil(frame.args["beta unofficial version"])
 +
    betaUnofficialUrl    = private.emptyToNil(frame.args["beta unofficial url"])
 +
  end
    
   -- get source url
 
   -- get source url
Line 63: Line 103:  
   local compat = private.getCompatInfo(status, summary, brokeIn, unofficialVersion, unofficialUrl, hasSource)
 
   local compat = private.getCompatInfo(status, summary, brokeIn, unofficialVersion, unofficialUrl, hasSource)
 
   local betaCompat = nil
 
   local betaCompat = nil
   if betaStatus or betaBrokeIn or betaUnofficialUrl or betaUnofficialVersion then
+
   if enableBeta and (betaStatus or betaBrokeIn or betaUnofficialUrl or betaUnofficialVersion) then
 
     betaCompat = private.getCompatInfo(betaStatus, betaSummary, betaBrokeIn, betaUnofficialVersion, betaUnofficialUrl, hasSource)
 
     betaCompat = private.getCompatInfo(betaStatus, betaSummary, betaBrokeIn, betaUnofficialVersion, betaUnofficialUrl, hasSource)
 
   end
 
   end
Line 74: Line 114:  
     url = "https://www.moddrop.com/stardew-valley/mods/" .. mw.uri.encode(moddropId, "PATH")
 
     url = "https://www.moddrop.com/stardew-valley/mods/" .. mw.uri.encode(moddropId, "PATH")
 
   elseif curseforgeId then
 
   elseif curseforgeId then
     url = "https://www.curseforge.com/stardewvalley/mods/" .. mw.uri.encode(curseforgeKey, "PATH")
+
     url = "https://www.curseforge.com/projects/" .. mw.uri.encode(curseforgeId, "PATH")
 
   elseif chucklefishId then
 
   elseif chucklefishId then
 
     url = "https://community.playstarbound.com/resources/" .. mw.uri.encode(chucklefishId, "PATH")
 
     url = "https://community.playstarbound.com/resources/" .. mw.uri.encode(chucklefishId, "PATH")
   else
+
   elseif customUrl then
 
     url = customUrl
 
     url = customUrl
 +
  elseif hasSource then
 +
    url = sourceUrl
 
   end
 
   end
   Line 90: Line 132:  
   row:attr("data-cf-id", chucklefishId)
 
   row:attr("data-cf-id", chucklefishId)
 
   row:attr("data-curseforge-id", curseforgeId)
 
   row:attr("data-curseforge-id", curseforgeId)
  row:attr("data-curseforge-key", curseforgeKey)
   
   row:attr("data-moddrop-id", moddropId)
 
   row:attr("data-moddrop-id", moddropId)
 
   row:attr("data-nexus-id", nexusId)
 
   row:attr("data-nexus-id", nexusId)
Line 101: Line 142:  
   row:attr("data-unofficial-version", compat.unofficialVersion)
 
   row:attr("data-unofficial-version", compat.unofficialVersion)
 
   row:attr("data-unofficial-url", compat.unofficialUrl)
 
   row:attr("data-unofficial-url", compat.unofficialUrl)
   row:attr("data-beta-status", betaCompat and betaCompat.status)
+
   if enableBeta then
  row:attr("data-beta-summary", betaCompat and betaCompat.summary)
+
    row:attr("data-beta-status", betaCompat and betaCompat.status)
  row:attr("data-beta-broke-in", betaCompat and betaCompat.brokeIn)
+
    row:attr("data-beta-summary", betaCompat and betaCompat.summary)
  row:attr("data-beta-unofficial-version", betaCompat and betaCompat.unofficialVersion)
+
    row:attr("data-beta-broke-in", betaCompat and betaCompat.brokeIn)
  row:attr("data-beta-unofficial-url", betaCompat and betaCompat.unofficialUrl)
+
    row:attr("data-beta-unofficial-version", betaCompat and betaCompat.unofficialVersion)
 +
    row:attr("data-beta-unofficial-url", betaCompat and betaCompat.unofficialUrl)
 +
  end
 
   row:attr("data-warnings", private.emptyToNil(table.concat(warnings, ",")))
 
   row:attr("data-warnings", private.emptyToNil(table.concat(warnings, ",")))
 
   row:attr("data-content-pack-for", contentPackFor)
 
   row:attr("data-content-pack-for", contentPackFor)
Line 172: Line 215:  
     if betaCompat ~= nil then
 
     if betaCompat ~= nil then
 
       field:wikitext("<br />")
 
       field:wikitext("<br />")
       field:wikitext("'''SDV 1.5.5 beta only:''' <span class=\"mod-beta-summary\">" .. betaCompat.summaryIcon .. " " .. betaCompat.summary .. "</span>")
+
       field:wikitext("'''SDV 1.6 beta only:''' <span class=\"mod-beta-summary\">" .. betaCompat.summaryIcon .. " " .. betaCompat.summary .. "</span>")
 
       if betaCompat.status == "optional" then
 
       if betaCompat.status == "optional" then
 
         field:wikitext("<ref name=\"optional-update\" />")
 
         field:wikitext("<ref name=\"optional-update\" />")
Line 236: Line 279:  
     if #ids == 0 then
 
     if #ids == 0 then
 
       field:wikitext("[⚠ no id] ")
 
       field:wikitext("[⚠ no id] ")
    end
  −
    if (not curseforgeId) ~= (not curseforgeKey) then
  −
      field:wikitext("<abbr title=\"The mod data is invalid: can't specify Curseforge key or ID without the other.\">[⚠ invalid data]</abbr>")
   
     end
 
     end
   Line 327: 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,404

edits

Navigation menu