aboutsummaryrefslogtreecommitdiff
path: root/gamemode/hud/draw_spell.lua
diff options
context:
space:
mode:
Diffstat (limited to 'gamemode/hud/draw_spell.lua')
-rw-r--r--gamemode/hud/draw_spell.lua105
1 files changed, 64 insertions, 41 deletions
diff --git a/gamemode/hud/draw_spell.lua b/gamemode/hud/draw_spell.lua
index 032c25f..96440e4 100644
--- a/gamemode/hud/draw_spell.lua
+++ b/gamemode/hud/draw_spell.lua
@@ -2,48 +2,67 @@ CASTING_SPELL = nil
--AddLUACSFolder("spellminigames")
-local Folder = GM.Folder:gsub("gamemodes/","").."/gamemode/hud/"
+local Folder = GM.Folder:gsub("gamemodes/","").."/gamemode/hud/games"
--A table of spells to functions?
-Spells = {}
---[[
- ["fireball"] = {
- ["minigame"] = connectthedots,
- ["interupt"] = connectextradots,
- ["difficulty"] = 1
- }
-}]]--
+Spells = {
+ ["Fireball"] = {
+ ["file"] = "connectthedots.lua",
+ ["minigame"] = "Cast",
+ ["interupt"] = "AddDots",
+ ["draw"] = "Draw",
+ ["difficulty"] = 1,
+ },
+}
+
+Games = {}
function loadgames()
- GAMEMODE.minigames = {}
- print("WS2A:Looking for minigames in:" .. Folder)
- AddCSLuaFile(Folder .. "/games/base.lua")
- include(Folder .. "/games/base.lua")
- local games, fold = file.Find(Folder.."*","LUA")
- local game = {}
- print("WS2A:Loading " .. #(games) .. " minigames")
- print("WS2A:Found " .. #(fold) .. " folders")
- for k,v in pairs(games) do
- print(v)
- --[[
- if (v != "base.lua") then
- AddCSLuaFile(Folder.."/"..v)
- include(Folder.."/"..v)
- if((not game.Name) or (not game.minigame) or (not game.interupt)) then
- print("WS2A:Error loading " .. Folder .. "/" .. v .. "One or more of the are missing: Name, minigame, interupt")
- continue
- else
- print("WS2A:Loaded " .. Folder .. "/" .. v)
+ includedfiles = {}
+ 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
+ end
+ print("Resolveing minigame names")
+ for k,v in pairs(Spells) do
+ local mgname = v["minigame"]
+ local mginame = v["interupt"]
+ local mgdname = v["draw"]
+ for i,j in pairs(Games) do
+ if i == v["file"] then
+ print("Resolved " .. k)
+ local castfunc = j[mgname]
+ local drawfunc = j[mgdname]
+ local interuptfunc = j[mginame]
+ if(castfunc) then
+ v["minigame"] = castfunc
+ else
+ print("Spell " .. k .. " does not have a cast func! This may be an error!")
+ end
+ if(drawfunc) then
+ v["draw"] = drawfunc
+ else
+ print("Spell " .. k .. " does not have a draw func! This may be an error!")
+ end
+ if(interuptfunc) then
+ v["interupt"] = interuptfunc
+ else
+ print("Spell " .. k .. " does not have an interupt func! This may be an error!")
+ end
end
-
- table.insert(GAMEMODE.Spells,{
- Spell.Name
- })
-
- NPC = table.Copy(BaseItem)
-
end
- ]]--
end
end
@@ -60,13 +79,13 @@ function StartMinigame(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["interupt"](CASTING_SPELL)
return
end
- if spells[spell] then
- CASTING_SPELL = spells[spell]
- spells[spell]["minigame"](spells[spell]["difficulty"])
+ if Spells[spell] then
+ CASTING_SPELL = Spells[spell]
+ Spells[spell]["minigame"](CASTING_SPELL, Spells[spell]["difficulty"])
else
print("Could not find spell " .. spell)
end
@@ -74,7 +93,11 @@ end
function DrawSpellOverlay()
if(CASTING_SPELL) then
- CASTING_SPELL["minigame"]()
+ CASTING_SPELL["draw"](CASTING_SPELL)
+ if(CASTING_SPELL.Score != nil) then
+ finishedcasting(CASTING_SPELL.Score)
+ CASTING_SPELL = nil
+ end
end
end