From bb286ba7d07b73b1297a2abfabf41b41e8aa73ce Mon Sep 17 00:00:00 2001 From: Octav Sandulescu Date: Fri, 21 Aug 2015 16:51:18 +0000 Subject: [PATCH] Add remote interface, localize errors --- control.lua | 8 +-- evoGUI.lua | 3 +- info.json | 2 +- prototypes/logistic-reader.lua | 89 ++++++++++++++++++++++++++++++++++ remote.lua | 43 ++++++++++++++++ script-locale/en.cfg | 8 +++ 6 files changed, 148 insertions(+), 5 deletions(-) create mode 100644 prototypes/logistic-reader.lua create mode 100644 remote.lua diff --git a/control.lua b/control.lua index 41336d5..c3a54c2 100644 --- a/control.lua +++ b/control.lua @@ -1,7 +1,9 @@ require "defines" require "evoGUI" -local function log(message) +if not evogui then evogui = {} end + +function evogui.log(message) for i, p in ipairs(game.players) do p.print(message) end @@ -9,12 +11,12 @@ end game.on_event(defines.events.on_tick, function(event) local status, err = pcall(evogui.update_gui) - if err then log(string.format("[evoGUI] Error: %s", err)) end + if err then evogui.log({"err_generic", "on_tick", err}) end end) game.on_event(defines.events.on_gui_click, function(event) if evogui.on_click[event.element.name] ~= nil then local status, err = pcall(evogui.on_click[event.element.name], event) - if err then log(string.format("[evoGUI|on_gui_click|%s] Error: %s", event.element.name, err)) end + if err then evogui.log({"err_specific", "on_gui_click", event.element.name, err}) end end end) diff --git a/evoGUI.lua b/evoGUI.lua index 6e89395..8a9600d 100644 --- a/evoGUI.lua +++ b/evoGUI.lua @@ -5,12 +5,13 @@ require "value_sensors.play_time" require "value_sensors.player_locations" require "value_sensors.pollution_around_player" require "settingsGUI" +require "remote" if not evogui then evogui = {} end if not evogui.on_click then evogui.on_click = {} end evogui.update_delay = 60 -- ticks to wait between each GUI update -local EXPECTED_VERSION = "0.3.2" +local EXPECTED_VERSION = "0.3.3" function evogui.update_gui() diff --git a/info.json b/info.json index 2a4a15c..3fa0262 100644 --- a/info.json +++ b/info.json @@ -1,6 +1,6 @@ { "name": "EvoGUI", - "version": "0.3.2", + "version": "0.3.3", "title": "Evolution Factor Indicator", "author": "Octav \"narc\" Sandulescu", "contact": "factorio-mods@narc.ro", diff --git a/prototypes/logistic-reader.lua b/prototypes/logistic-reader.lua new file mode 100644 index 0000000..d1dbe6f --- /dev/null +++ b/prototypes/logistic-reader.lua @@ -0,0 +1,89 @@ +local logistic_reader_item = { +} + +local logistic_reader_recipe = { +} + +local logistic_reader_entity = { +} + +local invisible_inserter = { + type = "inserter", + name = "evogui-hidden-inserter", + icon = "__EvoGUI__/graphics/nil.png", + flags = {"placeable-neutral", "player-creation", "not-on-map"}, + minable = {hardness = 0.2, mining_time = 0.5, result = "evogui-logistic-reader"}, + max_health = 40, + corpse = "small-remnants", + order = "z[zebra]", + resistances = {{ + type = "fire", + percent = 90 + }}, + collision_box = {{-0, -0}, {0, 0}}, + selection_box = {{-0, -0}, {0, 0}}, + pickup_position = {0, -1}, + insert_position = {0, 1.2}, + energy_per_movement = 7000, + energy_per_rotation = 7000, + energy_source = { + type = "burner", + usage_priority = "secondary-input", + drain = "0.0kW", + effectivity=1, + fuel_inventory_size=1, + }, + extension_speed = 0.07, + rotation_speed = 0.04, + fast_replaceable_group = "inserter", + filter_count = 5, + hand_base_picture = { + filename = "__EvoGUI__/graphics/nil.png", + priority = "extra-high", + width = 1, + height = 1 + }, + hand_closed_picture = { + filename = "__EvoGUI__/graphics/nil.png", + priority = "extra-high", + width = 1, + height = 1 + }, + hand_open_picture = { + filename = "__EvoGUI__/graphics/nil.png", + priority = "extra-high", + width = 1, + height = 1 + }, + hand_base_shadow = { + filename = "__EvoGUI__/graphics/nil.png", + priority = "extra-high", + width = 1, + height = 1 + }, + hand_closed_shadow = { + filename = "__EvoGUI__/graphics/nil.png", + priority = "extra-high", + width = 1, + height = 1 + }, + hand_open_shadow = { + filename = "__EvoGUI__/graphics/nil.png", + priority = "extra-high", + width = 1, + height = 1 + }, + platform_picture = { + sheet = { + filename="__EvoGUI__/graphics/nil.png", + priority = "extra-high", + width = 1, + height = 1 + } + }, + programmable = true, + rotation_speed = 0.035, + uses_arm_movement = "basic-inserter", +} + +data:extend({invisible_inserter}) diff --git a/remote.lua b/remote.lua new file mode 100644 index 0000000..fa704b9 --- /dev/null +++ b/remote.lua @@ -0,0 +1,43 @@ +if not evogui then evogui = { log = function() end } end + + +local function get_player_by_name(player_name) + for _, p in pairs(game.players) do + if p.name == player_name then + return p + end + end + return nil +end + + +local function remote_rebuild(player_name) + if not player_name then + evogui.log({"err_needplayername"}) + return + end + + player = get_player_by_name(player_name) + if not player then + evogui.log({"err_nosuchplayer", tostring(player_name)}) + return + end + + if not global.evogui or not global.evogui[player_name] then + evogui.log({"err_noplayerdata", player_name}) + return + end + + global.evogui[player.name].version = "" +end + + +interface = { + rebuild = function(player_name) + local status, err = pcall(remote_rebuild, player_name) + if err then evogui.log({"err_generic", "interface.rebuild", err}) end + end +} + + +remote.add_interface("EvoGUI", interface) diff --git a/script-locale/en.cfg b/script-locale/en.cfg index b1b081d..a5efb26 100644 --- a/script-locale/en.cfg +++ b/script-locale/en.cfg @@ -19,3 +19,11 @@ settings_always_visible=Always visible settings_in_popup=Visible in popup settings_close=Close + + +err_generic=[EvoGUI|__1__] Error: __2__ +err_specific=[EvoGUI|__1__|__2__] Error: __3__ + +err_needplayername=[EvoGUI] Need a player name! +err_nosuchplayer=[EvoGUI] No such player: __1__! +err_noplayerdata=[EvoGUI] No player data for __1__!