| 🌟 | 現在、 鉄壁HSは通常HSと同じダメージになります。LMG及びDMR、チャージライフル、ハンマーポイント弾を除き、すべてのダメージ値が一致していることを確認しています。 |
モジュール:Utility/Library
ナビゲーションに移動
検索に移動
このモジュールについての説明文ページを モジュール:Utility/Library/doc に作成できます
local aw = {}
function aw.shallowCopy(obj)
local typename = type(obj)
local copy
if typename == 'table' then
copy = {}
for key, value in pairs(obj) do
copy[key] = value
end
else
copy = obj
end
return copy
end
function aw.getTableKeys(tbl)
local keyset = {}
for k, _ in pairs(tbl) do
keyset[#keyset + 1] = k
end
return keyset
end
function aw.getAsBoolean(strOrNumOrBool, defaultValue)
defaultValue = defaultValue or false
local typename = type(strOrNumOrBool)
if typename == 'boolean' then
return strOrNumOrBool
elseif typename == 'number' then
return strOrNumOrBool ~= 0
elseif typename == 'string' then
local str = string.lower(strOrNumOrBool)
return str == 'true' or str == 't' or str == '1'
else
return defaultValue
end
end
function aw.getAsNumber(strOrNum, defaultValue)
defaultValue = defaultValue or 0
local typename = type(strOrNum)
if typename == 'number' then
return strOrNum
elseif typename == 'string' then
return tonumber(strOrNum)
else
return defaultValue
end
end
function aw.escapeHtml(html)
local result, _ = html
:gsub('&', '&')
:gsub('"', '"')
return result
end
function aw.round(num)
return math.floor(tonumber(string.format("%.4f", num)) + 0.5)
end
function aw.roundover(num)
return math.ceil(tonumber(string.format("%.4f", num)) - 0.5)
end
function aw.selectiveRound(num, useRound)
if useRound or false then
return aw.round(num)
else
return aw.roundover(num)
end
end
-- 型チェック
function aw.isNumber(num)
return num and type(num) == 'number'
end
function aw.isNumberAndGreaterThanZero(num)
return isNumber(num) and num > 0
end
function aw.isNumberAndGreaterThanOrEqualToZero(num)
return isNumber(num) and num >= 0
end
-- 数字にカンマをつける関数
function aw.comma(amount)
local formatted = amount
while true do
formatted, k = string.gsub(formatted, "^(-?%d+)(%d%d%d)", '%1,%2')
if k == 0 then
break
end
end
return formatted
end
-- 一部分に同じ要素をもつ配列をテキスト化する関数
local function toRepeatingString(cache, count)
if count > 1 then
return cache .. '×' .. count
else
return cache
end
end
function aw.stringifyRepeatingArray(array, separator)
local cache = array[1]
local count = 0
local output = nil
for _, damage in ipairs(array) do
if cache == damage then
count = count + 1
else
local text = toRepeatingString(cache, count)
if output ~= nil then
output = output .. separator .. text
else
output = text
end
cache = damage
count = 1
end
end
local text = toRepeatingString(cache, count)
if output ~= nil then
output = output .. separator .. text
else
output = text
end
return output
end
return aw