new post | browse code | authors | help | about

LuaBin 2.0

Viewing file root / lua / menu / map_favourites.lua

  1. //=============================================================================//
  2. //  ___  ___   _   _   _    __   _   ___ ___ __ __
  3. // |_ _|| __| / \ | \_/ |  / _| / \ | o \ o \\ V /
  4. //  | | | _| | o || \_/ | ( |_n| o ||   /   / \ /
  5. //  |_| |___||_n_||_| |_|  \__/|_n_||_|\\_|\\ |_|  2009
  6. //                                                                               
  7. //=============================================================================//
  8.  
  9. require( "glon" )
  10.  
  11. module( "map_favourites", package.seeall )
  12.  
  13. local faves = glon.decode( cookie.GetString( "FavMaps", "" ) ) or {};
  14.  
  15. function RebuildCookie()
  16.  
  17.         local str = glon.encode( faves )
  18.         cookie.Set( "FavMaps", str )
  19.  
  20. end
  21.  
  22. function Add( mapname )
  23.  
  24.         faves[ mapname ] = 1
  25.        
  26.         RebuildCookie()
  27.        
  28.         if ( IsValid(SinglePlayerMenu) ) then SinglePlayerMenu:RebuildFavourites() end
  29.         if ( IsValid(MultiPlayerMenu) ) then MultiPlayerMenu:RebuildFavourites() end
  30.  
  31. end
  32.  
  33. function Remove( mapname )
  34.  
  35.         faves[ mapname ] = nil
  36.        
  37.         RebuildCookie()
  38.        
  39.         if ( IsValid(SinglePlayerMenu) ) then SinglePlayerMenu:RebuildFavourites() end
  40.         if ( IsValid(MultiPlayerMenu) ) then MultiPlayerMenu:RebuildFavourites() end
  41.  
  42. end
  43.  
  44. function Count()
  45.         return table.Count( faves )
  46. end
  47.  
  48. function Get()
  49.  
  50.         local formatted = {}
  51.         for k, v in pairs( faves ) do
  52.                 table.insert( formatted, g_MapList[ k .. ".bsp" ] )
  53.         end
  54.  
  55.         return formatted
  56.  
  57. end