function Meta( tab )
tab.__index = tab
return setmetatable( tab, {
__call = function( self, t )
return setmetatable( t, self )
end
} )
end
local _F = {}
_F.__index = _F
AccessorFunc( _F, "Type", "Type", FORCE_STRING )
AccessorFunc( _F, "Path", "Path", FORCE_STRING )
function _F:__tostring()
return string.format( "[%s] %s", self:GetType(), self:GetPath() )
end
function _F:GetExtension()
return self:GetPath():match( "(%..+)$" )
end
function _F:GetFileName()
return self:GetPath():gsub( ".*[\\/]+(.+)%.", 1 )
end
function _F:IsModel()
return self:GetType() == "Model"
end
function _F:IsSound()
return self:GetType() == "Sound"
end
function _F:IsFont()
return self:GetType() == "Font"
end
function _F:IsMaterial()
return self:GetType() == "Material"
end
function _F:IsParticle()
return self:GetType() == "Particle"
end
function _F:AddFile()
local folder = ""
if self:IsModel() then
folder = "models/"
elseif self:IsSound() then
folder = "sound/"
elseif self:IsFont() then
folder = "resource/"
elseif self:IsMaterial() then
folder = "materials/"
elseif self:IsParticle() then
folder = "particles/"
end
resource.AddFile( folder .. self:GetPath() )
end
function _F:Precache( models, sounds )
if self:IsSound() and sounds then
util.PrecacheSound( self:GetPath() )
elseif self:IsModel() and models then
util.PrecacheModel( self:GetPath() )
end
end
function RSAddFile( name, file )
table.insert( ResourceSmart.DownloadList[ name ], file )
end
function RSCreateFile( path )
local tbl = setmetatable( {}, _F )
tbl:SetPath( path )
local ext = tbl:GetExtension()
tbl:SetType(
(ext == ".mdl") and "Model" or
(ext == ".vmt") and "Material" or
(ext == ".ttf") and "Font" or
(ext == ".pcf") and "Particle" or
(ext == ".wav" or ext == ".mp3") and "Sound" or ""
)
return tbl
end
function RSGetVersion()
http.Get( ResourceSmart.VersionURL, "", function( contents )
if contents == nil then
Msg( ">>> " .. ResourceSmart.VersionURL .. " missing contents\n" )
filex.Append( "ResourceSmart/errors.txt", ">>> " .. ResourceSmart.VersionURL .. " missing contents\n" )
return
end
return contents
end )
end
function RSCheckVersion( debug )
http.Get( ResourceSmart.VersionURL, "", function( contents )
if contents == nil then
Msg( ">>> " .. ResourceSmart.VersionURL .. " missing contents\n" )
filex.Append( "ResourceSmart/errors.txt", ">>> " .. ResourceSmart.VersionURL .. " missing contents\n" )
return
end
if ResourceSmart.Version == contents then
if debug then
Msg( ">>> ResourceSmart[ VersionChecker] >> true\n" )
end
return true
else
if debug then
Msg( ">>> ResourceSmart[ VersionChecker] >> false\n" )
end
return false
end
end )
end
function RSAddDir( dir )
for k, v in pairs( file.Find( "../" .. dir .. "/*" ) ) do
resource.AddFile( dir .. v )
end
end
function RSConVarAddFile( name, file, cvar )
if not ConVarExists( tostring( cvar ) ) then
CreateConVar( cvar, 1, true )
end
if GetConVar( cvar ) == 0 then
return
else
table.insert( ResourceSmart.DownloadList[ name ], file )
end
end
function RSConVarAddDir( dir, cvar )
if not ConVarExists( tostring( cvar ) ) then
CreateConVar( cvar, 1, true )
end
if GetConVar( cvar ) == 0 then
return
else
for k, v in pairs( file.Find( "../" .. dir .. "/*" ) ) do
resource.AddFile( dir .. v )
end
end
end
function RSMapAddDir( dir, map )
if not string.lower( game.GetMap() ) == map then return end
for k, v in pairs( file.Find( "../" .. dir .. "/*" ) ) do
resource.AddFile( dir .. v )
end
end
function RSNMapAddDir( dir, map )
if string.lower( game.GetMap() ) == map then return end
for k, v in pairs( file.Find( "../" .. dir .. "/*" ) ) do
resource.AddFile( dir .. v )
end
end