est31
2015-02-08 4b179821d3bc6cc3f01a6919e2182da8a9a62ea0
Get rid of technic.format
12 files modified
90 ■■■■■ changed files
technic/helpers.lua 42 ●●●● patch | view | raw | blame | history
technic/init.lua 8 ●●●● patch | view | raw | blame | history
technic/locale/de.txt 5 ●●●●● patch | view | raw | blame | history
technic/locale/es.txt 5 ●●●●● patch | view | raw | blame | history
technic/locale/it.txt 5 ●●●●● patch | view | raw | blame | history
technic/locale/template.txt 8 ●●●●● patch | view | raw | blame | history
technic/machines/LV/solar_panel.lua 2 ●●● patch | view | raw | blame | history
technic/machines/MV/wind_mill.lua 2 ●●● patch | view | raw | blame | history
technic/machines/register/battery_box.lua 4 ●●●● patch | view | raw | blame | history
technic/machines/register/solar_array.lua 2 ●●● patch | view | raw | blame | history
technic/machines/supply_converter.lua 3 ●●●● patch | view | raw | blame | history
technic/machines/switching_station.lua 4 ●●●● patch | view | raw | blame | history
technic/helpers.lua
@@ -1,5 +1,5 @@
--load config
local sepchar, baresepchar = nil, nil
local sepchar = nil
do
    local sepcode = technic.config:get("thousand_separator")
    --default is SI style
@@ -58,38 +58,10 @@
    return nil
end
function technic.format(str, ...)
    local arg={...}
    local param = nil
    local percent = false
    local res = ""
    local i = 1
    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
function technic.prettynum(num)
    local str, k = tostring(num), nil
    repeat
        str, k = str:gsub("^(-?%d+)(%d%d%d)", "%1"..sepchar.."%2")
    until k == 0
    return str
end
technic/init.lua
@@ -16,8 +16,12 @@
technic.modpath = modpath
-- Boilerplate to support intllib
local S = rawget(_G, "intllib") and intllib.Getter() or function(s) return s end
technic.getter = S
if minetest.get_modpath("intllib") then
    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
dofile(modpath.."/config.lua")
technic/locale/de.txt
@@ -36,6 +36,7 @@
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.
# $1: Machine name (Includes tier)
@1 Active (@2 EU) = @1 ist eingeschaltet (@2 EU)
%s Active = %s ist eingeschaltet
%s Disabled = %s ist ausgeschaltet
%s Enabled =
@@ -106,9 +107,9 @@
Discharge = Entladen
Power level = Energiestufe
# $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
%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%%
Choose Milling Program: = Waehle ein Fraesprogramm:
Slim Elements half / normal height: = Schmale Elemente von halber / normaler Hoehe:
technic/locale/es.txt
@@ -36,6 +36,7 @@
Machine cannot be removed because it is not empty = La maquina no puede removerse porque no esta vacia
Inventory move disallowed due to protection =
# $1: Machine name (Includes tier)
@1 Active (@2 EU) = @1 Activo (@2 EU)
%s Active = %s Activo
%s Enabled =
%s Idle = %s Quieto
@@ -102,9 +103,9 @@
Discharge = Descargar
Power level = Nivel de Poder
# $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
%s. Supply: %d Demand: %d = %s. Alimentacion: %d Demanda: %d
@1. Supply: @2 Demand: @3 = @1. Alimentacion: @2 Demanda: @3
# $1: Production percent
Production at %d%% = Produccion en %d%%
Stopped =
technic/locale/it.txt
@@ -33,6 +33,7 @@
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
# $1: Machine name (Includes tier)
@1 Active (@2 EU) = @1 Attivo (@2 EU)
%s Active = %s Attivo
%s Disabled = %s Disabilitato
%s Enabled =
@@ -103,9 +104,9 @@
Discharge = Scarica
Power level = Livello di potenza
# $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
%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%%
Choose Milling Program: = Scegliere un programma di Fresatura
Slim Elements half / normal height: = Metà elementi sottili / altezza normale:
technic/locale/template.txt
@@ -36,6 +36,7 @@
Machine cannot be removed because it is not empty =
Inventory move disallowed due to protection =
# $1: Machine name (Includes tier)
@1 Active (@2 EU) =
%s Active =
%s Disabled =
%s Enabled =
@@ -68,7 +69,7 @@
## Machine names
# $1: Tier
%s Alloy Furnace =
%s Battery Box =
%s Battery Box =
%s Cable =
%s CNC Machine =
%s Centrifuge =
@@ -111,9 +112,9 @@
Discharge =
Power level =
# $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
%s. Supply: %d Demand: %d =
@1. Supply: @2 Demand: @3 =
Production at %d%% =
Choose Milling Program: =
Slim Elements half / normal height: =
@@ -124,6 +125,7 @@
Digging finished =
Digging %d m above machine =
Digging %d m below machine =
@1 (@2 @3 -> @4 @5) =
## CNC
Cylinder =
technic/machines/LV/solar_panel.lua
@@ -24,7 +24,7 @@
        local charge_to_give = math.floor((light + pos1.y) * 3)
        charge_to_give = math.max(charge_to_give, 0)
        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)
    else
        meta:set_string("infotext", S("%s Idle"):format(machine_name))
technic/machines/MV/wind_mill.lua
@@ -55,7 +55,7 @@
        meta:set_int("MV_EU_supply", power)
    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
minetest.register_node("technic:wind_mill", {
technic/machines/register/battery_box.lua
@@ -142,8 +142,8 @@
            .."^[lowpart:"..charge_percent
            ..":technic_power_meter_fg.png]")
        local infotext = technic.format(S("%s Battery Box: %e/%e"), tier,
                current_charge, max_charge)
        local infotext = S("@1 Battery Box: @2/@3", tier,
                technic.prettynum(current_charge), technic.prettynum(max_charge))
        if eu_input == 0 then
            infotext = S("%s Idle"):format(infotext)
        end
technic/machines/register/solar_array.lua
@@ -28,7 +28,7 @@
            local charge_to_give = math.floor((light + pos.y) * data.power)
            charge_to_give = math.max(charge_to_give, 0)
            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)
        else
            meta:set_string("infotext", S("%s Idle"):format(machine_name))
technic/machines/supply_converter.lua
@@ -30,8 +30,7 @@
        meta:set_int(from.."_EU_supply", 0)
        meta:set_int(to.."_EU_demand", 0)
        meta:set_int(to.."_EU_supply", input * remain)
        meta:set_string("infotext", machine_name
            ..technic.format(" (%e %s -> %e %s)", input, from, input * remain, to))
        meta:set_string("infotext", S("@1 (@2 @3 -> @4 @5)", machine_name, technic.prettynum(input), from, technic.prettynum(input * remain), to))
    else
        meta:set_string("infotext", S("%s Has Bad Cabling"):format(machine_name))
        if to then
technic/machines/switching_station.lua
@@ -292,8 +292,8 @@
        --dprint("Total BA demand:"..BA_eu_demand)
        meta:set_string("infotext",
                technic.format(S("%s. Supply: %e Demand: %e"),
                machine_name, PR_eu_supply, RE_eu_demand))
                S("@1. Supply: @2 Demand: @3",
                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 PR_eu_supply >= RE_eu_demand then