🌟現在、鉄壁 鉄壁ヘッドショットには対応済みです。
鉄壁HSは通常HSと同じダメージになります。LMG及びDMR、チャージライフル、ハンマーポイント弾を除き、すべてのダメージ値が一致していることを確認しています。

「モジュール:Utility/Library」の版間の差分

提供:Apex Data
ナビゲーションに移動 検索に移動
(xを超過またはx以上の数値型であるかを判定する関数を追加)
(文字列末尾一致関数 stringends の追加)
98行目: 98行目:


-- 文字列ライブラリー
-- 文字列ライブラリー
function aw.stringstarts(str, start)
function aw.stringstarts(str, target)
return string.sub(str, 1, string.len(start)) == start
return string.sub(str, 1, string.len(target)) == target
end
 
function aw.stringends(str, target)
return target == '' or string.sub(str, -string.len(target)) == target
end
end



2021年8月16日 (月) 11:28時点における版

このモジュールについての説明文ページを モジュール: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)
	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'
	elseif defaultValue == nil then
		return false
	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("%.6f", num)) + 0.5)
end

function aw.roundx(num, digits)
	local shift = math.pow(10, digits)
	return aw.round(shift * num) / shift
end

function aw.roundover(num)
	return math.ceil(tonumber(string.format("%.6f", num)) - 0.5)
end

function aw.clamp(num, low, high)
	return math.min(math.max(num, low), high)
end

-- 型チェック
function aw.isNumber(num)
	return type(num) == 'number'
end

function aw.isNumberAndGreaterThanZero(num)
	return aw.isNumber(num) and num > 0
end

function aw.isNumberAndGreaterThanOrEqualToZero(num)
	return aw.isNumber(num) and num >= 0
end

function aw.isNumberAndGreaterThanX(num, x)
	return aw.isNumber(num) and num > x
end

function aw.isNumberAndGreaterThanOrEqualToX(num, x)
	return aw.isNumber(num) and num >= x
end

-- 文字列ライブラリー
function aw.stringstarts(str, target)
	return string.sub(str, 1, string.len(target)) == target
end

function aw.stringends(str, target)
	return target == '' or string.sub(str, -string.len(target)) == target
end

function aw.getEmphasizableTextFunc(mainFormat, prefixFormat, suffixFormat)
	prefixFormat = prefixFormat or '%s'
	suffixFormat = suffixFormat or '%s'
	
	local psFormat = string.format('%s%s%s', prefixFormat, mainFormat, suffixFormat)
	local pFormat  = string.format('%s%s', prefixFormat, mainFormat)
	local sFormat  = string.format('%s%s', mainFormat, suffixFormat)
	return function(longname, shortname)
		local shortableName = string.gsub(
			longname,
			string.format('(.*)%s(.*)', string.gsub(shortname, '-', '%%-')),
			function(prefix, suffix)
				if prefix ~= '' then
					if suffix ~= '' then
					return string.format(psFormat, prefix, shortname, suffix)
				else
					return string.format(pFormat, prefix, shortname)
					end
				else
					if suffix ~= '' then
						return string.format(sFormat, shortname, suffix)
					else
						return string.format(mainFormat, shortname)
					end
				end
			end)
		return shortableName
	end
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