Skip to content

Commit

Permalink
wip: lua_ls stuff and found problems
Browse files Browse the repository at this point in the history
  • Loading branch information
Histalek committed Oct 16, 2023
1 parent 0270844 commit 109867b
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 28 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,6 @@ Temporary Items
todo.txt
addon.json
*.gma
.luarc.json

ttt2.jpg
31 changes: 31 additions & 0 deletions .luarc.json.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"$schema": "https://raw.githubusercontent.com/sumneko/vscode-lua/master/setting/schema.json",
"diagnostics.disable": [
"duplicate-set-field",
"unused-local",
"lowercase-global"
],
"diagnostics.globals": [
"GM",
"TRAITOR",
"DETECTIVE",
"BaseClass",
"CLGAMEMODESUBMENU"
],
"format.enable": false,
"runtime.special": {
"include": "require",
"includeCS": "require"
},
"runtime.version": "Lua 5.1",
"runtime.nonstandardSymbol": [
"!",
"!=",
"&&",
"||",
"//",
"/**/",
"continue"
],
"workspace.checkThirdParty": false
}
4 changes: 2 additions & 2 deletions gamemodes/terrortown/entities/entities/ttt_c4/shared.lua
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,12 @@ AccessorFunc(ENT, "timer_length", "TimerLength", FORCE_NUMBER)
---
-- @accessor number
-- @realm shared
AccessorFuncDT(ENT, "explode_time", "ExplodeTime")
AccessorFunc(ENT, "explode_time", "ExplodeTime", FORCE_NUMBER)

---
-- @accessor boolean
-- @realm shared
AccessorFuncDT(ENT, "armed", "Armed", FORCE_BOOL)
AccessorFunc(ENT, "armed", "Armed", FORCE_BOOL)

ENT.timeBeep = 0
ENT.safeWires = nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ ENT.HealFreq = 0.2
---
-- @accessor number
-- @realm shared
AccessorFuncDT(ENT, "StoredHealth", "StoredHealth")
AccessorFunc(ENT, "StoredHealth", "StoredHealth", FORCE_NUMBER)

---
-- @accessor Player
Expand Down
2 changes: 1 addition & 1 deletion gamemodes/terrortown/gamemode/shared/sh_door.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ local function GetDataString(ply, data)
dataTable[#dataTable + 1] = data
end

return string.Implode("||", dataTable)
return table.concat(dataTable, "||")
end

---
Expand Down
9 changes: 6 additions & 3 deletions gamemodes/terrortown/gamemode/shared/sh_equip_items.lua
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ if SERVER then
end, "ttt2changeshops")

cvars.AddChangeCallback("ttt2_random_shop_items", function(name, old, new)
local tmp = tonumber(new)
local tmp = tonumber(new, 10)

SetGlobalInt("ttt2_random_shop_items", tmp)

Expand All @@ -601,7 +601,7 @@ if SERVER then
end, "ttt2updatererollglobal")

cvars.AddChangeCallback("ttt2_random_shop_reroll_cost", function(name, old, new)
SetGlobalInt("ttt2_random_shop_reroll_cost", tonumber(new))
SetGlobalInt("ttt2_random_shop_reroll_cost", tonumber(new, 10))
end, "ttt2updatererollcostglobal")

cvars.AddChangeCallback("ttt2_random_shop_reroll_per_buy", function(name, old, new)
Expand Down Expand Up @@ -759,6 +759,7 @@ end
-- @internal
-- @realm shared
function InitFallbackShops()
-- TODO do we really not use TEAM_* or ROLE_* for the shops?
local tbl = {TRAITOR, DETECTIVE}

for i = 1, #tbl do
Expand Down Expand Up @@ -857,7 +858,7 @@ end
-- @realm shared
-- @local
local function ValueToKey(tbl)
local tmp = tmp or {}
local tmp = {}

for key, value in pairs(tbl) do
tmp[value] = value
Expand Down Expand Up @@ -890,6 +891,7 @@ end
-- @realm shared
function InitDefaultEquipment(eq)
CleanUpDefaultCanBuyIndices(eq)
-- TODO same as above
InitDefaultEquipmentForRole(TRAITOR, eq)
InitDefaultEquipmentForRole(DETECTIVE, eq)
end
Expand Down Expand Up @@ -967,6 +969,7 @@ end
-- @realm shared
function ResetDefaultEquipment(eq)
CleanUpDefaultCanBuyIndices(eq)
-- TODO same as above
ResetDefaultEquipmentForRole(TRAITOR, eq)
ResetDefaultEquipmentForRole(DETECTIVE, eq)
end
Expand Down
4 changes: 2 additions & 2 deletions gamemodes/terrortown/gamemode/shared/sh_init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -426,8 +426,8 @@ if CLIENT then
if not tbl or #tbl < 2 then return end

local _func = function(adata, bdata)
a = adata.id
b = bdata.id
local a = adata.id
local b = bdata.id

if tonumber(a) and not tonumber(b) then
return true
Expand Down
4 changes: 2 additions & 2 deletions gamemodes/terrortown/gamemode/shared/sh_rolelayering.lua
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ if CLIENT then
-- @realm client
function rolelayering.RequestDataFromServer(role)
net.Start("TTT2SyncRolelayerData")
net.WriteBit(0) -- Request data = 0, Send data = 1
net.WriteBit(false) -- Request data = false, Send data = true
net.WriteUInt(role or ROLE_NONE, ROLE_BITS)
net.SendToServer()
end
Expand All @@ -180,7 +180,7 @@ if CLIENT then
-- @realm client
function rolelayering.SendDataToServer(role, layers)
net.Start("TTT2SyncRolelayerData")
net.WriteBit(1) -- Request data = 0, Send data = 1
net.WriteBit(true) -- Request data = false, Send data = true

net.WriteUInt(role or ROLE_NONE, ROLE_BITS)

Expand Down
17 changes: 0 additions & 17 deletions lua/ttt2/libraries/none.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,6 @@ function clr(color)
return color.r, color.g, color.b, color.a
end

---
-- This @{function} creates a getter and a setter @{function} based on the name and the prefix "Get" and "Set"
-- @param table tbl the @{table} that should receive the Getter and Setter @{function}
-- @param string varname the name the tbl @{table} should have as key value
-- @param string name the name that should be concatenated to the prefix "Get" and "Set"
-- @realm shared
function AccessorFuncDT(tbl, varname, name)
tbl["Get" .. name] = function(s)
return s.dt and s.dt[varname]
end

tbl["Set" .. name] = function(s, v)
if s.dt then
s.dt[varname] = v
end
end
end

---
-- Short helper for input.LookupBinding, returns capitalised key or a default
Expand Down

0 comments on commit 109867b

Please sign in to comment.