-
Notifications
You must be signed in to change notification settings - Fork 0
/
lib.lua
55 lines (43 loc) · 1002 Bytes
/
lib.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
function HasElectricTrainInstalled()
return HasModInstalled("ElectricTrain")
end
function HasSEInstalled()
return HasModInstalled("space-exploration")
end
function HasModInstalled(mod)
if mods then
return mods[mod]
end
return game.active_mods[mod]
end
function table.count(self)
if self == nil or self == {} then
return 0
end
local i = 0
for _ in pairs(self) do
i = i + 1
end
return i
end
function format_number(number_string)
local number = number_string:match('%d+%.?%d+')
local append_suffix = number_string:match('%a+')
local pre = ""
local typ = ""
if append_suffix:len() == 2 then
pre = append_suffix:sub(1, 1):upper()
typ = append_suffix:sub(2):upper()
elseif append_suffix:len() == 1 then
typ = append_suffix:upper()
end
if pre == "K" then
number = number * 1000
elseif pre == "M" then
number = number * 1000000
end
if typ == "W" then
number = number / 60
end
return number
end