Skip to content

Commit

Permalink
Get rid of middleclass
Browse files Browse the repository at this point in the history
  • Loading branch information
Insality committed Oct 14, 2024
1 parent 54345b9 commit 067b650
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 189 deletions.
45 changes: 19 additions & 26 deletions druid/component.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@
-- @alias druid.base_component

local const = require("druid.const")
local class = require("druid.system.middleclass")
local helper = require("druid.helper")

local BaseComponent = class("druid.component")
local BaseComponent = {}

local INTERESTS = {} -- Cache interests per component class in runtime
local IS_AUTO_TEMPLATE = not (sys.get_config_int("druid.no_auto_template", 0) == "1")
Expand Down Expand Up @@ -355,24 +354,6 @@ function BaseComponent.setup_component(self, druid_instance, context, style, ins
end


--- Basic constructor of component. It will call automaticaly
-- by `BaseComponent.create`
-- @tparam BaseComponent self @{BaseComponent}
-- @tparam string name BaseComponent name
-- @tparam number|nil input_priority The input priority. The bigger number processed first
-- @local
function BaseComponent.initialize(self, name, input_priority)
self._component = {
name = name,
input_priority = input_priority or const.PRIORITY_INPUT,
default_input_priority = input_priority or const.PRIORITY_INPUT,
is_debug = false,
_is_input_priority_changed = true, -- Default true for sort once time after GUI init
_uid = BaseComponent.create_uid()
}
end


--- Print log information if debug mode is enabled
-- @tparam BaseComponent self @{BaseComponent}
-- @tparam string message
Expand Down Expand Up @@ -499,12 +480,24 @@ end
-- @tparam number|nil input_priority The input priority. The bigger number processed first
-- @local
function BaseComponent.create(name, input_priority)
-- Yea, inheritance here
local new_class = class(name, BaseComponent)

new_class.initialize = function(self)
BaseComponent.initialize(self, name, input_priority)
end
local new_class = setmetatable({}, {
__index = BaseComponent,
__call = function(cls, ...)
local self = setmetatable({
_component = {
name = name,
input_priority = input_priority or const.PRIORITY_INPUT,
default_input_priority = input_priority or const.PRIORITY_INPUT,
is_debug = false,
_is_input_priority_changed = true, -- Default true for sort once time after GUI init
_uid = BaseComponent.create_uid()
}
}, {
__index = cls
})
return self
end
})

return new_class
end
Expand Down
4 changes: 3 additions & 1 deletion druid/druid.lua
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,9 @@ function M.new(context, style)
M.set_default_style(default_style)
end

local new_instance = druid_instance(context, style)
local new_instance = setmetatable({}, { __index = druid_instance })
new_instance:initialize(context, style)

table.insert(_instances, new_instance)
return new_instance
end
Expand Down
7 changes: 5 additions & 2 deletions druid/extended/hotkey.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@
-- @within BaseComponent
-- @alias druid.hotkey

--- On change state callback(self, state)
-- @tfield DruidEvent on_change_state @{DruidEvent}
--- On hotkey released callback(self, argument)
-- @tfield DruidEvent on_hotkey_pressed @{DruidEvent}

--- On hotkey released callback(self, argument)
-- @tfield DruidEvent on_hotkey_released @{DruidEvent}

--- Visual node
-- @tfield node node
Expand Down
7 changes: 3 additions & 4 deletions druid/system/druid_instance.lua
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@
-- @see Timer

local helper = require("druid.helper")
local class = require("druid.system.middleclass")
local settings = require("druid.system.settings")
local base_component = require("druid.component")

Expand All @@ -94,7 +93,7 @@ local back_handler = require("druid.base.back_handler")
-- local dynamic_grid = require("druid.extended.dynamic_grid")
-- local checkbox_group = require("druid.extended.checkbox_group")

local DruidInstance = class("druid.druid_instance")
local DruidInstance = {}

local MSG_ADD_FOCUS = hash("acquire_input_focus")
local MSG_REMOVE_FOCUS = hash("release_input_focus")
Expand Down Expand Up @@ -479,7 +478,7 @@ end
-- @tparam table|BaseComponent|nil whitelist_components The array of component to whitelist
-- @treturn self @{DruidInstance}
function DruidInstance.set_whitelist(self, whitelist_components)
if whitelist_components and whitelist_components.isInstanceOf then
if whitelist_components and whitelist_components._component then
whitelist_components = { whitelist_components }
end

Expand All @@ -501,7 +500,7 @@ end
-- @tparam table|BaseComponent|nil blacklist_components The array of component to blacklist
-- @treturn self @{DruidInstance}
function DruidInstance.set_blacklist(self, blacklist_components)
if blacklist_components and blacklist_components.isInstanceOf then
if blacklist_components and blacklist_components._component then
blacklist_components = { blacklist_components }
end

Expand Down
156 changes: 0 additions & 156 deletions druid/system/middleclass.lua

This file was deleted.

0 comments on commit 067b650

Please sign in to comment.