User:LunarEcklipse/Templates/Sandbox

From Sea of Thieves Wiki
Jump to navigation Jump to search

Template:InfoboxVoyage

The Dark Relic Voyage to The Ancient Isles was one of the Mercenary Voyages in Sea of Thieves. Players could buy the voyage from Duke at the Tavern for 5 Doubloons from August 14th to September 11th, 2019.

The Voyage

This Mercenary Voyage was centred around two Bounty maps and two Treasure Maps to find mysterious Dark Relics in The Ancient Isles.

Chapters

Description

"The Order of Souls suspects that Dark Relics have been taken to The Ancient Isles."

Old

Patch Module Fix Steps

  1. Ensure incoming argument is a string with type().
    1. If not, convert it to one if possible or throw appropriate error/skip.
      1. All Lua variable types: nil, boolean, number, string, userdata, function, thread, table
      2. Do convert: number, boolean
      3. Don't convert all others, potential for undefined behaviour otherwise (they shouldn't even be able to get there in the first place).
    2. Ensure string is longer than zero.
  2. Perform pattern match for linebreaks with string.gsub() to create string array separated by newlines.
    1. Pattern match characters should be /r/n.
  3. For each substring, pattern match to determine number of asterisks (*) between string start and first alphanumeric character/non-asterisk special character.
  4. Compare number of asterisks to number of asterisks in last iteration, use for loop to nest or break additional <ul></ul> tags as needed.
    1. Start at 0 for first iteration.
  5. Declare li, use pattern match to put de-asterisked and de-leading whitespaced string into it, and close li.
    1. It's important that any UL tags in the substring are escaped, because it'll prevent breakages in case someone is being naughty and trying to break the template.
  6. If this is the last iteration (no more elements in array after this), escape all remaining uls according to current depth
  7. Repeat as necessary.

Patch Module Altered Code

local p = {} function p.main(frame) local args = require('Dev:Arguments').getArgs(frame) local raisebadargissue = false -- For error handling later. -- Cargo Query local a = mw.ext.cargo.query( "Versions", "_pageName,version,name,release_date", { where = 'version="' .. args[1] .. '"', ["no html"] = true } ) a = a[1] or { } local html = mw.html.create( "ul" ) :tag("li") -- Version + Date if a.version then html = html :tag("b") :wikitext( '[[' .. a.version .. ']] (' .. a.release_date .. ')' ) :done() :tag("ul") -- Detail notes sub-bullets for i=2,25 do -- #args should get the array length of args to prevent unncessecary loops. if args[i] ~= nil then local inc_arg = args[i] local arg_isvalid = false if type(inc_arg) == 'string' then -- If the argument is a string, it's valid. arg_isvalid = true elseif type(inc_arg) == 'number' then -- If the argument is a number, cast to string to make valid. inc_arg = tostring(inc_arg) arg_isvalid = true elseif type(inc_arg) == 'boolean' then -- If the argument is a boolean, then a little logic can convert it to a string easily. if inc_arg == true then inc_arg = 'true' else inc_arg = 'false' end arg_isvalid = true end -- If one of the remaining types gets in, then something is very wrong and that line should be skipped and probably flagged. if arg_isvalid then -- If the arg is valid then do the following. -- First, we separate the string by newline characters into an array via a gmatch. local arg_nsplit = {} for j in inc_arg:gmatch("([^\n]*)\n?") do if type(j) == 'string' then if #j ~= 0 then -- Don't do anything if the string is completely empty. -- Now, we use pattern matches to find the first alphanumeric character. local strstart, _ = string.find(j, '[^%*^%s]') -- Locates the first character that's not a whitespace or a * in the string. local asteriskdepth = 0 -- Predefine asterisk depth as 0. if strstart ~= nil then if strstart > 1 then -- If strstart = 1 then there is no asterisks to worry about in the string at all. local strslicefront = string.sub(j, 1, strstart - 1) -- We need to subtract 1 here otherwise it includes the first part of the string. This fetches a substring that is everything up to the first character. _, asteriskdepth = string.gsub(strslicefront, "%*", "") -- Returns the number of asterisks in the substring. end local strsliceback = string.sub(j, strstart, #j) -- This will return all of the test we want to actually display in the li if asteriskdepth > 0 then for k=1, asteriskdepth do html = html :tag('ul') end end if #strsliceback > 0 then -- One last check to make sure this part of the string isn't empty. html = html :tag('li') :wikitext( strsliceback ) :done() end if asteriskdepth > 0 then for k=1, asteriskdepth do html = html :done() end end end end end end else raisebadargissue = true end end end else html = html :tag('span') :css('color', 'red') :wikitext('Error: Patch version not found! An issue exists with the inputted patch name, please check that an existing version has been used.') end html = html:allDone() strout = tostring(html) if raisebadargissue then strout = strout .. '[[Category:Patches with arguments causing undefined behavior]]' -- Any page in this category needs to be looked at *thoroughly* because this shouldn't happen. Yes, this includes nil because it means that the argument somehow became nil after it was checked for nil the first time. end return strout end return p

Patch Module Original Code (In Case I Mess Up)

local p = {} function p.main(frame) local args = require('Dev:Arguments').getArgs(frame) -- Cargo Query local a = mw.ext.cargo.query( "Versions", "_pageName,version,name,release_date", { where = 'version="' .. args[1] .. '"', ["no html"] = true } ) a = a[1] or { } local html = mw.html.create( "ul" ) :tag("li") :tag("b") -- Version + Date if a.version then html = html :wikitext( '[[' .. a.version .. ']] (' .. a.release_date .. ')' ) :done() :tag('ul') -- Detail notes sub-bullets for i=2,25 do if args[i] ~= NIL then html = html :tag('li') :wikitext( args[i] ) end end else html = html :tag('span') :css('color', 'red') :wikitext('Error: Patch version not found! An issue exists with the inputted patch name, please check that an existing version has been used.') :done() end html = html:allDone() return tostring(html) end return p