mirror of
https://github.com/minetest-mods/technic.git
synced 2024-08-21 05:54:05 +02:00
Get rid of technic.format
This commit is contained in:
parent
7ed1aa9398
commit
4b179821d3
@ -1,5 +1,5 @@
|
|||||||
--load config
|
--load config
|
||||||
local sepchar, baresepchar = nil, nil
|
local sepchar = nil
|
||||||
do
|
do
|
||||||
local sepcode = technic.config:get("thousand_separator")
|
local sepcode = technic.config:get("thousand_separator")
|
||||||
--default is SI style
|
--default is SI style
|
||||||
@ -58,38 +58,10 @@ function technic.get_or_load_node(pos)
|
|||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
function technic.format(str, ...)
|
function technic.prettynum(num)
|
||||||
local arg={...}
|
local str, k = tostring(num), nil
|
||||||
local param = nil
|
repeat
|
||||||
local percent = false
|
str, k = str:gsub("^(-?%d+)(%d%d%d)", "%1"..sepchar.."%2")
|
||||||
local res = ""
|
until k == 0
|
||||||
local i = 1
|
return str
|
||||||
for c in str:gmatch"." do
|
|
||||||
if percent then
|
|
||||||
assert(c ~= "%") --syntax error
|
|
||||||
if c == "e" then
|
|
||||||
-- use enhanced number formatting
|
|
||||||
-- only works for unsigned numbers
|
|
||||||
local numstr = tostring(math.abs(arg[i]))
|
|
||||||
local a, b, body, frac = numstr:find("^(%d+)([.]?.-)$")
|
|
||||||
a = 1
|
|
||||||
body = body..baresepchar
|
|
||||||
while a ~= 0 do
|
|
||||||
body, a = body:gsub("(%d)(%d%d%d)"..sepchar, "%1"..sepchar.."%2"..sepchar, 1)
|
|
||||||
end
|
|
||||||
body = body:gsub(sepchar.."$", "")
|
|
||||||
res = res .. body .. frac
|
|
||||||
else
|
|
||||||
--use traditional string:format
|
|
||||||
res = res .. (string.format(("%"..c), arg[i]))
|
|
||||||
end
|
|
||||||
i = i + 1
|
|
||||||
percent = false
|
|
||||||
elseif c == "%" then
|
|
||||||
percent = true
|
|
||||||
else
|
|
||||||
res = res .. c
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return res
|
|
||||||
end
|
end
|
@ -16,8 +16,12 @@ local modpath = minetest.get_modpath("technic")
|
|||||||
technic.modpath = modpath
|
technic.modpath = modpath
|
||||||
|
|
||||||
-- Boilerplate to support intllib
|
-- Boilerplate to support intllib
|
||||||
local S = rawget(_G, "intllib") and intllib.Getter() or function(s) return s end
|
if minetest.get_modpath("intllib") then
|
||||||
technic.getter = S
|
technic.getter = intllib.Getter()
|
||||||
|
else
|
||||||
|
technic.getter = function(s,a,...)if a==nil then return s end a={a,...}return s:gsub("(@?)@(%(?)(%d+)(%)?)",function(e,o,n,c)if e==""then return a[tonumber(n)]..(o==""and c or"")else return"@"..o..n..c end end) end
|
||||||
|
end
|
||||||
|
local S = technic.getter
|
||||||
|
|
||||||
-- Read configuration file
|
-- Read configuration file
|
||||||
dofile(modpath.."/config.lua")
|
dofile(modpath.."/config.lua")
|
||||||
|
@ -36,6 +36,7 @@ Rubber Fiber = Gummifaser
|
|||||||
Machine cannot be removed because it is not empty = Die Maschine kann nicht entfernt werden, weil sie noch nicht leer ist.
|
Machine cannot be removed because it is not empty = Die Maschine kann nicht entfernt werden, weil sie noch nicht leer ist.
|
||||||
Inventory move disallowed due to protection = Das Inventar ist geschuetzt, Zugriff verweigert.
|
Inventory move disallowed due to protection = Das Inventar ist geschuetzt, Zugriff verweigert.
|
||||||
# $1: Machine name (Includes tier)
|
# $1: Machine name (Includes tier)
|
||||||
|
@1 Active (@2 EU) = @1 ist eingeschaltet (@2 EU)
|
||||||
%s Active = %s ist eingeschaltet
|
%s Active = %s ist eingeschaltet
|
||||||
%s Disabled = %s ist ausgeschaltet
|
%s Disabled = %s ist ausgeschaltet
|
||||||
%s Enabled =
|
%s Enabled =
|
||||||
@ -106,9 +107,9 @@ Charge = Aufladen
|
|||||||
Discharge = Entladen
|
Discharge = Entladen
|
||||||
Power level = Energiestufe
|
Power level = Energiestufe
|
||||||
# $1: Tier $2: current_charge $3: max_charge
|
# $1: Tier $2: current_charge $3: max_charge
|
||||||
%s Battery Box: %d/%d = %s Batteriebox: %d/%d
|
@1 Battery Box: @2/@3 = @1 Batteriebox: @2/@3
|
||||||
# $1: Machine name $2: Supply $3: Demand
|
# $1: Machine name $2: Supply $3: Demand
|
||||||
%s. Supply: %d Demand: %d = %s. Versorgung: %d Bedarf: %d
|
@1. Supply: @2 Demand: @3 = @1. Versorgung: @2 Bedarf: @3
|
||||||
Production at %d%% = Produktion bei %d%%
|
Production at %d%% = Produktion bei %d%%
|
||||||
Choose Milling Program: = Waehle ein Fraesprogramm:
|
Choose Milling Program: = Waehle ein Fraesprogramm:
|
||||||
Slim Elements half / normal height: = Schmale Elemente von halber / normaler Hoehe:
|
Slim Elements half / normal height: = Schmale Elemente von halber / normaler Hoehe:
|
||||||
|
@ -36,6 +36,7 @@ Rubber Fiber = Fibra de Hule
|
|||||||
Machine cannot be removed because it is not empty = La maquina no puede removerse porque no esta vacia
|
Machine cannot be removed because it is not empty = La maquina no puede removerse porque no esta vacia
|
||||||
Inventory move disallowed due to protection =
|
Inventory move disallowed due to protection =
|
||||||
# $1: Machine name (Includes tier)
|
# $1: Machine name (Includes tier)
|
||||||
|
@1 Active (@2 EU) = @1 Activo (@2 EU)
|
||||||
%s Active = %s Activo
|
%s Active = %s Activo
|
||||||
%s Enabled =
|
%s Enabled =
|
||||||
%s Idle = %s Quieto
|
%s Idle = %s Quieto
|
||||||
@ -102,9 +103,9 @@ Charge = Cargar
|
|||||||
Discharge = Descargar
|
Discharge = Descargar
|
||||||
Power level = Nivel de Poder
|
Power level = Nivel de Poder
|
||||||
# $1: Tier $2: current_charge $3: max_charge
|
# $1: Tier $2: current_charge $3: max_charge
|
||||||
%s Battery Box: %d/%d = Caja de Bateria %s: %d/%d
|
@1 Battery Box: @2/@3 = Caja de Bateria @1: @2/@3
|
||||||
# $1: Machine name $2: Supply $3: Demand
|
# $1: Machine name $2: Supply $3: Demand
|
||||||
%s. Supply: %d Demand: %d = %s. Alimentacion: %d Demanda: %d
|
@1. Supply: @2 Demand: @3 = @1. Alimentacion: @2 Demanda: @3
|
||||||
# $1: Production percent
|
# $1: Production percent
|
||||||
Production at %d%% = Produccion en %d%%
|
Production at %d%% = Produccion en %d%%
|
||||||
Stopped =
|
Stopped =
|
||||||
|
@ -33,6 +33,7 @@ Rubber Fiber = Fibra di gomma
|
|||||||
Machine cannot be removed because it is not empty = La macchina non può essere rimossa perchè non è vuota
|
Machine cannot be removed because it is not empty = La macchina non può essere rimossa perchè non è vuota
|
||||||
Inventory move disallowed due to protection = Impossibile muovere l'inventario a causa della protezione
|
Inventory move disallowed due to protection = Impossibile muovere l'inventario a causa della protezione
|
||||||
# $1: Machine name (Includes tier)
|
# $1: Machine name (Includes tier)
|
||||||
|
@1 Active (@2 EU) = @1 Attivo (@2 EU)
|
||||||
%s Active = %s Attivo
|
%s Active = %s Attivo
|
||||||
%s Disabled = %s Disabilitato
|
%s Disabled = %s Disabilitato
|
||||||
%s Enabled =
|
%s Enabled =
|
||||||
@ -103,9 +104,9 @@ Charge = Carica
|
|||||||
Discharge = Scarica
|
Discharge = Scarica
|
||||||
Power level = Livello di potenza
|
Power level = Livello di potenza
|
||||||
# $1: Tier $2: current_charge $3: max_charge
|
# $1: Tier $2: current_charge $3: max_charge
|
||||||
%s Battery Box: %d/%d = %s Box Batterie: %d/%d
|
@1 Battery Box: @2/@3 = @1 Box Batterie: @2/@3
|
||||||
# $1: Machine name $2: Supply $3: Demand
|
# $1: Machine name $2: Supply $3: Demand
|
||||||
%s. Supply: %d Demand: %d = %s. Prodotto: %d Consumato: %d
|
@1. Supply: @2 Demand: @3 = @1. Prodotto: @2 Consumato: @3
|
||||||
Production at %d%% = Produzione a %d%%
|
Production at %d%% = Produzione a %d%%
|
||||||
Choose Milling Program: = Scegliere un programma di Fresatura
|
Choose Milling Program: = Scegliere un programma di Fresatura
|
||||||
Slim Elements half / normal height: = Metà elementi sottili / altezza normale:
|
Slim Elements half / normal height: = Metà elementi sottili / altezza normale:
|
||||||
|
@ -36,6 +36,7 @@ Rubber Fiber =
|
|||||||
Machine cannot be removed because it is not empty =
|
Machine cannot be removed because it is not empty =
|
||||||
Inventory move disallowed due to protection =
|
Inventory move disallowed due to protection =
|
||||||
# $1: Machine name (Includes tier)
|
# $1: Machine name (Includes tier)
|
||||||
|
@1 Active (@2 EU) =
|
||||||
%s Active =
|
%s Active =
|
||||||
%s Disabled =
|
%s Disabled =
|
||||||
%s Enabled =
|
%s Enabled =
|
||||||
@ -68,7 +69,7 @@ Disabled =
|
|||||||
## Machine names
|
## Machine names
|
||||||
# $1: Tier
|
# $1: Tier
|
||||||
%s Alloy Furnace =
|
%s Alloy Furnace =
|
||||||
%s Battery Box =
|
%s Battery Box =
|
||||||
%s Cable =
|
%s Cable =
|
||||||
%s CNC Machine =
|
%s CNC Machine =
|
||||||
%s Centrifuge =
|
%s Centrifuge =
|
||||||
@ -111,9 +112,9 @@ Charge =
|
|||||||
Discharge =
|
Discharge =
|
||||||
Power level =
|
Power level =
|
||||||
# $1: Tier $2: current_charge $3: max_charge
|
# $1: Tier $2: current_charge $3: max_charge
|
||||||
%s Battery Box: %d/%d =
|
@1 Battery Box: @2/@3 =
|
||||||
# $1: Machine name $2: Supply $3: Demand
|
# $1: Machine name $2: Supply $3: Demand
|
||||||
%s. Supply: %d Demand: %d =
|
@1. Supply: @2 Demand: @3 =
|
||||||
Production at %d%% =
|
Production at %d%% =
|
||||||
Choose Milling Program: =
|
Choose Milling Program: =
|
||||||
Slim Elements half / normal height: =
|
Slim Elements half / normal height: =
|
||||||
@ -124,6 +125,7 @@ Digging not started =
|
|||||||
Digging finished =
|
Digging finished =
|
||||||
Digging %d m above machine =
|
Digging %d m above machine =
|
||||||
Digging %d m below machine =
|
Digging %d m below machine =
|
||||||
|
@1 (@2 @3 -> @4 @5) =
|
||||||
|
|
||||||
## CNC
|
## CNC
|
||||||
Cylinder =
|
Cylinder =
|
||||||
|
@ -24,7 +24,7 @@ local run = function(pos, node)
|
|||||||
local charge_to_give = math.floor((light + pos1.y) * 3)
|
local charge_to_give = math.floor((light + pos1.y) * 3)
|
||||||
charge_to_give = math.max(charge_to_give, 0)
|
charge_to_give = math.max(charge_to_give, 0)
|
||||||
charge_to_give = math.min(charge_to_give, 200)
|
charge_to_give = math.min(charge_to_give, 200)
|
||||||
meta:set_string("infotext", technic.format(S("%s Active (%e EU)"), machine_name, charge_to_give))
|
meta:set_string("infotext", S("@1 Active (@2 EU)", machine_name, technic.prettynum(charge_to_give)))
|
||||||
meta:set_int("LV_EU_supply", charge_to_give)
|
meta:set_int("LV_EU_supply", charge_to_give)
|
||||||
else
|
else
|
||||||
meta:set_string("infotext", S("%s Idle"):format(machine_name))
|
meta:set_string("infotext", S("%s Idle"):format(machine_name))
|
||||||
|
@ -55,7 +55,7 @@ local run = function(pos, node)
|
|||||||
meta:set_int("MV_EU_supply", power)
|
meta:set_int("MV_EU_supply", power)
|
||||||
end
|
end
|
||||||
|
|
||||||
meta:set_string("infotext", technic.format("%s (%eEU)", machine_name, power))
|
meta:set_string("infotext", S("@1 (@2 EU)", machine_name, technic.prettynum(power)))
|
||||||
end
|
end
|
||||||
|
|
||||||
minetest.register_node("technic:wind_mill", {
|
minetest.register_node("technic:wind_mill", {
|
||||||
|
@ -142,8 +142,8 @@ function technic.register_battery_box(data)
|
|||||||
.."^[lowpart:"..charge_percent
|
.."^[lowpart:"..charge_percent
|
||||||
..":technic_power_meter_fg.png]")
|
..":technic_power_meter_fg.png]")
|
||||||
|
|
||||||
local infotext = technic.format(S("%s Battery Box: %e/%e"), tier,
|
local infotext = S("@1 Battery Box: @2/@3", tier,
|
||||||
current_charge, max_charge)
|
technic.prettynum(current_charge), technic.prettynum(max_charge))
|
||||||
if eu_input == 0 then
|
if eu_input == 0 then
|
||||||
infotext = S("%s Idle"):format(infotext)
|
infotext = S("%s Idle"):format(infotext)
|
||||||
end
|
end
|
||||||
|
@ -28,7 +28,7 @@ function technic.register_solar_array(data)
|
|||||||
local charge_to_give = math.floor((light + pos.y) * data.power)
|
local charge_to_give = math.floor((light + pos.y) * data.power)
|
||||||
charge_to_give = math.max(charge_to_give, 0)
|
charge_to_give = math.max(charge_to_give, 0)
|
||||||
charge_to_give = math.min(charge_to_give, data.power * 50)
|
charge_to_give = math.min(charge_to_give, data.power * 50)
|
||||||
meta:set_string("infotext", technic.format(S("%s Active (%e EU)"), machine_name, charge_to_give))
|
meta:set_string("infotext", S("@1 Active (@2 EU)", machine_name, technic.prettynum(charge_to_give)))
|
||||||
meta:set_int(tier.."_EU_supply", charge_to_give)
|
meta:set_int(tier.."_EU_supply", charge_to_give)
|
||||||
else
|
else
|
||||||
meta:set_string("infotext", S("%s Idle"):format(machine_name))
|
meta:set_string("infotext", S("%s Idle"):format(machine_name))
|
||||||
|
@ -30,8 +30,7 @@ local run = function(pos, node)
|
|||||||
meta:set_int(from.."_EU_supply", 0)
|
meta:set_int(from.."_EU_supply", 0)
|
||||||
meta:set_int(to.."_EU_demand", 0)
|
meta:set_int(to.."_EU_demand", 0)
|
||||||
meta:set_int(to.."_EU_supply", input * remain)
|
meta:set_int(to.."_EU_supply", input * remain)
|
||||||
meta:set_string("infotext", machine_name
|
meta:set_string("infotext", S("@1 (@2 @3 -> @4 @5)", machine_name, technic.prettynum(input), from, technic.prettynum(input * remain), to))
|
||||||
..technic.format(" (%e %s -> %e %s)", input, from, input * remain, to))
|
|
||||||
else
|
else
|
||||||
meta:set_string("infotext", S("%s Has Bad Cabling"):format(machine_name))
|
meta:set_string("infotext", S("%s Has Bad Cabling"):format(machine_name))
|
||||||
if to then
|
if to then
|
||||||
|
@ -292,8 +292,8 @@ minetest.register_abm({
|
|||||||
--dprint("Total BA demand:"..BA_eu_demand)
|
--dprint("Total BA demand:"..BA_eu_demand)
|
||||||
|
|
||||||
meta:set_string("infotext",
|
meta:set_string("infotext",
|
||||||
technic.format(S("%s. Supply: %e Demand: %e"),
|
S("@1. Supply: @2 Demand: @3",
|
||||||
machine_name, PR_eu_supply, RE_eu_demand))
|
machine_name, technic.prettynum(PR_eu_supply), technic.prettynum(RE_eu_demand)))
|
||||||
|
|
||||||
-- If the PR supply is enough for the RE demand supply them all
|
-- If the PR supply is enough for the RE demand supply them all
|
||||||
if PR_eu_supply >= RE_eu_demand then
|
if PR_eu_supply >= RE_eu_demand then
|
||||||
|
Loading…
Reference in New Issue
Block a user