From bf0673914b545f0b9855f273892debd0b5079b2a Mon Sep 17 00:00:00 2001 From: Michael Fabian 'Xaymar' Dirks Date: Thu, 5 Jul 2018 06:54:05 +0200 Subject: [PATCH] gamemode/server/states: Switch to generated implementation This has the benefit that all base info is present as meta info and setting a member to nil simply uses the meta member instead. --- .../gamemode/server/states/base.lua | 53 +++++++++++++++++++ .../gamemode/server/states/state_hide.lua | 6 ++- .../server/states/state_postmatch.lua | 6 ++- .../server/states/state_postround.lua | 6 ++- .../gamemode/server/states/state_prematch.lua | 7 +-- .../gamemode/server/states/state_preround.lua | 6 ++- .../gamemode/server/states/state_seek.lua | 5 +- 7 files changed, 77 insertions(+), 12 deletions(-) create mode 100644 source/gamemodes/prophuntextended/gamemode/server/states/base.lua diff --git a/source/gamemodes/prophuntextended/gamemode/server/states/base.lua b/source/gamemodes/prophuntextended/gamemode/server/states/base.lua new file mode 100644 index 0000000..d40ad53 --- /dev/null +++ b/source/gamemodes/prophuntextended/gamemode/server/states/base.lua @@ -0,0 +1,53 @@ +--[[ + The MIT License (MIT) + + Copyright (c) 2018 Xaymar + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. +--]] + +local stateDef = {} +stateDef.__index = stateDef + +function stateDef:__construct() + self.Name = "" +end + +function stateDef:GetName() + return self.Name +end + +function stateDef:OnEnter() end + +function stateDef:Tick() end + +function stateDef:OnLeave() end + +function state(name) + local obj = {} + obj.__index = obj + setmetatable(obj, stateDef) + obj:__construct() + if (name != nil) then + obj.Name = name + else + obj.Name = "Unnamed" + end + return obj; +end diff --git a/source/gamemodes/prophuntextended/gamemode/server/states/state_hide.lua b/source/gamemodes/prophuntextended/gamemode/server/states/state_hide.lua index 8c67f92..b7e3984 100644 --- a/source/gamemodes/prophuntextended/gamemode/server/states/state_hide.lua +++ b/source/gamemodes/prophuntextended/gamemode/server/states/state_hide.lua @@ -1,7 +1,7 @@ --[[ The MIT License (MIT) - Copyright (c) 2015 Xaymar + Copyright (c) 2015-2018 Xaymar Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -22,7 +22,9 @@ SOFTWARE. --]] -StateHide = {} +include "base.lua" + +StateHide = state("Hide") function StateHide:OnEnter(OldState) if GAMEMODE.Config:DebugLog() then print("StateHide: OnEnter") end diff --git a/source/gamemodes/prophuntextended/gamemode/server/states/state_postmatch.lua b/source/gamemodes/prophuntextended/gamemode/server/states/state_postmatch.lua index ac32d6d..42ca168 100644 --- a/source/gamemodes/prophuntextended/gamemode/server/states/state_postmatch.lua +++ b/source/gamemodes/prophuntextended/gamemode/server/states/state_postmatch.lua @@ -1,7 +1,7 @@ --[[ The MIT License (MIT) - Copyright (c) 2015 Xaymar + Copyright (c) 2015-2018 Xaymar Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -22,7 +22,9 @@ SOFTWARE. --]] -StatePostMatch = {} +include "base.lua" + +StatePostMatch = state("PostMatch") function StatePostMatch:OnEnter(OldState) if GAMEMODE.Config:DebugLog() then print("StatePostMatch: OnEnter") end diff --git a/source/gamemodes/prophuntextended/gamemode/server/states/state_postround.lua b/source/gamemodes/prophuntextended/gamemode/server/states/state_postround.lua index 5539916..b4cde90 100644 --- a/source/gamemodes/prophuntextended/gamemode/server/states/state_postround.lua +++ b/source/gamemodes/prophuntextended/gamemode/server/states/state_postround.lua @@ -1,7 +1,7 @@ --[[ The MIT License (MIT) - Copyright (c) 2015 Xaymar + Copyright (c) 2015-2018 Xaymar Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -22,7 +22,9 @@ SOFTWARE. --]] -StatePostRound = {} +include "base.lua" + +StatePostRound = state("PostRound") function StatePostRound:OnEnter(OldState) if GAMEMODE.Config:DebugLog() then print("StatePostRound: OnEnter") end diff --git a/source/gamemodes/prophuntextended/gamemode/server/states/state_prematch.lua b/source/gamemodes/prophuntextended/gamemode/server/states/state_prematch.lua index 017745e..173f359 100644 --- a/source/gamemodes/prophuntextended/gamemode/server/states/state_prematch.lua +++ b/source/gamemodes/prophuntextended/gamemode/server/states/state_prematch.lua @@ -1,7 +1,7 @@ --[[ The MIT License (MIT) - Copyright (c) 2015 Xaymar + Copyright (c) 2015-2018 Xaymar Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -22,8 +22,9 @@ SOFTWARE. --]] --- Precache Network Message -StatePreMatch = {} +include "base.lua" + +StatePreMatch = state("PreMatch") function StatePreMatch:OnEnter(OldState) if GAMEMODE.Config:DebugLog() then print("StatePreMatch: OnEnter") end diff --git a/source/gamemodes/prophuntextended/gamemode/server/states/state_preround.lua b/source/gamemodes/prophuntextended/gamemode/server/states/state_preround.lua index b829222..23f24cc 100644 --- a/source/gamemodes/prophuntextended/gamemode/server/states/state_preround.lua +++ b/source/gamemodes/prophuntextended/gamemode/server/states/state_preround.lua @@ -1,7 +1,7 @@ --[[ The MIT License (MIT) - Copyright (c) 2015 Xaymar + Copyright (c) 2015-2018 Xaymar Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -22,7 +22,9 @@ SOFTWARE. --]] -StatePreRound = {} +include "base.lua" + +StatePreRound = state("PreRound") function StatePreRound:OnEnter(OldState) if GAMEMODE.Config:DebugLog() then print("StatePreRound: OnEnter") end diff --git a/source/gamemodes/prophuntextended/gamemode/server/states/state_seek.lua b/source/gamemodes/prophuntextended/gamemode/server/states/state_seek.lua index f40aab7..7517fae 100644 --- a/source/gamemodes/prophuntextended/gamemode/server/states/state_seek.lua +++ b/source/gamemodes/prophuntextended/gamemode/server/states/state_seek.lua @@ -1,7 +1,7 @@ --[[ The MIT License (MIT) - Copyright (c) 2015 Xaymar + Copyright (c) 2015-2018 Xaymar Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -22,7 +22,10 @@ SOFTWARE. --]] +include "base.lua" + StateSeek = {} +StateSeek.Name = "Seek" function StateSeek:OnEnter(OldState) if GAMEMODE.Config:DebugLog() then print("StateSeek: OnEnter") end