aboutsummaryrefslogtreecommitdiff
path: root/gamemode/hud/draw_spell.lua
blob: b68e9889514f999c49b428091d1b9b40fa466b8e (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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
CASTING_SPELL = nil

--AddLUACSFolder("spellminigames")

local Folder  	= GM.Folder:gsub("gamemodes/","").."/gamemode/hud/games"

--A table of spells to functions?
Spells = {
    ["Fireball"] = {
        ["file"] = "connectthedots.lua",
        ["minigame"] = "Cast",
        ["interupt"] = "AddDots",
        ["draw"] = "Draw",
        ["difficulty"] = 1,
    },
}

Games = {}

function loadgames()
    includedfiles = {}
    Games = {}
    print("Looking for what minigames we need...")
    for k,v in pairs(Spells) do
        local filename = v["file"]
        if (includedfiles[filename] == nil) then
            print("Spell " .. k .. " depends on " .. filename)
            includedfiles[filename] = true
        end
    end
    Game = {}
    print("Loading in minigames")
    for k,v in pairs(includedfiles) do
        AddCSLuaFile(Folder .. "/" .. k)
        Game = {}
        include(Folder .. "/" .. k)
        Games[k] = Game
        print("Loaded game:")
        PrintTable(Game,1)
    end
    print("Resolveing minigame names")
    print("All games:")
    PrintTable(Games,1)
    print("All spells:")
    PrintTable(Spells)
    local needefunctions = {"minigame","draw","interupt"}
    for k,v in pairs(Spells) do
        local spell = v
        print("Resolveing spell:")
        PrintTable(Spells)
        local gametab = Games[v["file"]]
        if not gametab then
            print("Coudln't find " .. v["file"] .. " in games")
        end
        for i,j in pairs(gametab) do
            local issimple = false
            for l,m in pairs(spell) do
                print("Checking if ",m,"is",i)
                if(m == i) then
                    print("Overloading " .. m)
                    spell[l] = j
                    issimple = true
                    break
                end
            end
            if not issimple then
                spell[i] = j
            end
        end
        --[[
        local mgname = v["minigame"]
        local mginame = v["interupt"]
        local mgdname = v["draw"]
        for i,j in pairs(Games) do
            if i == v["file"] then
                for l,m in pairs(j) do
                    Spells[k][l] = m
                    print("Resolved " .. k)
                    local castfunc = j[mgname]
                    local drawfunc = j[mgdname]
                    local interuptfunc = j[mginame]
                    if(castfunc) then
                        Spells[k]["minigame"] = castfunc
                    else
                        print("Spell " .. k .. " does not have a cast func! This may be an error!")
                    end
                    if(drawfunc) then
                        Spells[k]["draw"] = drawfunc
                    else
                        print("Spell " .. k .. " does not have a draw func! This may be an error!")
                    end
                    if(interuptfunc) then
                        Spells[k]["interupt"] = interuptfunc
                    else
                        print("Spell " .. k .. " does not have an interupt func! This may be an error!")
                    end
                end
            end
            Spells[k] = j
        end
        ]]--
    end
    print("After resolveing:")
    PrintTable(Spells)
end

hook.Add("Initialize","Loadspells",function()
	loadgames()
end)

concommand.Add("reloadgames",function(ply,cmd,args)
    loadgames()
end)

function StartMinigame(spell)
    print("starting " .. spell)
    if not spell then return end
    --If we're already casting, and are told to cast again do someting.
    if CASTING_SPELL != nil then
        CASTING_SPELL["interupt"](CASTING_SPELL)
        return
    end

    if Spells[spell] then
        CASTING_SPELL = Spells[spell]
        CASTING_SPELL["minigame"](CASTING_SPELL, CASTING_SPELL["difficulty"])
    else
        print("Could not find spell " .. spell)
    end
end

function DrawSpellOverlay()
    if(CASTING_SPELL) then
        CASTING_SPELL["draw"](CASTING_SPELL)
        if(CASTING_SPELL.Score != nil) then
            finishedcasting(CASTING_SPELL.Score)
            CASTING_SPELL = nil
        end
    end
end

concommand.Add("startminigame",function(ply,cmd,args)
    print("Starting " .. args[1])
    StartMinigame(args[1])
end)