Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Configuration
- local reactor_name = "fusionReactorLogicAdapter_1" -- Nom du peripheral du reacteur
- local redstone_output_face = "top" -- Face ou envoyer la redstone si le reacteur est eteint
- local redstone_start_face = "left" -- Face ou envoyer un pulse pour demarrer le reacteur
- local redstone_pulse_time = 1 -- Duree du pulse en secondes
- -- Initialisation du moniteur
- local monitor = peripheral.find("monitor")
- if not monitor then
- error("Aucun ecran detecte")
- end
- -- Initialisation du reacteur
- local reactor = peripheral.wrap(reactor_name)
- if not reactor then
- error("Reactor not detected: " .. reactor_name)
- end
- monitor.clear()
- monitor.setTextScale(1)
- monitor.setTextColor(colors.white)
- -- Coordonnees du bouton
- local button_x1, button_y1 = 2, 7
- local button_x2, button_y2 = 18, 9
- -- Variables de suivi
- local last_ignited = nil
- local ignition_in_progress = false -- EmpĂȘche le double envoi du signal
- -- Fonction pour formater les nombres avec des espaces
- local function formatNumber(n)
- return tostring(n):reverse():gsub("(%d%d%d)", "%1 "):reverse():gsub("^ ", "")
- end
- -- Fonction pour afficher les informations
- local function displayInfo()
- local ignited = reactor.isIgnited()
- monitor.clear()
- -- Affichage du titre
- monitor.setCursorPos(1, 1)
- monitor.write("Fusion Reactor Controller")
- -- Ligne vide entre le titre et les infos
- monitor.setCursorPos(1, 3)
- monitor.write("")
- -- Affichage du statut du reacteur
- monitor.setCursorPos(1, 4)
- monitor.write("Reactor Status :")
- monitor.setCursorPos(1, 5)
- if ignited then
- monitor.setTextColor(colors.green)
- monitor.write("Ignited")
- redstone.setOutput(redstone_output_face, false) -- Desactiver la redstone
- ignition_in_progress = false -- Reinitialiser l'etat apres allumage
- else
- monitor.setTextColor(colors.red)
- monitor.write("Stopped")
- redstone.setOutput(redstone_output_face, true) -- Activer la redstone
- end
- -- Remise de la couleur en blanc apres l'affichage du statut
- monitor.setTextColor(colors.white)
- if ignited then
- -- Ligne vide avant la production d'energie
- monitor.setCursorPos(1, 7)
- monitor.write("")
- -- Affichage de la production d'energie
- local production = reactor.getProductionRate()
- local productionRF = production / 2.5 -- Conversion de J en RF
- monitor.setCursorPos(1, 8)
- monitor.write("Energy Production")
- monitor.setCursorPos(1, 9)
- monitor.write(formatNumber(productionRF) .. " RF/t")
- else
- if ignition_in_progress then
- -- Affichage du message "Reactor ignition started"
- monitor.setCursorPos(1, 7)
- monitor.write("Reactor ignition")
- monitor.setCursorPos(1, 8)
- monitor.write("started...")
- else
- -- Affichage du bouton "START REACTOR"
- monitor.setCursorPos(button_x1, button_y1)
- monitor.setBackgroundColor(colors.gray)
- monitor.setTextColor(colors.white)
- monitor.write(" START REACTOR ")
- -- Remise a zero des couleurs apres le bouton
- monitor.setBackgroundColor(colors.black)
- monitor.setTextColor(colors.white)
- end
- end
- last_ignited = ignited
- end
- -- Fonction pour gerer le clic sur le bouton
- local function checkTouch()
- while true do
- local event, side, x, y = os.pullEvent("monitor_touch")
- if not reactor.isIgnited() and not ignition_in_progress then
- if x >= button_x1 and x <= button_x2 and y >= button_y1 and y <= button_y2 then
- -- Definir l'etat "ignition en cours"
- ignition_in_progress = true
- displayInfo() -- Rafraichir pour afficher "Reactor ignition started"
- -- Envoi du pulse de redstone sur la face choisie
- redstone.setOutput(redstone_start_face, true)
- sleep(redstone_pulse_time)
- redstone.setOutput(redstone_start_face, false)
- end
- end
- end
- end
- -- Boucle de mise a jour en continu
- parallel.waitForAny(
- function()
- while true do
- displayInfo()
- sleep(1)
- end
- end,
- checkTouch
- )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement