summaryrefslogtreecommitdiff
path: root/gamemode/utility.lua
blob: ec7eaab88365ed9bfb8deb5846852ac1ef5e53e0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
//Helper functions to refactor the init
print("Utility.lua included!")

function findRecursive(folderstring,recursive,dofunction)
  local folderpath = --[["gamemodes/" .. GM.GAMEMODE_FOLDER_NAME .. "/gamemode/" .. ]]folderstring .. "/"
  local files, directories = file.Find(folderpath .. "*", "LUA")
  for k,v in pairs(files) do
    dofunction(folderstring .. "/".. v)
  end
  if(recursive) then
    for k,v in pairs(directories) do
      findRecursive(folderstring.. "/" .. v,recursive,dofunction)
    end
  end
end

//Does AddCSLuaFile() on all files within a folderpath, optionally recursive
//Ex:
//  AddCSLuaFolder("client/extras",true)
function AddCSLuaFolder(folderstring,recursive)
  print("AddCSLuaFolder called on " .. folderstring)
  findRecursive(folderstring,recursive,function(string)
    print("Adding CS Lu file:" .. string)
    AddCSLuaFile(string)
  end)
end

//Does include() on all files within a folderpath, optionally recursive
//Ex:
//  includeFolder("server/extras",false)
function includeFolder(folderstring,recursive)
  print("includeFolder called on " .. folderstring)
  findRecursive(folderstring,recursive,function(string)
    print("Includeing file:" .. string)
    include(string)
  end)
end

function addResourceFolder(folderpath,recursive)
  local files, directories = file.find(folderpath .. "*", "GAME")
  if(recursive) then
    for k,v in pairs(directories) do
      addResourceFolder(folderpath..v,recursive)
    end
  end
  for k,v in pairs(files) do
    resource.AddFile(v)
  end
end