102 lines
3.5 KiB
Plaintext
102 lines
3.5 KiB
Plaintext
-- 本地化读取工具
|
||
local Localization = {}
|
||
|
||
--> Services
|
||
local ReplicatedStorage = game:GetService("ReplicatedStorage")
|
||
local LocalizationService = game:GetService("LocalizationService")
|
||
|
||
--> Modules
|
||
local Utils = require(ReplicatedStorage.Tools.Utils)
|
||
|
||
--> Json
|
||
local JsonLanguage_En_US = require(ReplicatedStorage.Json.Language_En_US)
|
||
local JsonLanguage_Zh_CN = require(ReplicatedStorage.Json.Language_Zh_CN)
|
||
local JsonImage_En_US = require(ReplicatedStorage.Json.Image_En_US)
|
||
local JsonImage_Zh_CN = require(ReplicatedStorage.Json.Image_Zh_CN)
|
||
|
||
local JsonParam = require(ReplicatedStorage.Json.Param)
|
||
|
||
--> Variables
|
||
local LocalPlayer = game.Players.LocalPlayer
|
||
local SystemLocaleId = LocalizationService.SystemLocaleId
|
||
|
||
--> Color
|
||
local QUALITY_COLOR = {
|
||
[1] = Color3.fromRGB(255, 255, 255), -- 白色
|
||
[2] = Color3.fromRGB(0, 255, 0), -- 绿色
|
||
[3] = Color3.fromRGB(0, 150, 255), -- 蓝色
|
||
[4] = Color3.fromRGB(150, 0, 255), -- 紫色
|
||
[5] = Color3.fromRGB(255, 150, 0), -- 橙色
|
||
[6] = Color3.fromRGB(255, 0, 0), -- 红色
|
||
[7] = Color3.fromRGB(255, 215, 0), -- 金色
|
||
[8] = Color3.fromRGB(255, 0, 255), -- 粉色
|
||
}
|
||
|
||
-- 获取本地Json文件
|
||
function Localization:GetLocalizationJson()
|
||
if SystemLocaleId == "zh-CN" then
|
||
return JsonLanguage_Zh_CN, JsonImage_Zh_CN
|
||
else
|
||
return JsonLanguage_En_US, JsonImage_En_US
|
||
end
|
||
end
|
||
|
||
local JsonLanguage, JsonImage = Localization:GetLocalizationJson()
|
||
|
||
-- 获取文本Id数据
|
||
function Localization:GetLanguageData(Id: number)
|
||
if not Id then return end
|
||
local data = Utils:GetIdDataFromJson(JsonLanguage, Id)
|
||
if not data then return "" end
|
||
return data.text
|
||
end
|
||
|
||
-- 获取图片Id数据
|
||
function Localization:GetImageData(Id: number)
|
||
if not Id then return "" end
|
||
local data = Utils:GetIdDataFromJson(JsonImage, Id)
|
||
if not data then return "" end
|
||
return data.sourceId
|
||
end
|
||
|
||
-- 获取装备品质描述
|
||
function Localization:GetEquipmentQualityDesc(Quality: number)
|
||
local qualityData = Utils:GetSpecialKeyDataFromJson(JsonParam, "key", "quality_show")
|
||
if not qualityData then return "" end
|
||
local languageData = Utils:GetSpecialKeyDataFromJson(JsonLanguage, "id", qualityData.intArray[Quality])
|
||
if not languageData then return "" end
|
||
local language = languageData.text
|
||
return language
|
||
end
|
||
|
||
-- 将Color3转换为十六进制字符串
|
||
local function Color3ToHex(color: Color3): string
|
||
local r = math.floor(color.R * 255)
|
||
local g = math.floor(color.G * 255)
|
||
local b = math.floor(color.B * 255)
|
||
return string.format("#%02X%02X%02X", r, g, b)
|
||
end
|
||
|
||
-- 根据quality获取带颜色包装的文本
|
||
function Localization:GetColoredTextByQuality(quality: number, text: string): string
|
||
if not quality or not text then return text or "" end
|
||
|
||
local color = QUALITY_COLOR[quality]
|
||
if not color then return text end
|
||
|
||
local hexColor = Color3ToHex(color)
|
||
return string.format('<font color="%s">%s</font>', hexColor, text)
|
||
end
|
||
|
||
-- 根据quality获取装备品质描述(带颜色)
|
||
function Localization:GetColoredEquipmentQualityDesc(Quality: number): string
|
||
local qualityData = Utils:GetSpecialKeyDataFromJson(JsonParam, "key", "quality_show")
|
||
if not qualityData then return "" end
|
||
local languageData = Utils:GetSpecialKeyDataFromJson(JsonLanguage, "id", qualityData.intArray[Quality])
|
||
if not languageData then return "" end
|
||
local language = languageData.text
|
||
|
||
return self:GetColoredTextByQuality(Quality, language)
|
||
end
|
||
|
||
return Localization |