Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/1 initial tests #6

Merged
merged 5 commits into from
Nov 29, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
closes #3 automatic updates of values
  • Loading branch information
JonasJurczok committed Nov 29, 2018
commit 89694f31cc4bbaaedb16abf9a461f71c2cce2c9e
30 changes: 24 additions & 6 deletions src/pmon/pmon.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ function pmon.on_tick(event)
pmon.mod_init()

for _, monitor in pairs(global.pmon) do
-- update data

pmon.update_data(monitor)
end

-- update UI
Expand All @@ -23,6 +22,17 @@ function pmon.on_tick(event)
end
end

function pmon.update_data(monitor)
if (monitor.type == "solar-panel") then
monitor.value = (0.85 - monitor.entity.surface.darkness)/0.85
elseif (monitor.type == "accumulator") then
local max = monitor.entity.electric_buffer_size
local current = monitor.entity.energy

monitor.value = current / max
end
end

function pmon.update_ui(player)
local frame = pmon.ensure_main_frame(player)

Expand Down Expand Up @@ -123,14 +133,13 @@ function pmon.add_monitor(player)
local title = dialog.pmon_add_dialog_flow.pmon_add_monitor_title.text

local monitor = {}
monitor.type = entity.prototype.type
monitor.entity = entity
monitor.title = title
monitor.name = string.gsub(title, " ", "_")
monitor.type = entity.prototype.type
monitor.value = 0

table.insert(global.pmon, monitor)

end

function pmon.create_add_dialog(player, entity)
Expand Down Expand Up @@ -207,7 +216,16 @@ function pmon.on_player_selected_area(event)
player = game.players[event.player_index]

if player.cursor_stack.name == "pmon-power-monitor" then
player.clean_cursor()
pmon.create_add_dialog(player, event.entities[1])
local entity = event.entities[1]

if (entity) then
local type = entity.prototype.type
if (type == "solar-panel" or type == "accumulator") then
player.clean_cursor()
pmon.create_add_dialog(player, entity)
else
player.print("Currently only solar panels and accumulators are supported.")
end
end
end
end