mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2025-12-31 04:51:40 +09:00
First Test Success
This commit is contained in:
@@ -51,5 +51,5 @@ return {
|
|||||||
'config.expcore-commands.auth_runtime_disable', -- allows commands to be enabled and disabled during runtime
|
'config.expcore-commands.auth_runtime_disable', -- allows commands to be enabled and disabled during runtime
|
||||||
'config.permission_groups', -- loads some predefined permission groups
|
'config.permission_groups', -- loads some predefined permission groups
|
||||||
'config.roles', -- loads some predefined roles
|
'config.roles', -- loads some predefined roles
|
||||||
--'expcore.gui.test' -- loads multiple gui defines to test the gui system
|
'expcore.gui.test' -- loads multiple gui defines to test the gui system
|
||||||
}
|
}
|
||||||
@@ -17,6 +17,31 @@ end)
|
|||||||
properties.caption = nil
|
properties.caption = nil
|
||||||
properties.type = 'sprite-button'
|
properties.type = 'sprite-button'
|
||||||
end)
|
end)
|
||||||
|
:define_draw(function(properties,parent,element)
|
||||||
|
-- Note that element might be nil if this is the first draw function
|
||||||
|
-- in this case button is a new concept so we know this is the first function and element is nil
|
||||||
|
if properties.type == 'button' then
|
||||||
|
element = parent.draw{
|
||||||
|
type = properties.type,
|
||||||
|
name = properties.name,
|
||||||
|
caption = properties.caption,
|
||||||
|
tooltip = properties.tooltip
|
||||||
|
}
|
||||||
|
|
||||||
|
else
|
||||||
|
element = parent.draw{
|
||||||
|
type = properties.type,
|
||||||
|
name = properties.name,
|
||||||
|
sprite = properties.sprite,
|
||||||
|
tooltip = properties.tooltip
|
||||||
|
}
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
-- We must return the element or what we want to be seen as the instance, this is so other draw functions have access to it
|
||||||
|
-- for example if our custom button defined a draw function to change the font color to red
|
||||||
|
return element
|
||||||
|
end)
|
||||||
|
|
||||||
@usage-- Makeing a alternative button based on the first
|
@usage-- Makeing a alternative button based on the first
|
||||||
local custom_button =
|
local custom_button =
|
||||||
|
|||||||
@@ -14,21 +14,53 @@ local Gui = {
|
|||||||
concepts = {}
|
concepts = {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
--[[-- Gets the gui concept with this name
|
||||||
|
@tparam string name the name of the concept that you want to get
|
||||||
|
@usage-- Getting a gui concept
|
||||||
|
local button = Gui.get_concept('Button')
|
||||||
|
]]
|
||||||
|
function Gui.get_concept(name)
|
||||||
|
return Gui.concepts[name] or error('Gui concept "'..name..'" is not defind',2)
|
||||||
|
end
|
||||||
|
|
||||||
|
--[[-- Used internally to save concept names to the core gui module
|
||||||
|
@function Prototype:change_name
|
||||||
|
@tparam[opt=self.name] string new_name the new name of the concept
|
||||||
|
@usage-- Internal Saving
|
||||||
|
-- this is never needed to be done, internal use only!
|
||||||
|
local button = Gui.get_concept('Button')
|
||||||
|
button:change_name('Not Button')
|
||||||
|
]]
|
||||||
|
function Prototype:change_name(new_name)
|
||||||
|
if new_name then
|
||||||
|
Gui.concepts[self.name] = nil
|
||||||
|
self.name = new_name
|
||||||
|
self.properties.name = new_name
|
||||||
|
end
|
||||||
|
|
||||||
|
Gui.concepts[self.name] = self
|
||||||
|
return self
|
||||||
|
end
|
||||||
|
|
||||||
|
--[[-- Returns a new gui concept with no properties or events
|
||||||
|
@tparam string name the name that you want this concept to have
|
||||||
|
@usage-- Making a new concept, see module usage
|
||||||
|
local button = Gui.new_concept('Button')
|
||||||
|
]]
|
||||||
function Gui.new_concept(name)
|
function Gui.new_concept(name)
|
||||||
if Gui.concepts[name] then
|
if Gui.concepts[name] then
|
||||||
error('Gui concept "'..name..'" is already defind',2)
|
error('Gui concept "'..name..'" is already defind',2)
|
||||||
end
|
end
|
||||||
|
|
||||||
local concept = Prototype:clone(name)
|
return Prototype:clone(name)
|
||||||
Gui.concepts[name] = concept
|
|
||||||
|
|
||||||
return concept
|
|
||||||
end
|
|
||||||
|
|
||||||
function Gui.get_concept(name)
|
|
||||||
return Gui.concepts[name] or error('Gui concept "'..name..'" is not defind',2)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--[[-- Making anew concept based on the properties and drawing of another
|
||||||
|
@tparam string name the name of the concept that you want as the base
|
||||||
|
@tparam string new_name the name that you want the new concept to have
|
||||||
|
@usage-- Making a new concept from another, see module usage
|
||||||
|
local custom_button = Gui.clone_concept('Button','CustomButton')
|
||||||
|
]]
|
||||||
function Gui.clone_concept(name,new_name)
|
function Gui.clone_concept(name,new_name)
|
||||||
local concept = Gui.concepts[name] or error('Gui concept "'..name..'" is not defind',2)
|
local concept = Gui.concepts[name] or error('Gui concept "'..name..'" is not defind',2)
|
||||||
|
|
||||||
@@ -36,10 +68,7 @@ function Gui.clone_concept(name,new_name)
|
|||||||
error('Gui concept "'..name..'" is already defind',2)
|
error('Gui concept "'..name..'" is already defind',2)
|
||||||
end
|
end
|
||||||
|
|
||||||
local new_concept = concept:clone(new_name)
|
return concept:clone(new_name)
|
||||||
Gui.concepts[new_name] = new_concept
|
|
||||||
|
|
||||||
return new_concept
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return Gui
|
return Gui
|
||||||
@@ -18,6 +18,31 @@ end)
|
|||||||
properties.caption = nil
|
properties.caption = nil
|
||||||
properties.type = 'sprite-button'
|
properties.type = 'sprite-button'
|
||||||
end)
|
end)
|
||||||
|
:define_draw(function(properties,parent,element)
|
||||||
|
-- Note that element might be nil if this is the first draw function
|
||||||
|
-- in this case button is a new concept so we know this is the first function and element is nil
|
||||||
|
if properties.type == 'button' then
|
||||||
|
element = parent.draw{
|
||||||
|
type = properties.type,
|
||||||
|
name = properties.name,
|
||||||
|
caption = properties.caption,
|
||||||
|
tooltip = properties.tooltip
|
||||||
|
}
|
||||||
|
|
||||||
|
else
|
||||||
|
element = parent.draw{
|
||||||
|
type = properties.type,
|
||||||
|
name = properties.name,
|
||||||
|
sprite = properties.sprite,
|
||||||
|
tooltip = properties.tooltip
|
||||||
|
}
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
-- We must return the element or what we want to be seen as the instance, this is so other draw functions have access to it
|
||||||
|
-- for example if our custom button defined a draw function to change the font color to red
|
||||||
|
return element
|
||||||
|
end)
|
||||||
|
|
||||||
local custom_button =
|
local custom_button =
|
||||||
button:clone('CustomButton')
|
button:clone('CustomButton')
|
||||||
@@ -117,9 +142,27 @@ function Prototype:clone(concept_name)
|
|||||||
concept.set_store_from_instance = nil
|
concept.set_store_from_instance = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Sets the concept name
|
||||||
|
concept:change_name()
|
||||||
|
|
||||||
return concept
|
return concept
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--[[-- Used internally to save concept names to the core gui module
|
||||||
|
@function Prototype:change_name
|
||||||
|
@tparam[opt=self.name] string new_name the new name of the concept
|
||||||
|
@usage-- Internal Saving
|
||||||
|
-- this is never needed to be done, internal use only!
|
||||||
|
local button = Gui.get_concept('Button')
|
||||||
|
button:change_name('Not Button')
|
||||||
|
]]
|
||||||
|
function Prototype:change_name(new_name)
|
||||||
|
-- over writen in core file
|
||||||
|
self.name = new_name or self.name
|
||||||
|
self.properties.name = self.name
|
||||||
|
return self
|
||||||
|
end
|
||||||
|
|
||||||
--[[-- Adds a new event trigger to the concept which can be linked to a factorio event
|
--[[-- Adds a new event trigger to the concept which can be linked to a factorio event
|
||||||
@tparam string event_name the name of the event to add, must be unique, recomented to start with "on_"
|
@tparam string event_name the name of the event to add, must be unique, recomented to start with "on_"
|
||||||
@tparam[opt] defines.events factorio_event when given will fire the custom event when the factorio event is raised
|
@tparam[opt] defines.events factorio_event when given will fire the custom event when the factorio event is raised
|
||||||
@@ -293,6 +336,7 @@ Gui.get_concept('Button')
|
|||||||
:define_draw(function(properties,parent,element)
|
:define_draw(function(properties,parent,element)
|
||||||
-- Note that element might be nil if this is the first draw function
|
-- Note that element might be nil if this is the first draw function
|
||||||
-- for this example we assume button was cloned from Prototype and so has no other draw functions defined
|
-- for this example we assume button was cloned from Prototype and so has no other draw functions defined
|
||||||
|
-- this means that there is no element yet and what we return will be the first time the element is returned
|
||||||
-- although not shown here you also can recive any extra arguments here from the call to draw
|
-- although not shown here you also can recive any extra arguments here from the call to draw
|
||||||
if properties.type == 'button' then
|
if properties.type == 'button' then
|
||||||
element = parent.draw{
|
element = parent.draw{
|
||||||
@@ -312,8 +356,8 @@ Gui.get_concept('Button')
|
|||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- We must return the element or what we want to be seen as the instance
|
-- We must return the element or what we want to be seen as the instance, this is so other draw functions have access to it
|
||||||
-- this is so other draw functions have access to it, say if our custom button defined a draw function to change the font color to red
|
-- for example if our custom button defined a draw function to change the font color to red
|
||||||
return element
|
return element
|
||||||
end)
|
end)
|
||||||
]]
|
]]
|
||||||
|
|||||||
93
expcore/gui/test.lua
Normal file
93
expcore/gui/test.lua
Normal file
@@ -0,0 +1,93 @@
|
|||||||
|
--[[-- Core Module - Gui
|
||||||
|
@module Gui
|
||||||
|
@alias Gui
|
||||||
|
]]
|
||||||
|
|
||||||
|
local Gui = require 'expcore.gui'
|
||||||
|
|
||||||
|
local tests = {}
|
||||||
|
|
||||||
|
--[[-- Runs a set of gui tests to ensure that the system is working
|
||||||
|
@tparam LuaPlayer player the player that the guis are made for and who recives the results
|
||||||
|
@tparam[opt] string category when given only tests in this category are ran
|
||||||
|
@usage-- Run all gui tests
|
||||||
|
Gui.run_tests(Gui.test_string_return(game.print))
|
||||||
|
]]
|
||||||
|
function Gui.run_tests(player,category)
|
||||||
|
local results = {
|
||||||
|
passed = 0,
|
||||||
|
failed = 0,
|
||||||
|
total = 0,
|
||||||
|
errors = {}
|
||||||
|
}
|
||||||
|
|
||||||
|
if not category then
|
||||||
|
results.breakdown = {}
|
||||||
|
|
||||||
|
for cat,_ in pairs(tests) do
|
||||||
|
local rtn = Gui.run_tests(player,cat)
|
||||||
|
results.passed = results.passed + rtn.passed
|
||||||
|
results.failed = results.failed + rtn.failed
|
||||||
|
results.total = results.total + rtn.total
|
||||||
|
|
||||||
|
for test_name, err in pairs(rtn.errors) do
|
||||||
|
results.errors[cat..'/'..test_name] = err
|
||||||
|
end
|
||||||
|
|
||||||
|
results.breakdown[cat] = rtn
|
||||||
|
end
|
||||||
|
|
||||||
|
player.print(string.format('All Tests Complete. %d failed.',results.failed))
|
||||||
|
|
||||||
|
return results
|
||||||
|
end
|
||||||
|
|
||||||
|
local cat_tests = tests[category]
|
||||||
|
|
||||||
|
results.total = #cat_tests
|
||||||
|
|
||||||
|
local output = player.print
|
||||||
|
for test_name, callback in pairs(cat_tests) do
|
||||||
|
local success, err = pcall(callback,player)
|
||||||
|
|
||||||
|
if success then
|
||||||
|
results.passed = results.passed + 1
|
||||||
|
else
|
||||||
|
results.erorrs[test_name] = err
|
||||||
|
output(string.format('Test "%s / %s" failed:\n%s',category,test_name,err))
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
output(string.format('Test Complete "%s". %d failed.',category,results.failed))
|
||||||
|
|
||||||
|
return results
|
||||||
|
end
|
||||||
|
|
||||||
|
--[[
|
||||||
|
Basic frame creation
|
||||||
|
]]
|
||||||
|
|
||||||
|
local test_frame =
|
||||||
|
Gui.new_concept('test_frame')
|
||||||
|
:define_draw(function(properties,parent,element)
|
||||||
|
element =
|
||||||
|
parent.add{
|
||||||
|
name = properties.name,
|
||||||
|
type = 'frame',
|
||||||
|
caption = 'Gui Tests'
|
||||||
|
}
|
||||||
|
|
||||||
|
element.add{
|
||||||
|
type = 'label',
|
||||||
|
caption = 'Hello, World!'
|
||||||
|
}
|
||||||
|
|
||||||
|
return element
|
||||||
|
end)
|
||||||
|
|
||||||
|
tests.Frame = {
|
||||||
|
['Draw Frame'] = function(player)
|
||||||
|
test_frame:draw(player.gui.center)
|
||||||
|
end
|
||||||
|
}
|
||||||
@@ -16,7 +16,7 @@ local interface_modules = {
|
|||||||
['Group']='expcore.permission_groups',
|
['Group']='expcore.permission_groups',
|
||||||
['Roles']='expcore.roles',
|
['Roles']='expcore.roles',
|
||||||
['Store']='expcore.store',
|
['Store']='expcore.store',
|
||||||
--['Gui']='expcore.gui',
|
['Gui']='expcore.gui',
|
||||||
['Sudo']='expcore.sudo'
|
['Sudo']='expcore.sudo'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user