diff options
Diffstat (limited to 'gamemode')
| -rw-r--r-- | gamemode/config/sv_sql.lua | 2 | ||||
| -rw-r--r-- | gamemode/core/database/sv_setup.lua | 4 | ||||
| -rw-r--r-- | gamemode/core/mapstich/sv_mapstich.lua | 4 | ||||
| -rw-r--r-- | gamemode/core/npc/sh_npcsystem.lua | 15 | ||||
| -rw-r--r-- | gamemode/inventorysystem/abilities/sh_abilities.lua | 2 | ||||
| -rw-r--r-- | gamemode/nrequire.lua | 116 | ||||
| -rw-r--r-- | gamemode/shared.lua | 6 | ||||
| -rw-r--r-- | gamemode/shared/log.lua | 20 | ||||
| -rw-r--r-- | gamemode/utility/svg/cl_svg.lua | 23 |
9 files changed, 158 insertions, 34 deletions
diff --git a/gamemode/config/sv_sql.lua b/gamemode/config/sv_sql.lua index 501f8e1..dc2599e 100644 --- a/gamemode/config/sv_sql.lua +++ b/gamemode/config/sv_sql.lua @@ -26,7 +26,7 @@ local parse = { [""] = function() return nil end } local default_file = [[ -EnableMySQL=true +EnableMySQL=false Host=localhost Username=root Password=root diff --git a/gamemode/core/database/sv_setup.lua b/gamemode/core/database/sv_setup.lua index 4aba3db..a79287a 100644 --- a/gamemode/core/database/sv_setup.lua +++ b/gamemode/core/database/sv_setup.lua @@ -57,7 +57,9 @@ local function connect() end end hook.Add("DatabaseInitialized","setup_table",function() - assert(MySQLite.isMySQL(),"Database wasn't mysqloo, something is probably wrong!") + if not MySQLite.isMySQL() then + log.warn("Database wasn't mysqloo, something is probably wrong!") + end local setup_success = function(res,li) log.info("Set up playerdata table") --print("Set up connection to db") diff --git a/gamemode/core/mapstich/sv_mapstich.lua b/gamemode/core/mapstich/sv_mapstich.lua index 11b4540..7e5a963 100644 --- a/gamemode/core/mapstich/sv_mapstich.lua +++ b/gamemode/core/mapstich/sv_mapstich.lua @@ -10,7 +10,9 @@ local log = nrequire("log.lua") --if not zones then error("This thing needs zones to function!") end hook.Add("DatabaseInitialized","initalize_mapstich",function() - assert(MySQLite.isMySQL(),"Database wasn't mysqloo, something is probably wrong!") + if not MySQLite.isMySQL() then + log.warn("Database wasn't mysqloo, something is probably wrong!") + end end) util.AddNetworkString("art_zonechange") diff --git a/gamemode/core/npc/sh_npcsystem.lua b/gamemode/core/npc/sh_npcsystem.lua index 9b43965..5b93f1e 100644 --- a/gamemode/core/npc/sh_npcsystem.lua +++ b/gamemode/core/npc/sh_npcsystem.lua @@ -115,11 +115,16 @@ local function loadMap() local foldername = "artery/maps/" .. mapname ExecuteOnFolder(foldername,true,function(path) - print("I want to run",path) - local filetxt = file.Read(path,"DATA") - --print("File text is", filetxt) - CompileString(filetxt,path)() - --print("I want to execute",path) + local filename = path:match("/([^/]+)$") + print("I want to run",path, ";", filename) + local is_server = filename:match("^sv_") + local is_client = filename:match("^cl_") + if (is_client and CLIENT) or (is_server and SERVER) or (not is_server and not is_client) then + local filetxt = file.Read(path,"DATA") + --print("File text is", filetxt) + CompileString(filetxt,path)() + --print("I want to execute",path) + end end) end diff --git a/gamemode/inventorysystem/abilities/sh_abilities.lua b/gamemode/inventorysystem/abilities/sh_abilities.lua index fc6cd82..53c7d57 100644 --- a/gamemode/inventorysystem/abilities/sh_abilities.lua +++ b/gamemode/inventorysystem/abilities/sh_abilities.lua @@ -8,7 +8,7 @@ local reg = nrequire("inventory/inventory.lua") local itm = nrequire("item.lua") local inv = {} if CLIENT then - inv = nrequire("cl_prayers.lua") + inv = nrequire("cl_abilities.lua") end inv.Name = "Abilities" diff --git a/gamemode/nrequire.lua b/gamemode/nrequire.lua index ab1c191..5f0a063 100644 --- a/gamemode/nrequire.lua +++ b/gamemode/nrequire.lua @@ -1,11 +1,15 @@ ---[[ - A thing that kinda works like require, or at least, works how I wish require worked. +--[[ A thing that kinda works like require, or at least, works how I wish require worked. calls hooks: artery_nrequire_defined artery_core_loaded + +The interface is pretty good, but it needs a rewrite to add state machines, one for each file so that refreshes are more sane. ]] if nrequire ~= nil then return end +local nrequire_debugging = false +local debug_file = "artery_log.txt" + --The files we want clients to load local clienttoload = {} @@ -15,6 +19,22 @@ local searchpaths = { {"data/artery/global","GAME"}, } +nrequire = {} + +local watched_paths = {} +function nrequire.watch(func, path, path_part) + table.insert(watched_paths,{func,path,path_part}) +end + +local search_paths = {} +function nrequire.addSearchPath(path, path_part) + table.insert(search_paths, path, path_part) +end +nrequire.addSearchPath("gamemodes/artery/gamemode","GAME") +nrequire.addSearchPath("artery/global","DATA") +nrequire.addSearchPath("data/artery/global","GAME") + + if SERVER then --Network messages util.AddNetworkString("artery_downloadfile") @@ -100,6 +120,7 @@ local function collect_paths(pretbl) return ret end +local file_wtc = {} -- A write through cache for files on the client --[[ Scans the prefix table built by rebuild_include_table to find the file path for the partial name of an included file. If two files are named the same, you will need to include part of the file path until it can be resolved. @@ -136,6 +157,21 @@ local lastcall = {} --Holds when things were loaded local location = {} --Holds the location of files ("DATA","GAME","LUA",...) local deptbl = {} --Holds the dependencies between files local pathstack = {} + +local function nrequire_err(msg,throw) + local msgcolor,err_f + if CLIENT then + msgcolor = Color(209,96,196) + else + msgcolor = Color(160,49,150) + end + MsgC(msgcolor,msg) + if throw then + error(debug.traceback()) + else + MsgC(msgcolor,debug.traceback()) + end +end function nrequire(req,...) local varargs = {...} local tpath-- Find the full path for the nrequired() module @@ -149,8 +185,7 @@ function nrequire(req,...) tpath = scan(ntbl,req) end if tpath == nil then - MsgC(Color(209,96,196), "Unable to find file for include:" .. req) - error(debug.traceback()) + nrequire_err("Unable to find file for include:" .. req, true) end local trace = debug.getinfo(2,"flnSu") @@ -197,8 +232,7 @@ function nrequire(req,...) lastcall[tpath[1]] = os.time() location[tpath[1]] = tpath[2] end,function(err) - MsgC(Color(209,96,196),debug.traceback(),"\n") - MsgC(Color(209,96,196),"nrequire Error:",err,"\n") + nrequire_err("nrequire Error:" .. err .. "\n") end) end @@ -209,9 +243,11 @@ function nrequire(req,...) end local update_file_co = coroutine.create(function() + if CLIENT then return end while true do for k,v in pairs(reqtbl) do local loc = location[k] + print(string.format("Checking file %s at %s",k,loc)) if file.Time(k,loc) > lastcall[k] then print(string.format("Found updated file:%s",k)) nrequire(k) @@ -231,16 +267,18 @@ local update_file_co = coroutine.create(function() net.WriteString(file.Read(k,loc)) net.Broadcast() end - coroutine.yield() + for i = 1,100 do + coroutine.yield() + end end end end) -hook.Add("Tick","nrequire_update_tick",function() - if coroutine.status(update_file_co) == "suspended" then - coroutine.resume(update_file_co) - end -end) +--hook.Add("Tick","nrequire_update_tick",function() + --if coroutine.status(update_file_co) == "suspended" then + --coroutine.resume(update_file_co) + --end +--end) if SERVER then net.Receive("artery_requestcsfile",function(ln,ply) @@ -267,8 +305,7 @@ else xpcall(function() ret = ptr() end,function(err) - MsgC(Color(209,96,196),debug.traceback(),"\n") - MsgC(Color(209,96,196),"nrequire Error:",err,"\n") + nrequire_err("nrequire Error:" .. err .. "\n") end) else error(ptr) @@ -411,6 +448,9 @@ if SERVER then print("artery_request_client_download received by server") downloadclient(pl) end) + net.Receive("art_requestclientreload",function(ln,pl) + downloadclient(pl) + end) net.Receive("art_requestfile",function(ln,pl) local filedata = net.ReadTable() local filetxt = file.Read(filedata.name,filedata.directory) @@ -477,9 +517,16 @@ else file.CreateDir(path) print("Writing to ", fullpath) file.Write(fullpath,tbl.text) - nrequire(tbl.name) - --timer.Simple(10,function() RunConsoleCommand("retry") end) - redoincludes() + file_wtc[fullpath] = tbl.text + timer.Simple(0,function() + --nrequire(tbl.name) + timer.Simple(10,function() + if needs_restart then + RunConsoleCommand("retry") + end + end) + --redoincludes() + end) end) net.Receive("artery_downloadfile",function(ln,pl) @@ -521,9 +568,6 @@ if SERVER then end if SERVER then - net.Receive("art_requestclientreload",function(ln,pl) - loadclient(pl) - end) else concommand.Add("artery_LoadClient",function(ply,cmd,args) net.Start("art_requestclientreload") @@ -568,3 +612,35 @@ if CLIENT then net.Receive("art_manualrefresh",doincludes) end concommand.Add("artery_manualrefresh",function(ply,cmd,args) doincludes() end) + +if nrequire_debugging then + local domain = "SERVER" + if CLIENT then + domain = "CLIENT" + end + local filename = string.format("%s_%s",domain,debug_file) + file.Open(filename,"w","DATA"):Close() + local oldprint = print + function print(...) + local f = file.Open(filename, "a", "DATA") + for _,v in pairs({...}) do + f:Write(tostring(v)) + f:Write("\t") + end + f:Write("\n") + f:Flush() + f:Close() + oldprint(...) + end + local function trace(t) + local dbg = debug.getinfo(2,"S") + if not dbg.short_src:find("artery") then + return + end + print(string.format("%s : %d - %s",dbg.short_src, dbg.linedefined, t)) + if t == "call" then + print(debug.traceback("",2)) + end + end + debug.sethook(trace,"cr",0) +end diff --git a/gamemode/shared.lua b/gamemode/shared.lua index 3daa013..c597c68 100644 --- a/gamemode/shared.lua +++ b/gamemode/shared.lua @@ -1,11 +1,7 @@ ---[[ - Set up the filesystem before doing anything else -]] - include("nrequire.lua") local ngm = GM or GAMEMODE ngm.Version = {0,7,5} ngm.Name = "Artery" ngm.Author = "Alexander \"Apickx\" Pickering" ngm.Email = "apickx@cogarr.com" -ngm.Website = "cogarr.com" +ngm.Website = "docs.cogarr.net/artery/" diff --git a/gamemode/shared/log.lua b/gamemode/shared/log.lua index 5fc043f..480cde2 100644 --- a/gamemode/shared/log.lua +++ b/gamemode/shared/log.lua @@ -14,18 +14,38 @@ elseif CLIENT then end local log_levels = { + --- Debugging messages. + -- Prints out messages for debugging, each parameter will have `tostring()` + -- called on it, interleaved with spaces and with `[DEBUG]` prepended to the whole string. + --@function debug(...) + --@param ... values to print debug = { color = col.console.gray,domain, prefix = "[DEBUG]" }, + --- Informational messages. + -- Prints out messages, each parameter will have `tostring()` + -- called on it, interleaved with spaces and with `[INFO]` prepended to the whole string. + --@function info(...) + --@param ... values that will have `tostring()` called on them, prefixed with `[INFO]` and interleaved with spaces. info = { color = col.console.cyan,domain, prefix = "[INFO]", }, + --- Warning messages. + -- Prints out warning messages, each parameter will have `tostring()` + -- called on it, interleaved with spaces and with `[WARN]` prepended to the whole string. + --@function warn(...) + --@param ... values that will have `tostring()` called on them, prefixed with `[WARN]` and interleaved with spaces. warn = { color = col.console.yellow,domain, prefix = "[WARNING]", }, + --- Error messages. + -- Prints out warning messages, each parameter will have `tostring()` + -- called on it, interleaved with spaces and with `[ERROR]` prepended to the whole string. + --@function error(...) + --@param ... values that will have `tostring()` called on them, prefixed with `[ERROR]` and interleaved with spaces. error = { color = col.console.red,domain, prefix = "[ERROR]", diff --git a/gamemode/utility/svg/cl_svg.lua b/gamemode/utility/svg/cl_svg.lua index 6a17f0a..7fa53d5 100644 --- a/gamemode/utility/svg/cl_svg.lua +++ b/gamemode/utility/svg/cl_svg.lua @@ -100,9 +100,32 @@ hook.Add("Think","process_svg_materials",function() for i = k,#toprocess do toprocess[i] = toprocess[i + 1] end + if v[3] then + v[3]() + end end end) +function svg.SetMaterialSVG(what,spath,background,foreground) + local html = vgui.Create("DHTML") + local svgdata = readsvg(spath) + local bgf = "" + local fgf = "" + if background ~= nil then + bgf = string.format("svg{background:%s}",background) + end + if foreground ~= nil then + fgf = string.format("svg path{fill:%s}",foreground) + end + html:SetHTML(string.format([[ +<style>%s%sbody{overflow:hidden}</style><body>%s</body> +]],background and bgf or "",foreground and fgf or "",svgdata)) + local mat = {} + toprocess[#toprocess + 1] = {mat,html,function() + what:SetMaterial(mat.material) + end} +end + function svg.SvgOnDpanel(spath,background,foreground,dpanel) local ret = {} ret.html = vgui.Create("DHTML",dpanel) |
