Advertisement
Guest User

Untitled

a guest
Feb 7th, 2011
304
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.48 KB | None | 0 0
  1.     class Script
  2.     {
  3.         List<IScriptItem> m_items = new List<IScriptItem>();
  4.         GameResource m_gameResource;
  5.         int m_itemIndex;
  6.         String m_filename;
  7.         bool m_shouldDelete;
  8.         public Script(String filename, GameResource resource)
  9.         {
  10.             m_filename = filename;
  11.             m_gameResource = resource;
  12.             DataNode rootNode = DataNodeResource.getDataNode(@"Content\scripts\" + filename);
  13.             m_itemIndex = 0;
  14.             addFromNode(rootNode);
  15.         }
  16.         public void setDeleted()
  17.         {
  18.             m_shouldDelete = true;
  19.         }
  20.         public String getFilename()
  21.         {
  22.             return m_filename;
  23.         }
  24.         public bool shouldDelete()
  25.         {
  26.             return m_shouldDelete;
  27.         }
  28.         void addFromNode(DataNode node)
  29.         {
  30.             int nodeCount = node.getNodeCount();
  31.             for (int nodeIndex = 0; nodeIndex < nodeCount; ++nodeIndex)
  32.             {
  33.                 DataNode thisNode = node.getNode(nodeIndex);
  34.                 String itemType = thisNode.getName();            IScriptItem itemToAdd = null;
  35.                 if ( itemType == "wait" ) // replace these else-ifs with your favourite String -> Object building logic
  36.                 {
  37.                     itemToAdd = new ScriptItems.Wait();
  38.                 }
  39.                 else if ( itemType == "play_cue" )
  40.                 {
  41.                     itemToAdd = new ScriptItems.PlayCue();
  42.                 }
  43.  
  44.                 if (itemToAdd != null)
  45.                 {
  46.                     itemToAdd.baseSetup(m_gameResource);   // set up base
  47.                     itemToAdd.setup(thisNode); // pass data to item set up
  48.                     m_items.Add(itemToAdd);
  49.                 }
  50.                 else
  51.                 {
  52.     // throw an exception or do some error thing here - you've tried to use a command in your script which doesn't exist!
  53.                 }
  54.  
  55.             }
  56.         }
  57.         public bool run(float dt)
  58.         {
  59.             bool shouldBreak = false;
  60.             while ( true )
  61.             {
  62.             if ( m_itemIndex >= (int)m_items.Count )
  63.             {
  64.             return false;
  65.             }
  66.             if ( shouldBreak )
  67.             {
  68.             return true;
  69.             }
  70.             m_items[m_itemIndex].run(dt);
  71.             shouldBreak = m_items[m_itemIndex].shouldUpdateGame();
  72.             if ( m_items[m_itemIndex].isComplete() )
  73.             {
  74.                  ++m_itemIndex;
  75.             }
  76.         }
  77.         }
  78.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement