2024-11-03 19:47:04 +08:00
|
|
|
-- rbuild config settings
|
|
|
|
|
|
|
|
|
|
local ffi = require("ffi")
|
2024-11-21 18:35:34 +08:00
|
|
|
local json = require("lua.json")
|
2024-11-22 20:09:25 +08:00
|
|
|
local logging = require("utils.logging")
|
2024-11-22 07:59:42 +08:00
|
|
|
|
2024-11-03 19:47:04 +08:00
|
|
|
-- ------------------------------------------------------------------------------------------------------
|
|
|
|
|
|
2024-11-17 21:00:11 +08:00
|
|
|
|
|
|
|
|
-- ------------------------------------------------------------------------------------------------------
|
|
|
|
|
-- The main module table
|
2024-11-22 20:09:25 +08:00
|
|
|
local settings = {
|
|
|
|
|
|
|
|
|
|
recents = {},
|
|
|
|
|
}
|
2024-11-17 21:00:11 +08:00
|
|
|
|
|
|
|
|
-- Default settings if none are loaded or found
|
2024-11-07 17:14:49 +08:00
|
|
|
local platforms = { "Win64", "MacOS", "Linux", "IOS64" }
|
2024-12-09 22:30:21 +08:00
|
|
|
local buildtypes = { "Release", "Debug", "Release Remotery", "Debug Remotery" }
|
2024-12-10 13:17:20 +08:00
|
|
|
local resolutions = { "1920x1080", "1680x1050", "1600x900", "1440x900", "1376x768", "Custom" }
|
2024-11-07 17:14:49 +08:00
|
|
|
local arch = { "x86", "x64", "arm", "arm64", "arm64be", "ppc", "mips", "mipsel", "mips64", "mips64el", "mips64r6", "mips64r6el" }
|
|
|
|
|
local oss = { "Windows", "Linux", "OSX", "BSD", "POSIX", "Other" }
|
2024-12-10 13:17:20 +08:00
|
|
|
local optimisations = { "None", "Level 1", "Level 2", "Level 3" }
|
2024-11-07 17:14:49 +08:00
|
|
|
|
2024-12-09 22:30:21 +08:00
|
|
|
settings.default_settings = {
|
2024-11-03 19:47:04 +08:00
|
|
|
|
2024-11-07 09:30:16 +08:00
|
|
|
rbuilder = {
|
2024-11-07 17:14:49 +08:00
|
|
|
appname = { index = 1, value = "rbuild", slen = 7 },
|
|
|
|
|
version = { index = 2, value = "00.01.snow", slen = 32 },
|
2024-11-07 09:30:16 +08:00
|
|
|
},
|
2024-11-03 19:47:04 +08:00
|
|
|
|
2024-11-07 09:30:16 +08:00
|
|
|
platform = {
|
2024-11-07 17:14:49 +08:00
|
|
|
target = { index = 1, value = 1, ptype = "combo", plist = platforms },
|
2024-12-10 13:17:20 +08:00
|
|
|
arch = { index = 2, value = 2, ptype = "combo", plist = arch },
|
|
|
|
|
os = { index = 3, value = 1, ptype = "combo", plist = oss },
|
|
|
|
|
performance = { index = 4, value = 1, ptype = "combo", plist = optimisations },
|
2024-11-07 09:30:16 +08:00
|
|
|
},
|
2024-11-03 19:47:04 +08:00
|
|
|
|
2024-12-09 22:30:21 +08:00
|
|
|
options = {
|
|
|
|
|
build_type = { index = 1, value = 1, ptype = "combo", plist = buildtypes },
|
|
|
|
|
build_relative = { index = 2, value = false, ptype = "check" },
|
|
|
|
|
build_bytecode = { index = 3, value = true, ptype = "check" },
|
|
|
|
|
},
|
|
|
|
|
|
2024-11-07 09:30:16 +08:00
|
|
|
project = {
|
2024-11-17 21:00:11 +08:00
|
|
|
project_name = { index = 1, value = "default", ptype = "string", slen = 64 },
|
2024-11-21 18:35:34 +08:00
|
|
|
build_path = { index = 2, value = "<change me>", ptype = "path", slen = 256 }, -- Always starts empty. Will support a project file.
|
|
|
|
|
project_start = { index = 3, value = "example1.lua", ptype = "file", pfilter = "*.lua", slen = 128 },
|
2024-11-07 09:30:16 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
|
|
graphics = {
|
2024-12-10 13:17:20 +08:00
|
|
|
-- If custom is set then width and height can be customized as needed
|
2024-11-07 17:14:49 +08:00
|
|
|
display_res = { index = 1, value = 1, ptype = "combo", plist = resolutions },
|
|
|
|
|
display_width = { index = 2, value = 1024, vmin = 640, vmax = 8192, vstep = 32, vinc = 0.1, ptype = "int" },
|
|
|
|
|
display_height = { index = 3, value = 768, vmin = 480, vmax = 8192, vstep = 32, vinc = 0.1, ptype = "int" },
|
|
|
|
|
display_fps = { index = 4, value = 60, vmin = 25, vmax = 200, vstep = 5, vinc = 0.1, ptype = "int" },
|
2024-12-10 13:17:20 +08:00
|
|
|
antialias = { index = 5, value = "fxaa", slen = 16, ptype = "string" },
|
|
|
|
|
fullscreen = { index = 6, value = false, ptype = "check" },
|
2024-11-07 09:30:16 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
|
|
audio = {
|
2024-12-10 13:17:20 +08:00
|
|
|
-- For tweaking deploy audio defaults
|
2024-11-07 17:14:49 +08:00
|
|
|
master_volume = { index = 1, value = 1.0, vmin = 0.0, vmax = 1.0, vstep = 0.02, vinc = 0.1, ptype = "float" },
|
|
|
|
|
effects_volume = { index = 2, value = 1.0, vmin = 0.0, vmax = 1.0, vstep = 0.02, vinc = 0.1, ptype = "float" },
|
|
|
|
|
music_volume = { index = 3, value = 1.0, vmin = 0.0, vmax = 1.0, vstep = 0.02, vinc = 0.1, ptype = "float" },
|
2024-11-07 09:30:16 +08:00
|
|
|
},
|
2024-11-03 19:47:04 +08:00
|
|
|
|
2024-11-07 09:30:16 +08:00
|
|
|
sokol = {
|
2024-11-13 17:11:06 +08:00
|
|
|
sokol_path = { index = 1, value = "../../../../", ptype = "path", slen = 256 },
|
|
|
|
|
sokol_bin = { index = 2, value = "bin/", ptype = "path", slen = 256 },
|
|
|
|
|
sokol_ffi = { index = 3, value = "ffi/", ptype = "path", slen = 256 },
|
|
|
|
|
sokol_lua = { index = 4, value = "lua/", ptype = "path", slen = 256 },
|
|
|
|
|
sokol_examples = { index = 5, value = "examples/", ptype = "path", slen = 256 },
|
2024-11-07 09:30:16 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
|
|
remote = {
|
|
|
|
|
-- These are futures --
|
2024-11-07 17:14:49 +08:00
|
|
|
remote_build = { index = 1, value = "https://mybuildserver.com/sokol_build", slen = 256 },
|
|
|
|
|
remote_data = { index = 2, value = "https://myremotedata.com/data", slen = 256 },
|
2024-11-07 09:30:16 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
|
|
-- Assets will be populated by project file
|
|
|
|
|
assets = {
|
2024-11-17 21:00:11 +08:00
|
|
|
lua = {},
|
|
|
|
|
images = {},
|
|
|
|
|
data = {},
|
2024-11-07 09:30:16 +08:00
|
|
|
},
|
2024-11-03 19:47:04 +08:00
|
|
|
}
|
|
|
|
|
|
2024-11-17 21:00:11 +08:00
|
|
|
-- ------------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
local function loadconfig(projectpath)
|
|
|
|
|
|
|
|
|
|
local res = nil
|
|
|
|
|
local fh = io.open(projectpath, "r")
|
|
|
|
|
if(fh) then
|
|
|
|
|
res = fh:read("*a")
|
|
|
|
|
fh:close()
|
2024-11-22 07:59:42 +08:00
|
|
|
if(res == nil or #res == 0) then
|
2024-11-27 19:29:57 +08:00
|
|
|
logging.error("loadconfig - cannot read settings file: "..projectpath)
|
2024-11-22 07:59:42 +08:00
|
|
|
res = nil
|
|
|
|
|
else
|
|
|
|
|
res = json.decode(res)
|
|
|
|
|
end
|
2024-11-17 21:00:11 +08:00
|
|
|
else
|
2024-11-27 19:29:57 +08:00
|
|
|
logging.error("settings.load - unable to load config: "..projectpath)
|
2024-11-17 21:00:11 +08:00
|
|
|
end
|
|
|
|
|
return res
|
|
|
|
|
end
|
2024-11-03 19:47:04 +08:00
|
|
|
|
|
|
|
|
-- ------------------------------------------------------------------------------------------------------
|
|
|
|
|
|
2024-11-22 20:09:25 +08:00
|
|
|
settings.add_recents = function( filename )
|
|
|
|
|
|
|
|
|
|
if(settings.recents) then
|
|
|
|
|
|
|
|
|
|
-- Check it isnt already in the list, add to first and remove the other.
|
2024-11-23 08:33:02 +08:00
|
|
|
local cleaned_recents = {}
|
|
|
|
|
|
2024-11-22 20:09:25 +08:00
|
|
|
for i, v in ipairs(settings.recents) do
|
2024-11-23 08:33:02 +08:00
|
|
|
local testf = string.gsub(filename, "%-", "_")
|
|
|
|
|
local testv = string.gsub(v, "%-", "_")
|
|
|
|
|
if string.match(testf, testv) then
|
|
|
|
|
else
|
|
|
|
|
table.insert(cleaned_recents, v)
|
|
|
|
|
end
|
2024-11-22 20:09:25 +08:00
|
|
|
end
|
2024-11-23 08:33:02 +08:00
|
|
|
settings.recents = cleaned_recents
|
2024-11-22 20:09:25 +08:00
|
|
|
table.insert(settings.recents, 1, filename)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-- ------------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
settings.load_recents = function( )
|
2024-11-17 21:00:11 +08:00
|
|
|
|
2024-11-21 18:35:34 +08:00
|
|
|
-- Grab the recents file list too.
|
|
|
|
|
local fh = io.open("config/recent_projects.json", "r")
|
|
|
|
|
if(fh) then
|
2024-11-22 20:09:25 +08:00
|
|
|
settings.recents = json.decode( fh:read("*a") )
|
2024-11-17 21:00:11 +08:00
|
|
|
fh:close()
|
2024-11-22 20:09:25 +08:00
|
|
|
else
|
2024-11-27 19:29:57 +08:00
|
|
|
logging.error("settings.load_recents: Cannot load recents.")
|
2024-11-22 20:09:25 +08:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- ------------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
settings.save_recents = function( )
|
|
|
|
|
|
|
|
|
|
-- Grab the recents file list too.
|
|
|
|
|
if(settings.recents) then
|
|
|
|
|
local fh = io.open("config/recent_projects.json", "w")
|
|
|
|
|
if(fh) then
|
|
|
|
|
fh:write(json.encode( settings.recents ))
|
|
|
|
|
fh:close()
|
2024-11-27 19:29:57 +08:00
|
|
|
logging.info("settings.save_recents.")
|
2024-11-22 20:09:25 +08:00
|
|
|
else
|
2024-11-27 19:29:57 +08:00
|
|
|
logging.error("settings.save_recents: Cannot save recents.")
|
2024-11-22 20:09:25 +08:00
|
|
|
end
|
2024-11-17 21:00:11 +08:00
|
|
|
end
|
2024-11-22 20:09:25 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- ------------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
settings.load = function( projectpath )
|
2024-11-17 21:00:11 +08:00
|
|
|
|
2024-11-21 18:35:34 +08:00
|
|
|
if( projectpath == nil ) then
|
2024-11-27 19:29:57 +08:00
|
|
|
logging.info("settings.load projectpath nil, using default settings.")
|
2024-12-09 22:30:21 +08:00
|
|
|
settings.config = settings.default_settings
|
2024-11-21 18:35:34 +08:00
|
|
|
else
|
|
|
|
|
-- Load the project settings into the local config
|
|
|
|
|
settings.config = loadconfig(projectpath)
|
2024-11-27 19:29:57 +08:00
|
|
|
if(settings.config == nil) then
|
|
|
|
|
logging.error("settings.load invalid projectpath nil, using default settings.")
|
2024-12-09 22:30:21 +08:00
|
|
|
settings.config = settings.default_settings
|
2024-11-27 19:29:57 +08:00
|
|
|
end
|
2024-11-21 18:35:34 +08:00
|
|
|
end
|
2024-11-17 21:00:11 +08:00
|
|
|
|
|
|
|
|
local title = settings.config.rbuilder.appname.value.." ("..settings.config.rbuilder.version.value..")"
|
|
|
|
|
settings.config.rbuilder.title = { value = title, slen = 32 }
|
2024-11-22 20:09:25 +08:00
|
|
|
|
2024-11-17 21:00:11 +08:00
|
|
|
return settings.config
|
|
|
|
|
end
|
2024-11-03 19:47:04 +08:00
|
|
|
|
|
|
|
|
-- ------------------------------------------------------------------------------------------------------
|
|
|
|
|
|
2024-11-22 07:59:42 +08:00
|
|
|
settings.save = function( projectpath )
|
|
|
|
|
|
|
|
|
|
-- Grab the recents file list too.
|
|
|
|
|
settings.recent = nil
|
|
|
|
|
local fh = io.open(projectpath, "w")
|
|
|
|
|
if(fh) then
|
|
|
|
|
fh:write( json.encode(settings.config) )
|
|
|
|
|
fh:close()
|
2024-11-27 19:29:57 +08:00
|
|
|
else
|
|
|
|
|
logging.error("settings.save - Failed to save config: "..tostring(projectpath))
|
2024-11-22 07:59:42 +08:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- ------------------------------------------------------------------------------------------------------
|
|
|
|
|
|
2024-11-03 19:47:04 +08:00
|
|
|
return settings
|
|
|
|
|
|
|
|
|
|
-- ------------------------------------------------------------------------------------------------------
|