From 711e7627c4a79e14d7ef8a5b9f569481cbdcedcd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Shadowsun=E2=84=A2?= <12494967+CattoGamer@users.noreply.github.com> Date: Sun, 6 Oct 2024 01:41:14 +0200 Subject: [PATCH] Move time time converter function to utils --- .../gamemode/extensions/sh_util.lua | 18 ++++++++++++++++++ .../gamemode/modules/theater/sh_theater.lua | 15 +-------------- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/workshop/gamemodes/cinema_modded/gamemode/extensions/sh_util.lua b/workshop/gamemodes/cinema_modded/gamemode/extensions/sh_util.lua index 97f8f70..e872319 100644 --- a/workshop/gamemodes/cinema_modded/gamemode/extensions/sh_util.lua +++ b/workshop/gamemodes/cinema_modded/gamemode/extensions/sh_util.lua @@ -30,6 +30,24 @@ function SecondsToISO_8601(seconds) return (t.h and t.h .. "h" or "") .. (t.m and t.m .. "m" or "") .. (t.s and t.s .. "s" or "") end +-- Helper function for converting HH:MM:SS time strings +local hhmmss = "(%d+):(%d+):(%d+)" +local mmss = "(%d+):(%d+)" +function ConvertTimeToSeconds(time) + local hr, min, sec = string.match(time, hhmmss) + + -- Not in HH:MM:SS, try MM:SS + if not hr then + min, sec = string.match(time, mmss) + if not min then return end -- Not in MM:SS, give up + hr = 0 + end + + return tonumber(hr) * 3600 + + tonumber(min) * 60 + + tonumber(sec) +end + -- Get the value for an attribute from a html element function ParseElementAttribute( element, attribute ) if not element then return end diff --git a/workshop/gamemodes/cinema_modded/gamemode/modules/theater/sh_theater.lua b/workshop/gamemodes/cinema_modded/gamemode/modules/theater/sh_theater.lua index 0fc470b..9f27885 100644 --- a/workshop/gamemodes/cinema_modded/gamemode/modules/theater/sh_theater.lua +++ b/workshop/gamemodes/cinema_modded/gamemode/modules/theater/sh_theater.lua @@ -490,8 +490,6 @@ if SERVER then end - local hhmmss = "(%d+):(%d+):(%d+)" - local mmss = "(%d+):(%d+)" function THEATER:Seek( seconds ) if not IsVideoTimed(self:VideoType()) then return end @@ -501,18 +499,7 @@ if SERVER then -- Seconds isn't a number, check HH:MM:SS if not tonumber(seconds) then - local hr, min, sec = string.match(seconds, hhmmss) - - -- Not in HH:MM:SS, try MM:SS - if not hr then - min, sec = string.match(seconds, mmss) - if not min then return end -- Not in MM:SS, give up - hr = 0 - end - - seconds = tonumber(hr) * 3600 + - tonumber(min) * 60 + - tonumber(sec) + seconds = util.ConvertTimeToSeconds(seconds) end -- If it's not one of those two things then it will fall trough wihtout any changes.