factoriolib / flib

A set of high-quality, commonly-used utilities for creating Factorio mods.
https://mods.factorio.com/mod/flib
MIT License
67 stars 15 forks source link

How to use flib.gui-beta while using stdlib's event system? #34

Closed kevinmama closed 3 years ago

kevinmama commented 3 years ago

Sorry for duplicating issue#19.

gui-beta call 'flib_gui.hook_events' when it is load. I can't use my own event handler.

Solve by rewrite some code in flib-beta before using it


local gui = require("__flib__.gui-beta")
local Event = require('__stdlib__/stdlib/event/event')

local gui_event_defines = {}
for name, id in pairs(defines.events) do
    if string.find(name, "^on_gui") then
        gui_event_defines[name] = id
        --event_id_to_string_mapping[id] = string.gsub(name, "^on_gui", "on")
    end
end

function gui.hook_events(callback)
    --local on_event = script.on_event
    for _, id in pairs(gui_event_defines) do
        --on_event(id, callback)
        Event.register(id, callback)
    end
end
`
raiguard commented 3 years ago

You don't need to rewrite anything, just don't call hook_events and pass the events you need through stdlib.