209 lines
5.2 KiB
Lua
209 lines
5.2 KiB
Lua
local modInfo = Mod.getInfo('smc__core__formspec')
|
||
local require = modInfo.require
|
||
|
||
---@type AdminListUI
|
||
local AdminListUI = Mod.getInfo('smc__ui__admin_list').require('AdminListUI')
|
||
|
||
core.register_chatcommand('list', {
|
||
privs = {server = true},
|
||
|
||
func = function(name, param)
|
||
local player = core.get_player_by_name(name)
|
||
|
||
AdminListUI:showForm(name)
|
||
|
||
return true, ''
|
||
end
|
||
})
|
||
|
||
core.register_chatcommand('set_param2', {
|
||
privs = {server = true},
|
||
|
||
func = function(name, param)
|
||
local player = core.get_player_by_name(name)
|
||
if player == nil then
|
||
return
|
||
end
|
||
local pos = player:get_pos() - vector.new(0, 0.5, 0)
|
||
pos = pos:round()
|
||
|
||
local node = core.get_node(pos)
|
||
node.param2 = param
|
||
core.set_node(pos, node)
|
||
|
||
return true, ''
|
||
end
|
||
})
|
||
|
||
AdminListUI:registerOnFormFieldActionMatch('%S+::item_button',function(player, fieldName, fieldValue)
|
||
---@type ItemStackString?
|
||
local stack = string.match(fieldName, '(%S+)::item_button')
|
||
|
||
if stack == nil then
|
||
return
|
||
end
|
||
|
||
local playerName = player:get_player_name()
|
||
AdminListUI:setContex(playerName, 'select_item', stack)
|
||
|
||
AdminListUI:showForm(playerName)
|
||
end)
|
||
|
||
AdminListUI:registerOnFormFieldAction('admin_commands:list_add_item', function(player, fieldName, fieldValue)
|
||
---@type InvRef
|
||
local inv = player:get_inventory()
|
||
|
||
local playerName = player:get_player_name()
|
||
local stack = AdminListUI:getContex(playerName, 'select_item')
|
||
stack = ItemStack(stack)
|
||
stack:set_count(fieldValue)
|
||
|
||
if inv:room_for_item('main', stack) then
|
||
inv:add_item('main', stack)
|
||
end
|
||
end)
|
||
|
||
core.register_on_joinplayer(function(player, last_login)
|
||
player:set_sky({
|
||
sky_color = {
|
||
day_sky = '#b5e8ff',
|
||
day_horizon = '#80bbe2',
|
||
},
|
||
type = 'regular',
|
||
})
|
||
|
||
player:set_lighting({
|
||
shadows = { intensity = 0.33 },
|
||
volumetric_light = { strength = 0.45 },
|
||
exposure = {
|
||
luminance_min = -3.5,
|
||
luminance_max = -2.5,
|
||
exposure_correction = 0.35,
|
||
speed_dark_bright = 1500,
|
||
speed_bright_dark = 700,
|
||
},
|
||
saturation = 1.0,
|
||
})
|
||
|
||
end)
|
||
|
||
-- Keys indicating the languages for which localization presence is checked.
|
||
local LANG_CODES = {'en', 'ru'}
|
||
|
||
-- Number of missed localizations.
|
||
local missedLocaleCount = 0
|
||
|
||
local function checkLocale(strTranslate, langCodes)
|
||
local str = core.strip_escapes(strTranslate)
|
||
|
||
for _, langCode in ipairs(langCodes or LANG_CODES) do
|
||
if core.strip_escapes(core.get_translated_string(langCode, strTranslate)) == str then
|
||
missedLocaleCount = missedLocaleCount + 1
|
||
Logger.warningLog('Localization missing[%s][%s]. String: `%s`.', missedLocaleCount, langCode, str)
|
||
end
|
||
end
|
||
end
|
||
|
||
core.register_chatcommand('get_missing_locale', {
|
||
privs = {server = true},
|
||
description = '{short_mod_name:string?, lang_codes:string[]?}',
|
||
func = function(name, paramsStr)
|
||
local params = core.deserialize(('return '..paramsStr) or '{}')
|
||
|
||
if params == nil then
|
||
return false
|
||
end
|
||
|
||
local shortModName = params.short_mod_name
|
||
local langCodes = params.lang_codes
|
||
|
||
if shortModName ~= nil and type(shortModName) ~= 'string' then
|
||
return false, 'Incorrect mod name'
|
||
end
|
||
|
||
if langCodes ~= nil and type(langCodes) ~= 'table' then
|
||
return false, 'Incorrect lang code'
|
||
end
|
||
|
||
local items
|
||
if shortModName == '' or shortModName == nil then
|
||
items = Smc.getRegisteredItems()
|
||
else
|
||
items = Smc.getRegisteredItemsByMod(shortModName)
|
||
end
|
||
|
||
if items == nil then
|
||
return false, 'There are no items registered for this mod (or the entire game)'
|
||
end
|
||
|
||
---@param name string
|
||
---@param item Item
|
||
for name, item in pairs(items) do
|
||
local itemSettings = item.itemDef.settings
|
||
local title, desc = itemSettings._title, itemSettings._description
|
||
|
||
checkLocale(title, langCodes)
|
||
checkLocale(desc, langCodes)
|
||
end
|
||
|
||
return true, ''
|
||
end
|
||
})
|
||
|
||
core.register_chatcommand('create_locale', {
|
||
privs = { server = true },
|
||
description = '<short_mod_name> <lang_code>',
|
||
func = function(name, params)
|
||
local shortModName, langCode = string.match(params, '(%S+) (%S+)')
|
||
|
||
if shortModName == nil or shortModName == '' then
|
||
return false, 'Incorrect mod name!'
|
||
end
|
||
|
||
if langCode == nil or langCode == '' or not table.contains(LANG_CODES, langCode)then
|
||
return false, 'Incorrect lang code!'
|
||
end
|
||
|
||
local items = Smc.getRegisteredItemsListByMod(shortModName)
|
||
|
||
if items == nil then
|
||
return false, 'There are no items registered for this mod (or the entire game)'
|
||
end
|
||
|
||
local filePath = core.get_worldpath()..('/%s.%s.tr'):format(shortModName, langCode)
|
||
local file, err = io.open(filePath, 'w')
|
||
|
||
if not file then
|
||
return false, 'Cannot open file: '..err
|
||
end
|
||
|
||
file:write('# textdomain: '..shortModName..'\n\n')
|
||
|
||
for _, item in ipairs(items) do
|
||
local itemSettings = item.itemDef.settings
|
||
local name = string.match(itemSettings.name, ('%S+:(%S+)'))
|
||
local title = core.strip_colors(core.get_translated_string(langCode, itemSettings._title))
|
||
local desc = core.strip_colors(core.get_translated_string(langCode, itemSettings._description))
|
||
|
||
if title ~= name..'-title' then
|
||
title = '[locale already exists]'
|
||
else
|
||
title = ''
|
||
end
|
||
|
||
if desc ~= name..'-desc' then
|
||
desc = '[locale already exists]'
|
||
else
|
||
desc = ''
|
||
end
|
||
|
||
file:write(('%s-title=%s\n%s-desc=%s\n'):format(name, title, name, desc))
|
||
end
|
||
|
||
file:write('\n')
|
||
file:close()
|
||
|
||
return true, 'File created: '..filePath
|
||
end
|
||
})
|