1
0
mirror of https://github.com/Refactorio/RedMew.git synced 2025-03-17 21:08:08 +02:00

added integer + postive_integer to settings types

This commit is contained in:
grilledham 2019-06-19 17:33:43 +01:00
parent c7f63dcc4f
commit 183a31293f
3 changed files with 35 additions and 5 deletions

View File

@ -31,6 +31,8 @@ button_tooltip=Shows / hides the Redmew Gui buttons.
[redmew_settings_util]
fraction_invalid_value=fraction setting type requires the input to be a valid number between 0 and 1.
integer_invalid_value=integer setting type requires the input to be a valid number.
positive_integer_invalid_value=positive integer setting type requires the input to be a valid positive number.
string_invalid_value=string setting type requires the input to be either a valid string or something that can be converted to a string.
boolean_invalid_value=boolean setting type requires the input to be either a boolean, number or string that can be transformed to a boolean.
color_invalid_string_value=color setting type requires the input to be either a valid preset such as "red" or "green", or a valid "r g b" or "r g b a" value.

View File

@ -133,11 +133,11 @@ local function color_sanitizer(input)
end
return true, to_valid_rgba_table({
r = input.r,
g = input.g,
b = input.b,
a = input.a,
})
r = input.r,
g = input.g,
b = input.b,
a = input.a,
})
end
return false, {'redmew_settings_util.invalid_color_value'}
@ -168,6 +168,32 @@ return {
return true, input
end
},
integer = {
equals = equals_by_value,
toScalar = raw,
sanitizer = function(input)
input = tonumber(input)
if input == nil then
return false, {'redmew_settings_util.integer_invalid_value'}
end
return true, floor(input)
end
},
positive_integer = {
equals = equals_by_value,
toScalar = raw,
sanitizer = function(input)
input = tonumber(input)
if input == nil or input <= 0 then
return false, {'redmew_settings_util.integer_invalid_value'}
end
return true, floor(input)
end
},
string = {
equals = equals_by_value,
toScalar = raw,

View File

@ -45,6 +45,8 @@ Public.events = {
Public.types = {
fraction = 'fraction',
integer = 'integer',
positive_integer = 'positive_integer',
string = 'string',
boolean = 'boolean',
color = 'color',