View difference between Paste ID: rbTACve9 and YTCe6Hn4
SHOW: | | - or go back to the newest paste.
1
local bedrockPath='Build/' if OneOS then OneOS.LoadAPI('/System/API/Bedrock.lua', false)elseif fs.exists(bedrockPath..'/Bedrock')then os.loadAPI(bedrockPath..'/Bedrock')else if http then print('Downloading Bedrock...')local h=http.get('http://pastebin.com/raw.php?i=0MgKNqpN')if h then local f=fs.open(bedrockPath..'/Bedrock','w')f.write(h.readAll())f.close()h.close()os.loadAPI(bedrockPath..'/Bedrock')else error('Failed to download Bedrock. Is your internet working?') end else error('This program needs to download Bedrock to work. Please enable HTTP.') end end if Bedrock then Bedrock.BasePath = bedrockPath Bedrock.ProgramPath = shell.getRunningProgram() end
2
3-
local receivingComputer = 475
3+
local baseRestAPI = 'http://45.76.117.50:8080/datastore/'
4-
local currentSelection
4+
5
local program, currentState
6-
rednet.open('back')
6+
7-
local program
7+
8
	program = Bedrock:Initialise()
9
	program:Run(function()
10
		program:LoadView('main')
11
		
12
		-- Make sure the button is up to date with current reactor state
13
		currentState = getReactorState()
14-
		-- Load Button (loadBtn)
14+
		local newText = currentState and 'Reactor State: ON' or 'Reactor State: OFF'
15-
		program:GetObject('loadBtn').OnClick = function(self, event, side, x, y)
15+
		local newColour = currentState and colors.green or colors.red
16-
			-- Request file from other computer
16+
		program:GetObject('labelState').Text = newText
17-
			program:StartTimer(updateResidentList, 0.1)
17+
		program:GetObject('labelState').TextColour = newColour
18
		
19
		program:GetObject('reactorState').OnClick = function(self, event, side, x, y)
20-
		-- Add Button (addBtn)
20+
			currentState = not currentState
21-
		program:GetObject('addBtn').OnClick = function(self, event, side, x, y)
21+
			local newText = currentState and 'Reactor State: ON' or 'Reactor State: OFF'
22-
			-- Request file from other computer
22+
			local newColour = currentState and colors.green or colors.red
23-
			addNew()
23+
			program:GetObject('labelState').Text = 'OFF'
24
			program:GetObject('labelState').TextColour = newColour
25
			program:StartTimer(function()setReactorState(currentState)end, 0.1)
26-
		-- Save Button (saveBtn)
26+
27-
		program:GetObject('saveBtn').OnClick = function(self, event, side, x, y)
27+
28-
			-- Send file to pc.
28+
29-
			local newResidents = ''
29+
30-
			for key, item in ipairs(program:GetObject('residentList').Items) do
30+
function getReactorState()
31-
				newResidents = newResidents .. item .. '\n'
31+
	local reactorRequest = http.get(baseRestAPI..'get/namar_reactor/state')
32-
			end
32+
	local requestContent = reactorRequest.readAll()
33-
			rednet.send(receivingComputer, newResidents, 'resident_controller')
33+
	local reactorState = requestContent == 'error:nostore' or requestContent == 'true' or false
34
	reactorRequest.close()
35
	return reactorState
36-
		-- Delete Button (deleteBtn)
36+
37-
		program:GetObject('deleteBtn').OnClick = function(self, event, side, x, y)
37+
38-
			-- Remove from Items, tried to remvoe the key, only works with new table element.
38+
function setReactorState(bool)
39-
			if ( currentSelection ) then
39+
	http.request(baseRestAPI..'set/namar_reactor/state/'..tostring(bool))
40-
				program:DisplayAlertWindow('Are you sure?', 'Delete "'..currentSelection..'"?', {'No', 'Yes'}, function(value)
40+
41-
					if ( value == 'Yes' ) then
41+
42-
						local newResidents = {}
42+
43-
						for key, item in ipairs(program:GetObject('residentList').Items) do
43+