mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2025-12-30 12:31:41 +09:00
Changed store to use a single function
This commit is contained in:
@@ -112,12 +112,12 @@ function Checkbox.new_checkbox(name)
|
||||
|
||||
if self.option_set then
|
||||
local value = Checkbox.option_sets[self.option_set][element.name]
|
||||
local category = self.categorize and self.categorize(element) or value
|
||||
local category = self.categorize and self.categorize(element)
|
||||
self:set_store(category,value)
|
||||
|
||||
elseif self.store then
|
||||
local value = element.state
|
||||
local category = self.categorize and self.categorize(element) or value
|
||||
local category = self.categorize and self.categorize(element)
|
||||
self:set_store(category,value)
|
||||
|
||||
else
|
||||
@@ -166,12 +166,7 @@ end
|
||||
function Checkbox._prototype_radiobutton:get_store(category,internal)
|
||||
if not self.store then return end
|
||||
local location = not internal and self.option_set or self.store
|
||||
|
||||
if self.categorize then
|
||||
return Store.get_child(location,category)
|
||||
else
|
||||
return Store.get(location)
|
||||
end
|
||||
return Store.get(location,category)
|
||||
end
|
||||
|
||||
--- Sets the stored value of the radiobutton or the option set if present
|
||||
@@ -182,12 +177,7 @@ end
|
||||
function Checkbox._prototype_radiobutton:set_store(category,value,internal)
|
||||
if not self.store then return end
|
||||
local location = not internal and self.option_set or self.store
|
||||
|
||||
if self.categorize then
|
||||
return Store.set_child(location,category,value)
|
||||
else
|
||||
return Store.set(location,category)
|
||||
end
|
||||
return Store.set(location,category,value)
|
||||
end
|
||||
|
||||
--- Registers a new option set that can be linked to radiobutotns (only one can be true at a time)
|
||||
|
||||
@@ -255,7 +255,7 @@ function Gui._sync_store_factory(callback)
|
||||
|
||||
Instances.register(self.name,self.categorize)
|
||||
|
||||
Store.register_synced(self.store,function(value,category)
|
||||
Store.register(self.store,true,function(value,category)
|
||||
if self.events.on_store_update then
|
||||
self.events.on_store_update(value,category)
|
||||
end
|
||||
@@ -419,24 +419,24 @@ end
|
||||
-- @treturn any the value that is stored for this define
|
||||
function Gui._prototype:get_store(category)
|
||||
if not self.store then return end
|
||||
if self.categorize then
|
||||
return Store.get_child(self.store,category)
|
||||
else
|
||||
return Store.get(self.store)
|
||||
end
|
||||
return Store.get(self.store,category)
|
||||
end
|
||||
|
||||
--- Sets the value in this elements store, category needed if categorize function used
|
||||
-- @tparam string category[opt] the category to get such as player name or force name
|
||||
-- @tparam boolean any value the value to set for this define, must be valid for its type ie for checkbox etc
|
||||
-- @tparam any value the value to set for this define, must be valid for its type ie for checkbox etc
|
||||
-- @treturn boolean true if the value was set
|
||||
function Gui._prototype:set_store(category,value)
|
||||
if not self.store then return end
|
||||
if self.categorize then
|
||||
return Store.set_child(self.store,category,value)
|
||||
else
|
||||
return Store.set(self.store,category)
|
||||
end
|
||||
return Store.set(self.store,category,value)
|
||||
end
|
||||
|
||||
--- Sets the value in this elements store to nil, category needed if categorize function used
|
||||
-- @tparam[opt] string category the category to get such as player name or force name
|
||||
-- @treturn boolean true if the value was set
|
||||
function Gui._prototype:clear_store(category)
|
||||
if not self.store then return end
|
||||
return Store.clear(self.store,category)
|
||||
end
|
||||
|
||||
--- Gets an element define give the uid, debug name or a copy of the element define
|
||||
|
||||
@@ -250,8 +250,7 @@ local function change_value_prototype(self,amount,category,filter)
|
||||
|
||||
local function reset_store()
|
||||
local value = self.count_down and 1 or 0
|
||||
local _category = category or value
|
||||
self:set_store(_category,value)
|
||||
self:set_store(category,value)
|
||||
end
|
||||
|
||||
if self.store then
|
||||
@@ -261,15 +260,13 @@ local function change_value_prototype(self,amount,category,filter)
|
||||
|
||||
if self.count_down and new_value <= 0
|
||||
or not self.count_down and new_value >= 1 then
|
||||
self:set_store(category)
|
||||
self:clear_store(category)
|
||||
|
||||
if self.events.on_store_complete then
|
||||
category = category or reset_store
|
||||
self.events.on_store_complete(category,reset_store)
|
||||
end
|
||||
end
|
||||
|
||||
category = category or new_value
|
||||
self:set_store(category,new_value)
|
||||
|
||||
return
|
||||
|
||||
@@ -652,7 +652,7 @@ Event.add(defines.events.on_tick,function()
|
||||
progressbar_one:increment()
|
||||
progressbar_three:decrement()
|
||||
local categories = Store.get_children(progressbar_two.store)
|
||||
for category,_ in pairs(categories) do
|
||||
for _,category in pairs(categories) do
|
||||
progressbar_two:increment(1,category)
|
||||
end
|
||||
end)
|
||||
|
||||
Reference in New Issue
Block a user