-
Notifications
You must be signed in to change notification settings - Fork 1
/
LOSCalculator.txt
91 lines (86 loc) · 2.48 KB
/
LOSCalculator.txt
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
--@name Lanteans OS AppCard (Calculator)
--@author Yuri6037
--@class processor
--@model models/props_junk/sawblade001a.mdl
--Initialisation
Entity = ents.self()
Entity:setMaterial("phoenix_storms/black_chrome")
wire.createOutputs({"AppName", "AppCode"}, {"String", "String"})
Ports = wire.ports
--End
--Application
AppName = "calculator"
AppCode = [[
local Numpad = {
{"7", "8", "9", "/", "SIN"},
{"4", "5", "6", "*", "COS"},
{"1", "2", "3", "-", "SQT"},
{"0", ".", "+", "C", ""}
}
local app = {}
function app:Init()
self:SetSize(146, 166)
self:SetTitle("Calculator")
local CurNb = self:AddComponent("label", 10, 32)
CurNb:SetText("0")
local StNb = self:AddComponent("label", 30, 42)
StNb:SetText("")
local StOp = self:AddComponent("label", 10, 42)
StOp:SetText("")
local dot = false
for k, v in pairs(Numpad) do
for k1, v1 in pairs(v) do
local b = self:AddComponent("button", 10 + (k1 - 1) * 26, 62 + (k - 1) * 26, v1, function(app)
--TODO : Implement buttons (math.round(10))
if (v1 >= "0" and v1 <= "9" and string.len(CurNb.Text) < 11) then
if (CurNb.Text == "0") then CurNb.Text = "" end
CurNb.Text = CurNb.Text .. v1
elseif (v1 == "." and not(dot)) then
CurNb.Text = CurNb.Text .. v1
dot = true
elseif (v1 == "/" or v1 == "*" or v1 == "-" or v1 == "+") then
StNb:SetText(CurNb.Text)
StOp:SetText(v1)
CurNb:SetText("0")
elseif (v1 == "C") then
CurNb:SetText("0")
StNb:SetText("")
StOp:SetText("")
dot = false
elseif (v1 == "") then
local n = tonumber(StNb.Text)
local n1 = tonumber(CurNb.Text)
local res = 0
if (StOp.Text == "/") then res = n / n1
elseif (StOp.Text == "*") then res = n * n1
elseif (StOp.Text == "-") then res = n - n1
elseif (StOp.Text == "+") then res = n + n1 end
CurNb:SetText(tostring(res))
StNb:SetText("")
StOp:SetText("")
elseif (v1 == "COS") then
local n1 = tonumber(CurNb.Text)
CurNb.Text = tostring(math.cos(n1))
elseif (v1 == "SIN") then
local n1 = tonumber(CurNb.Text)
CurNb.Text = tostring(math.sin(n1))
elseif (v1 == "SQT") then
local n1 = tonumber(CurNb.Text)
CurNb.Text = tostring(math.sqrt(n1))
end
end)
b:SetSize(16, 16)
end
end
end
function app:PreRender()
GUI.ColoredRect(10, 32, 126, 26, COLOR(255, 255, 255))
end
OS.DefineApp("calculator", app)
OS.AddAppMenuItem("calculator", "Calculator", "Office")
]]
--End
--Saving
Ports["AppName"] = "app_" .. AppName
Ports["AppCode"] = AppCode
--End