Debian Codegraph @

lua/ghost/ghost.lua

raw symbols SCIP
1 --[[
2 Copyright (C) 2014 HarpyWar ([email protected])
3
4 This file is a part of the PvPGN Project http://pvpgn.pro
5 Licensed under the same terms as Lua itself.
6 ]]--
7
8 -- custom map list
9 gh_maplist = {}
10
11 function gh_load()
12 -- load ghost state
13 local filename = config.vardir() .. "ghost_users.dmp"
14 if file_exists(filename) then
15 gh_load_userbots(filename)
16 DEBUG("Loaded GHost state from " .. filename)
17 end
18
19 -- preload custom map list
20 local mapfile = gh_directory() .. "/maplist.txt"
21 if file_exists(mapfile) then
22 gh_load_maps(mapfile)
23 DEBUG("Loaded " .. #gh_maplist .. " GHost custom maps")
24 else
25 WARN("File with GHost custom map list is not found: " .. mapfile)
26 end
27
28 end
29
30 function gh_unload()
31 -- save ghost state
32 local filename = config.vardir() .. "ghost_users.dmp"
33 gh_save_userbots(filename)
34
35 DEBUG("Saved GHost state to " .. filename)
36 end
37
38
39
40
41 function gh_load_maps(filename)
42 -- load maps from the file
43 file_load(filename, file_load_dictionary_callback,
44 function(a,b)
45 -- split second part of the line to get mapname and filename
46 local idx = 0
47 for v in string.split(b, "|") do
48 if idx == 0 then
49 mapname = string:trim(v)
50 else
51 mapfile = string:trim(v)
52 end
53 idx = idx + 1
54 end
55 table.insert(gh_maplist, { code = a, name = mapname, filename = mapfile })
56 end)
57 end