Skip to content

Commit 2edff72

Browse files
committed
Merge branch 'latest' into docs-test
2 parents ec7f483 + d27c184 commit 2edff72

File tree

14 files changed

+155
-59
lines changed

14 files changed

+155
-59
lines changed

.gitignore

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11

2+
# Source Engine
23
/_bakeresourcecache/
34
*bakeresourcecache.vpk
5+
6+
# Tooling
47
__pycache__
58
/release/
69
/test_release/
710
__test*
811
*.bak
9-
check_lua_versions.sh
1012

1113
# MkDocs
12-
.cache
14+
.cache/
15+
check_lua_versions.sh
16+
serve_mobile.bat

.vscode/alyxlib.code-snippets

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"if thisEntity then",
1111
"\t-- Inherit this script if attached to entity",
1212
"\t-- Will also load the script at the same time if needed",
13-
"\tinherit(GetScriptFile())",
13+
"\tinherit(\"${1:EntityName}\")",
1414
"\treturn",
1515
"end",
1616
"",
@@ -45,8 +45,8 @@
4545
"scope": "lua",
4646
"prefix": ["Game Event"],
4747
"body": [
48-
"---@param params GAME_EVENT_$2",
49-
"base:GameEvent(${1:\"event\"}, function(self, params)",
48+
"---@param event GAME_EVENT_$2",
49+
"base:GameEvent(${1:\"event\"}, function(self, event)",
5050
"\t---@cast self ${3:ClassName}",
5151
"",
5252
"\t$0",
@@ -59,8 +59,8 @@
5959
"scope": "lua",
6060
"prefix": ["Player Event"],
6161
"body": [
62-
"---@param params PLAYER_EVENT_$2",
63-
"base:PlayerEvent(${1:\"event\"}, function(self, params)",
62+
"---@param event PLAYER_EVENT_$2",
63+
"base:PlayerEvent(${1:\"event\"}, function(self, event)",
6464
"\t---@cast self ${3:ClassName}",
6565
"",
6666
"\t$0",

.vscode/vlua_snippets.code-snippets

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848

4949
"Hook: OnTakeDamage":{
5050
"scope": "lua",
51-
"prefix": ["Hook", "OnTakeDamage", "Snippet"],
51+
"prefix": ["Hook", "OnTakeDamageTable", "Snippet"],
5252
"body": [
5353
"---@param damageTable TypeDamageTable",
5454
"function OnTakeDamage(damageTable)",

deployment_manifest.json

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,34 @@
113113
}
114114
],
115115

116+
"upload_removal": [
117+
{
118+
"type": "delete",
119+
"description": "Delete compiled panorama_lua.js",
120+
"source": "{AddonGame}/panorama/scripts/custom_game/panorama_lua.vjs_c"
121+
},
122+
{
123+
"type": "delete",
124+
"description": "Delete compiled panoramadoc.js",
125+
"source": "{AddonGame}/panorama/scripts/custom_game/panoramadoc.vjs_c"
126+
},
127+
{
128+
"type": "delete",
129+
"description": "Delete compiled alyxlib_debug_menu.xml",
130+
"source": "{AddonGame}/panorama/layout/custom_game/alyxlib_debug_menu.vxml_c"
131+
},
132+
{
133+
"type": "delete",
134+
"description": "Delete compiled alyxlib_debug_menu.js",
135+
"source": "{AddonGame}/panorama/scripts/custom_game/alyxlib_debug_menu.vjs_c"
136+
},
137+
{
138+
"type": "delete",
139+
"description": "Delete compiled alyxlib_debug_menu.css",
140+
"source": "{AddonGame}/panorama/styles/custom_game/alyxlib_debug_menu.vcss_c"
141+
}
142+
],
143+
116144
"sounds": [
117145
{
118146
"type": "copy",

scripts/vscripts/alyxlib/class.lua

Lines changed: 53 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ local function _inherit(base, self, fenv)
110110
break
111111
end
112112
end
113-
Warning("Trying to inherit an already inherited class ( "..class_name.." -> ["..tostring(self)..","..self:GetClassname()..","..self:GetName().."] )\n")
113+
warn("Trying to inherit an already inherited class ( "..class_name.." -> ["..tostring(self)..","..self:GetClassname()..","..self:GetName().."] )")
114114
return
115115
end
116116

@@ -133,7 +133,7 @@ local function _inherit(base, self, fenv)
133133
}
134134
-- Used to automatically save values
135135
meta.__newindex = function(table, key, value)
136-
if not key:startswith("__") and type(value) ~= "function" then
136+
if not key:startswith("_") and type(value) ~= "function" then
137137
meta.__values[key] = value
138138
self:Save(key, value)
139139
else
@@ -438,6 +438,7 @@ end
438438
---@field OnBreak fun(self: EntityClass, inflictor: EntityHandle) # Called when a breakable entity is broken.
439439
---@field OnTakeDamage fun(self: EntityClass, damageTable: OnTakeDamageTable) # Called when entity takes damage.
440440
---@field Precache fun(self: EntityClass, context: CScriptPrecacheContext) # Called before Spawn for precaching.
441+
---@field Think function # Entity think function.
441442
EntityClass = entity("EntityClass")
442443

443444
---Assign a new value to entity's field `name`.
@@ -461,24 +462,26 @@ function EntityClass:Save(name, value)
461462

462463
if name then
463464
Storage.Save(self, name, value~=nil and value or self[name])
465+
return
464466
end
467+
465468
for key, val in pairs(self) do
466-
if not key:startswith("__") and type(val) ~= "function" then
469+
if not key:startswith("_") and type(val) ~= "function" then
467470
Storage.Save(self, key, val)
468471
end
469472
end
470473
end
471474

472-
---Main entity think function which auto resumes on game load.
473-
---@luadoc-ignore
474-
function EntityClass:Think()
475-
Warning("Trying to think on entity class with no think defined ["..self.__name.."]\n")
476-
end
475+
-- ---Main entity think function which auto resumes on game load.
476+
-- ---@luadoc-ignore
477+
-- function EntityClass:Think()
478+
-- Warning("Trying to think on entity class with no think defined ["..self.__name.."]\n")
479+
-- end
477480

478481
---Resume the entity think function.
479482
---@luadoc-ignore
480483
function EntityClass:ResumeThink()
481-
if not self:IsNull() then
484+
if not self:IsNull() and type(self.Think) == "function" then
482485
self:SetContextThink("__EntityThink", function()
483486
-- Handle dead entity and user PauseThink used without returning nil
484487
if not IsValidEntity(self) or not self.IsThinking then return nil end
@@ -507,14 +510,14 @@ end
507510

508511
---Define a function for listening to a game event.
509512
---@param gameEvent GameEventsAll
510-
---@param func fun(self: EntityClass, params):any
513+
---@param func fun(self: EntityClass, event):any
511514
function EntityClass:GameEvent(gameEvent, func)
512515
self.__game_events[gameEvent] = func
513516
end
514517

515518
---Define a function for listening to a player event.
516519
---@param playerEvent PLAYER_EVENTS_ALL
517-
---@param func fun(self, params):any
520+
---@param func fun(self, event):any
518521
function EntityClass:PlayerEvent(playerEvent, func)
519522
self.__player_events[playerEvent] = func
520523
end
@@ -590,6 +593,8 @@ end
590593
---@return boolean # True if `ent` inherits `class`, false otherwise.
591594
---@diagnostic disable-next-line:lowercase-global
592595
function isinstance(ent, class)
596+
if not IsEntity(ent, true) then return false end
597+
593598
local inherits = rawget(ent, "__inherits")
594599
if inherits then
595600
for _, inherit in ipairs(inherits) do
@@ -621,4 +626,41 @@ function IsClassEntity(ent)
621626
return type(name) == "string" and EntityClassNameMap[name] ~= nil
622627
end
623628

629+
---
630+
---Binds a class to an already spawned entity so it remains attached between game loads.
631+
---
632+
---@param entity EntityHandle # Entity to bind to.
633+
---@param script string|table # Script, class, or class name to bind.
634+
---@param activateType any
635+
local function doClassBind(entity, script, activateType)
636+
local scope = entity:GetOrCreatePrivateScriptScope()
637+
print("inheriting", scope, script)
638+
inherit(script, scope)
639+
if activateType and type(scope.Activate) == "function" then
640+
scope.Activate(activateType)
641+
end
642+
end
643+
644+
---
645+
---Binds a class to an already spawned entity so it remains attached between game loads.
646+
---
647+
---@param entity EntityHandle # Entity to bind to.
648+
---@param script string # Script, class, or class name to bind.
649+
function BindClass(entity, script)
650+
doClassBind(entity, script, 0)
651+
entity:SetContext("BoundEntityClassScript", script, 0)
652+
end
653+
654+
---@param event PlayerEventPlayerActivate
655+
ListenToPlayerEvent("player_activate", function(event)
656+
local ent = Entities:First()
657+
while ent do
658+
local script = ent:GetContext("BoundEntityClassScript")
659+
if type(script) == "string" then
660+
doClassBind(ent, script)
661+
end
662+
ent = Entities:Next(ent)
663+
end
664+
end)
665+
624666
return version

scripts/vscripts/alyxlib/controls/input.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ end
400400
function Input:StopListening(id)
401401
for _id, tbl in pairs(buttonCallbacks) do
402402
if _id == id then
403-
tbl[_id] = nil
403+
buttonCallbacks[_id] = nil
404404
return
405405
end
406406
end

scripts/vscripts/alyxlib/debug/commands.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,8 @@ RegisterAlyxLibCommand("sphere", function (_, x, y, z, r)
449449
z = tonumber(z) or 0
450450
r = tonumber(r) or 16
451451

452-
DebugDrawSphere(Vector(x, y, z), Vector(255, 255, 255), 255, r, false, 10)
452+
DebugDrawSphere(Vector(x, y, z), Vector(255, 255, 255), 255, r, false, 15)
453+
DebugDrawSphere(Vector(x, y, z), Vector(255, 255, 255), 255, r, true, 10)
453454

454455
end, "Draws a debug sphere at 3D position with a radius", 0)
455456

scripts/vscripts/alyxlib/debug/common.lua

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ function Debug.PrintEntityList(list, properties)
187187
lenHandle = lenHandle + 1
188188
local formatStr = "%-"..lenIndex.."s %-"..lenHandle.."s"
189189
for propertyIndex, propertyTable in ipairs(propertyMetaData) do
190-
formatStr = formatStr .. " | %-"..propertyTable.max.."s"
190+
formatStr = formatStr .. " | %-"..math.min(propertyTable.max, 99).."s"
191191
end
192192
formatStr = formatStr .. " | %-"..lenParent.."s"
193193

@@ -591,7 +591,7 @@ end
591591
--- val2 = RandomFloat(0, 1),
592592
--- val3 = RandomFloat(0, 1)
593593
--- })
594-
--- ->
594+
---
595595
--- 1^ []
596596
--- | [] []
597597
--- | [] [] []
@@ -759,7 +759,7 @@ end
759759
---
760760
---Returns a simplified vector string with decimal places truncated.
761761
---
762-
---@param vector Vector
762+
---@param vector Vector|QAngle|table
763763
---@return string
764764
function Debug.SimpleVector(vector)
765765
return "[" .. math.trunc(vector.x, 3) .. ", " .. math.trunc(vector.y, 3) .. ", " .. math.trunc(vector.z, 3) .. "]"

scripts/vscripts/alyxlib/debug/debug_menu.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -867,7 +867,7 @@ function DebugMenu:SendCategoryToPanel(category)
867867

868868
if default ~= nil then
869869
-- find the index of the default value
870-
local index = TableFindIndex(item.values, function(v) return tostring(v.value) == tostring(default) end)
870+
local index = TableFindKey(item.values, function(v) return tostring(v.value) == tostring(default) end)
871871
if index > 0 then
872872
default = index
873873
else

scripts/vscripts/alyxlib/globals.lua

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -610,14 +610,14 @@ end
610610
---
611611
---@param list table
612612
---@param predicate fun(value:any):boolean
613-
---@return integer
614-
function TableFindIndex(list, predicate)
615-
for i, v in ipairs(list) do
613+
---@return any
614+
function TableFindKey(list, predicate)
615+
for i, v in pairs(list) do
616616
if predicate(v) then
617617
return i
618618
end
619619
end
620-
return 0
620+
return nil
621621
end
622622

623623
---

0 commit comments

Comments
 (0)