跳至內容
切換側欄
搜尋
建立帳號
登入
個人工具
建立帳號
登入
用於已登出編輯者的頁面
了解更多
貢獻
討論
導覽
首頁
近期變更
隨機頁面
MediaWiki說明
工具
連結至此的頁面
相關變更
特殊頁面
頁面資訊
正在編輯「
模組:滿意DocsUtils
」
模組
討論
English
閱讀
編輯原始碼
檢視歷史
更多
閱讀
編輯原始碼
檢視歷史
警告:
您尚未登入。 若您進行任何的編輯您的 IP 位址將會被公開。 若您
登入
或
建立帳號
,您的編輯將會以您的使用者名稱標示,並能擁有另外的益處。
防垃圾訊息檢查用。
請勿
填寫此欄位!
itemsJSON = mw.loadJsonData('滿意工廠模板:DocsItems.json') buildingsJSON = mw.loadJsonData('滿意工廠模板:DocsBuildings.json') recipesJSON = mw.loadJsonData('滿意工廠模板:DocsRecipes.json') -- Used for localization, used in infoboxes, recipe tables, and other templates if needed. loc = { units = { sec = " sec", m = " m", m2 = " m<sup>2</sup>", m3 = " m<sup>3</sup>", pmin = " / min", mj = " MJ", mw = " MW", kmh = " km/h" }, numbers = { decimalsep = ".", thousandsep = ",", }, branches = { stable = "Stable", experimental = "Experimental", ficsmas = "FICSMAS" }, filePage = "File:" } -- Get the length of an array, because Lua's built-in length function does not work for JSON data. -- - T - table function arrayLength(T) local l = 0 for _ in pairs(T) do l = l+1 end return l end -- Format a number (thousands separator, decimal separator) -- - n - number - number to format function formatNumber(n) local integerPart, decimalPart = string.format("%.5f", n):match("([^%.]+)%.?(.*)") decimalPart = decimalPart:gsub("0*$", "") local returnValue = ((string.reverse(integerPart):gsub("(%d%d%d)", "%1" .. loc.numbers.thousandsep):reverse():gsub("^%s*(.-)%s*$", "%1")) .. (#decimalPart > 0 and loc.numbers.decimalsep .. decimalPart or "")):gsub("^,*(.-),*$", "%1") return returnValue end -- Retrieve the same parameter from provided stable and experimental items, returns a table with both values -- - parameter - string - parameter name to retrieve -- - stableItem - table - stable item to retrieve the parameter from -- - experimentalItem - table - experimental item to retrieve the parameter from function getBranchValues(parameter, stableItem, experimentalItem) return {stable = stableItem ~= nil and stableItem[parameter] or nil, experimental = experimentalItem ~= nil and experimentalItem[parameter] or nil} end -- Format the differences between both branches using {{EA}}/{{EX}} templates -- - values - table - table with both values -- - singleBranch - boolean - if true and the value is only in one branch, it will be formatted with {{EA}}/{{EX}}, otherwise it will not -- - nowiki - boolean - if true, each value is wrapped in <nowiki></nowiki> function formatBranchDiff(values, singleBranch, nowiki) local branchValues = {} branchValues.stable = values.stable branchValues.experimental = values.experimental if (not branchValues.stable or branchValues.stable == 0) and (not branchValues.experimental or branchValues.experimental == 0) then return "" end if type(branchValues.stable) == "number" then branchValues.stable = formatNumber(branchValues.stable) end if type(branchValues.experimental) == "number" then branchValues.experimental = formatNumber(branchValues.experimental) end if nowiki then if branchValues.stable then branchValues.stable = "<nowiki>" .. branchValues.stable .. "</nowiki>" end if branchValues.experimental then branchValues.experimental = "<nowiki>" .. branchValues.experimental .. "</nowiki>" end end if branchValues.stable == branchValues.experimental then return branchValues.stable elseif branchValues.stable ~= nil and branchValues.experimental == nil then return singleBranch and ("{{EA|" .. branchValues.stable .. "}}") or branchValues.stable elseif branchValues.stable == nil and branchValues.experimental ~= nil then return singleBranch and ("{{EX|" .. branchValues.experimental .. "}}") or branchValues.experimental else return "{{EA|" .. branchValues.stable .. "}} ({{EX|" .. branchValues.experimental .. "}})" end end -- Resolve a className to a name for both branches -- - className - string - className to resolve -- - fileJSON - table - JSON file to search in function getNameFromClassName(className, fileJSON) local result = {} if fileJSON[className] ~= nil then for _, it in pairs(fileJSON[className]) do if it.stable then result.stable = it.name end if it.experimental then result.experimental = it.name end end end return result end -- Get object data from a file from the classname for both branches -- - className - string - className to resolve -- - fileJSON - table - JSON file to search in function getObjectFromClassName(className, fileJSON) local result = {} if fileJSON[className] ~= nil then for _, it in pairs(fileJSON[className]) do if it.stable then result.stable = it end if it.experimental then result.experimental = it end end end return result end -- Get a link (EA>EX) and name (branchDiff formatted) for a target -- - target - string - className to resolve -- - stable - boolean - whether to use stable branch name -- - experimental - boolean - whether to use experimental branch name -- - singleBranch - boolean - whether to format the name with {{EA}}/{{EX}} if available only on one branch function getLinkAndName(target, stable, experimental, singleBranch) local targetNames local targetLink local targetName -- resolve item or building name targetNames = getNameFromClassName(target, itemsJSON) if targetNames.stable == nil and targetNames.stable == nil then targetNames = getNameFromClassName(target, buildingsJSON) end if stable and experimental then targetName = formatBranchDiff(targetNames, singleBranch) else targetName = experimental and targetNames.experimental or targetNames.stable targetName = singleBranch and ("{{" .. (experimental and "EX" or "EA") .. "|" .. targetName .. "}}") or targetName end targetLink = targetNames.stable ~= nil and targetNames.stable or targetNames.experimental -- should never occur if targetName == nil or targetLink == nil then targetName = target targetLink = target end return targetLink, targetName end -- Generate an ItemLink for a target -- - target - string - className to resolve -- - stable - boolean - whether to use stable branch name -- - experimental - boolean - whether to use experimental branch name -- - singleBranch - boolean - whether to format the name with {{EA}}/{{EX}} if available only on one branch function generateItemLink(className, stable, experimental, singleBranch) local itemLink, itemName = getLinkAndName(className, stable, experimental, singleBranch) return mw.getCurrentFrame():expandTemplate{title="ItemLink", args={itemLink, itemName}} end
摘要:
請注意,所有於華麥百科所做的貢獻會依據CC BY-SA(創用CC 姓名標示─相同方式分享)授權條款發佈(詳情請見
說明:版權
)。若您不希望您的著作被任意修改與散佈,請勿在此發表文章。
您同時向我們保證在此的著作內容是您自行撰寫,或是取自不受版權保護的公開領域或自由資源。
請勿在未經授權的情況下發表文章!
取消
編輯說明
(在新視窗開啟)
此頁面使用了以下模板:
模組:滿意DocsUtils/doc
(
編輯
)