diff options
| author | Alexander Pickering <alexandermpickering@gmail.com> | 2016-05-27 20:24:40 -0400 |
|---|---|---|
| committer | Alexander Pickering <alexandermpickering@gmail.com> | 2016-05-27 20:24:40 -0400 |
| commit | 427b41c5683d9c913bd7b66d540d8a882a33ebf6 (patch) | |
| tree | 8c91e778b2ad6385964573964674fb3aa97a9594 | |
| parent | 9ea65b0c6a2b53766e5aa66cb6d86644a70da21f (diff) | |
| download | gmstranded-427b41c5683d9c913bd7b66d540d8a882a33ebf6.tar.gz gmstranded-427b41c5683d9c913bd7b66d540d8a882a33ebf6.tar.bz2 gmstranded-427b41c5683d9c913bd7b66d540d8a882a33ebf6.zip | |
Refactored where the structure code was
| -rw-r--r-- | gamemode/structuresystem/common.lua (renamed from gamemode/structuresystem/common_smelt.lua) | 106 | ||||
| -rw-r--r-- | gamemode/structuresystem/structures/stonefurnace.lua | 9 |
2 files changed, 42 insertions, 73 deletions
diff --git a/gamemode/structuresystem/common_smelt.lua b/gamemode/structuresystem/common.lua index 68a50b1..d7da6d6 100644 --- a/gamemode/structuresystem/common_smelt.lua +++ b/gamemode/structuresystem/common.lua @@ -1,19 +1,52 @@ + +local buts = 92 + +local function makeCraftingWindow(name) + local pw = ScrW() / 1.3 + local ph = ScrH() / 1.4 + local DermaPanel = vgui.Create( "DFrame" ) + DermaPanel:SetPos( 100, 100 ) + DermaPanel:SetSize( pw, ph ) + DermaPanel:SetTitle( name ) + DermaPanel:SetDraggable( true ) + DermaPanel:Center() + DermaPanel.Grid = vgui.Create("DGrid",DermaPanel) + DermaPanel.Grid:SetPos(10,30) + DermaPanel.Grid:SetColWide(buts) + DermaPanel.Grid:SetCols(pw / buts) + DermaPanel.Grid:SetRowHeight(buts) + DermaPanel.info = vgui.Create("DPanel",DermaPanel) + DermaPanel.info:SetPos(10,(buts * 2) + 30) + DermaPanel.info:SetSize(pw - 20, buts * 0.75) + DermaPanel.infotext = vgui.Create("DLabel",DermaPanel.info) + DermaPanel.infotext:SetText("") + DermaPanel.infotext:SetPos(10,10) + DermaPanel.infotext:SetDark(true) + DermaPanel.infotext:SetFont( "ScoreboardSub" ) + DermaPanel.infotext:Dock(TOP) + DermaPanel.reqtext = vgui.Create("DLabel",DermaPanel.info) + DermaPanel.reqtext:SetPos(10,30) + DermaPanel.reqtext:SetDark(true) + DermaPanel.reqtext:Dock(FILL) + + return DermaPanel +end + if SERVER then util.AddNetworkString( "makerecipe" ) end -function genericMakeFurnace(tbl) + +function genericMakeCrafting(tbl) local oldusefunc = tbl.onUse local overrideuse = function(self, ply) oldusefunc(self,ply) if SERVER or ply != LocalPlayer() then return end - PrintTable(tbl.genericRecipes) - tbl.Recipes = {} for k,v in pairs(tbl.genericRecipes) do local ratio = v.Ratio - local mults = {1,5,10,20,50} + local mults = v.Mults for i,j in pairs(mults) do local thisrecipe = {} thisrecipe.Req = {} @@ -24,8 +57,6 @@ function genericMakeFurnace(tbl) for l,m in pairs(v.Results) do thisrecipe.Results[l] = ratio[2] * j * m end - print("This recipe is :") - PrintTable(thisrecipe) thisrecipe.Name = v.Name .. " x" .. j thisrecipe.Description = v.Description thisrecipe.genericNum = k @@ -34,40 +65,12 @@ function genericMakeFurnace(tbl) end end - print("Recipes are:") - PrintTable(tbl.Recipes) - - local DermaPanel = vgui.Create( "DFrame" ) - DermaPanel:SetPos( 100, 100 ) - local buts = 128 - DermaPanel:SetSize( ScrW() / 1.3, ScrH() / 1.4 ) - DermaPanel:SetTitle( tbl.Name ) - DermaPanel:SetDraggable( true ) - DermaPanel:Center() - local Grid = vgui.Create("DGrid",DermaPanel) - Grid:SetPos(10,30) - Grid:SetColWide(buts) - Grid:SetRowHeight(buts) - DermaPanel.info = vgui.Create("DPanel",DermaPanel) - DermaPanel.info:SetPos(10,(buts * 2) + 30) - DermaPanel.info:SetSize(ScrW() / 1.3 - 20, buts * 0.75) - DermaPanel.infotext = vgui.Create("DLabel",DermaPanel.info) - DermaPanel.infotext:SetText("") - DermaPanel.infotext:SetPos(10,10) - DermaPanel.infotext:SetDark(true) - DermaPanel.infotext:SetFont( "ScoreboardSub" ) - DermaPanel.infotext:Dock(TOP) - DermaPanel.reqtext = vgui.Create("DLabel",DermaPanel.info) - DermaPanel.reqtext:SetPos(10,30) - DermaPanel.reqtext:SetDark(true) - DermaPanel.reqtext:Dock(FILL) + local DermaPanel = makeCraftingWindow(tbl.Name) for k,v in pairs(tbl.Recipes) do local testbut = vgui.Create("DButton") testbut:SetText(v.Name) testbut:SetSize(buts,buts) testbut.DoClick = function(button) - print("Recipe is:") - PrintTable(v) DermaPanel.structname = tbl.Name DermaPanel.recipeNum = v.genericNum DermaPanel.recipeMult = v.mult @@ -80,13 +83,12 @@ function genericMakeFurnace(tbl) local cancraft = true for i,j in pairs(v.Req) do if Resources[i] < j then - print("Can't craft becaues " .. i .. "(" .. Resources[i] .. ") is less than " .. j) cancraft = false end end DermaPanel.makebutton:SetEnabled(cancraft) end - Grid:AddItem(testbut) + DermaPanel.Grid:AddItem(testbut) DermaPanel:MakePopup() end DermaPanel.makebutton = vgui.Create("DButton",DermaPanel) @@ -115,16 +117,7 @@ net.Receive( "makerecipe", function(ln,ply) end local recipenum = net.ReadUInt(GMS.NETINT_BITCOUNT) local mult = net.ReadUInt(GMS.NETINT_BITCOUNT) - print("Attempting to craft:") - print("Table name:" .. tblname) - print("Recipenum:" .. recipenum) - print("Multiplier:" .. mult) - print("This recipe is:") - print("Table is:") - PrintTable(tbl) local recipe = tbl.genericRecipes[recipenum] - print("Recipe:") - PrintTable(recipe) --Check that we have enough ingredients for k,v in pairs(recipe.Requirements) do @@ -150,24 +143,3 @@ function genericGiveRecipie(tbl, recipe) tbl.genericRecipes = tbl.genericRecipes or {} table.insert(tbl.genericRecipes, recipe) end - -function recipieForSmelt(tbl, name, description, required, result, ratio, mults) - local recipie = {} - recipie.Req = {} - recipie.Req[required] = ratio[1] - recipie.Results = {} - recipie.Results[result] = ratio[2] - local num = table.insert(tbl.GenericRecipe,0,recipe) - for k,v in pairs(mults) do - if v == 0 then continue end - local thisrecipie = {} - thisrecipie.Name = name .. " x" .. math.floor(v) - thisrecipie.Description = description - thisrecipie.Req = {} - thisrecipie.Req[required] = math.floor(ratio[1] * v) - thisrecipie.Results = {} - thisrecipie.Results[result] = math.floor(ratio[2] * v) - thisrecipie.GenericRecipe = num - table.insert(tbl.Recipes,0,thisrecipie) - end -end diff --git a/gamemode/structuresystem/structures/stonefurnace.lua b/gamemode/structuresystem/structures/stonefurnace.lua index 5914ed2..029b242 100644 --- a/gamemode/structuresystem/structures/stonefurnace.lua +++ b/gamemode/structuresystem/structures/stonefurnace.lua @@ -3,10 +3,6 @@ local STRUCT = {} STRUCT.Name = "Stone Furnace" STRUCT.Model = "models/props/de_inferno/ClayOven.mdl" -STRUCT.Structure = { - {"models/props/de_inferno/ClayOven.mdl",Vector(0,0,0),Angle(0,0,0)} -} - STRUCT.onInitialize = function(self) print("Initalize called!") end @@ -35,10 +31,11 @@ local genericRecipe = { ["Requirements"] = {["Copper Ore"] = 1}, ["Results"] = {["Copper"] = 1}, ["Ratio"] = {1,1}, - ["Time"] = timefunc + ["Time"] = timefunc, + ["Mults"] = {1,5,10,20,50} } genericGiveRecipie(STRUCT,genericRecipe) -genericMakeFurnace(STRUCT) +genericMakeCrafting(STRUCT) registerStructure(STRUCT) |
