Guest User

Untitled

a guest
Sep 22nd, 2011
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.57 KB | None | 0 0
  1. --------------------------------------------------------------------------------
  2. --------------------------------------------------------------------------------
  3. --
  4. --  file:    defs.lua
  5. --  brief:   entry point for unitdefs, featuredefs, and weapondefs parsing
  6. --  author:  Dave Rodgers
  7. --  notes:   Spring.GetModOptions() is available
  8. --
  9. --  Copyright (C) 2007.
  10. --  Licensed under the terms of the GNU GPL, v2 or later.
  11. --
  12. --------------------------------------------------------------------------------
  13. --------------------------------------------------------------------------------
  14.  
  15. DEFS = {}
  16.  
  17. --------------------------------------------------------------------------------
  18. --------------------------------------------------------------------------------
  19.  
  20. local function LoadDefs(name)
  21.   local filename = 'gamedata/' .. name .. '.lua'
  22.   local success, result = pcall(VFS.Include, filename)
  23.   if (not success) then
  24.     Spring.Echo('Failed to load ' .. name)
  25.     error(result)
  26.   end
  27.   if (result == nil) then
  28.     error('Missing lua table for ' .. name)
  29.   end
  30.   return result
  31. end
  32.  
  33.  
  34. --------------------------------------------------------------------------------
  35. --------------------------------------------------------------------------------
  36.  
  37. Spring.TimeCheck('Loading all definitions: ', function()
  38.  
  39.   DEFS.unitDefs    = LoadDefs('unitDefs')
  40.  
  41.   DEFS.featureDefs = LoadDefs('featureDefs')
  42.  
  43.   DEFS.weaponDefs  = LoadDefs('weaponDefs')
  44.  
  45.   DEFS.armorDefs   = LoadDefs('armorDefs')
  46.  
  47.   DEFS.moveDefs    = LoadDefs('moveDefs')
  48.  
  49.   UnitDefs = DEFS.unitDefs
  50.   FeatureDefs = DEFS.featureDefs
  51.   WeaponDefs = DEFS.weaponDefs
  52.   ArmorDefs = DEFS.armorDefs
  53.   MoveDefs = DEFS.moveDefs
  54.  
  55.   if (VFS.FileExists('gamedata/anydefs_post.lua')) then
  56.     VFS.Include('gamedata/anydefs_post.lua')
  57.   end
  58.   if (VFS.FileExists('gamedata/ModifyStatistics.lua')) then
  59.     VFS.Include('gamedata/ModifyStatistics.lua')
  60.   end
  61.  
  62.   UnitDefs = nil
  63.   FeatureDefs = nil
  64.   WeaponDefs = nil
  65.   ArmorDefs = nil
  66.   MoveDefs = nil
  67.  
  68. end)
  69.  
  70.  
  71. --------------------------------------------------------------------------------
  72. --------------------------------------------------------------------------------
  73. --
  74. --  NOTE: the keys have to be lower case
  75. --
  76.  
  77. return {
  78.   unitdefs    = DEFS.unitDefs,
  79.   featuredefs = DEFS.featureDefs,
  80.   weapondefs  = DEFS.weaponDefs,
  81.   armordefs   = DEFS.armorDefs,
  82.   movedefs    = DEFS.moveDefs,
  83. }
  84.  
  85. --------------------------------------------------------------------------------
  86. --------------------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment