Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma once
- /*
- * ENTITY SCRIPT DOCUMENTATION
- 1. SYNTAX
- Variable names can contain these characters: 0-9, a-z, A-Z, _(underscore), they start and end with ""'s.
- Variable names cannot have spaces!!!
- Variable values have strings assigned, those are separated from other things by ""'s.
- End of variable definition is marked with ";".
- Strings are one-lined.
- Operator between labels: "." (like Object1.XPosition).
- Assignment operator: "=".
- Blocks have the same naming as variables, but they don't need the ""'s.
- Block beginnings and endings: { and }, respectively.
- 2. SYNTAX EXAMPLE
- Player
- {
- Pistol
- {
- "id" = "1";
- "bullet_count" = "32";
- }
- SMG
- {
- "id" = "2";
- "bullet_count" = "20";
- }
- "action" = "0";
- "last_sentence" = "Awesome!";
- }
- "ambient_color" = "10897245";
- */
- #define ESC_ERRVAL "\n";
- #include <vector>
- #include <map>
- #include <string>
- typedef std::map< std::string, std::string > CStrParamMap;
- struct SParamBlock;
- typedef std::map< std::string, SParamBlock* > CParamBlockMap;
- void EntityScriptError( const char* strError );
- struct SParamBlock
- {
- CStrParamMap m_params;
- CParamBlockMap m_blocks;
- SParamBlock* m_pParent;
- ~SParamBlock();
- std::string GetValue( const char* strKey );
- SParamBlock* GetBlock( const char* strName );
- std::string GetBlockName( SParamBlock* pBlock );
- std::string GetBlockFullName();
- SParamBlock* AddBlock( const char* strName );
- void RemoveBlock( const char* strName );
- void SetValue( const char* strKey, const char* strValue );
- void RemoveValue( const char* strValue );
- };
- class CEntityScript
- {
- public:
- CEntityScript( char* strData, unsigned int uLength );
- std::string Read( const char* strVariable );
- protected:
- SParamBlock m_mainBlock;
- std::vector< std::string > m_strTemp;
- };
- inline
- SParamBlock::~SParamBlock()
- {
- CParamBlockMap::iterator it = m_blocks.begin(), itend = m_blocks.end();
- while( it != itend )
- {
- delete it->second;
- it++;
- }
- }
- inline
- std::string SParamBlock::GetValue(const char *strKey)
- {
- if( m_params.find( strKey ) == m_params.end() )
- return ESC_ERRVAL;
- return m_params[ strKey ];
- }
- inline
- SParamBlock* SParamBlock::GetBlock(const char *strName)
- {
- if( m_blocks.find( strName ) == m_blocks.end() )
- return NULL;
- return m_blocks[ strName ];
- }
- inline
- std::string SParamBlock::GetBlockName(SParamBlock *pBlock)
- {
- CParamBlockMap::iterator it = m_blocks.begin(), itend = m_blocks.end();
- while( it != itend )
- {
- if( it->second == pBlock )
- return it->first;
- it++;
- }
- return ESC_ERRVAL;
- }
- inline
- void SParamBlock::SetValue(const char *strKey, const char *strValue)
- {
- m_params[ strKey ] = strValue;
- }
- inline
- void SParamBlock::RemoveValue(const char *strValue)
- {
- CStrParamMap::iterator it = m_params.find( strValue );
- if( it == m_params.end() )
- {
- std::string sError = "Value \"";
- sError += GetBlockFullName();
- sError += ".";
- sError += strValue;
- sError += " \" not found! (";
- EntityScriptError( sError.c_str() );
- return;
- }
- m_params.erase( it );
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement