EditScript.h 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. /*
  2. ** Command & Conquer Renegade(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /***********************************************************************************************
  19. *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
  20. ***********************************************************************************************
  21. * *
  22. * Project Name : LevelEdit *
  23. * *
  24. * $Archive:: /Commando/Code/Tools/LevelEdit/EditScript.h $*
  25. * *
  26. * Author:: Patrick Smith *
  27. * *
  28. * $Modtime:: 11/02/00 3:57p $*
  29. * *
  30. * $Revision:: 3 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #if defined(_MSC_VER)
  36. #pragma once
  37. #endif
  38. #ifndef __EDIT_SCRIPT_H
  39. #define __EDIT_SCRIPT_H
  40. #include "..\..\scripts\scriptevents.h"
  41. #include "vector.h"
  42. #include "utils.h"
  43. #include "wwstring.h"
  44. // Forward declarations
  45. class ChunkSaveClass;
  46. class ChunkLoadClass;
  47. //////////////////////////////////////////////////////////////////////////
  48. //
  49. // EditScriptClass
  50. //
  51. //////////////////////////////////////////////////////////////////////////
  52. class EditScriptClass
  53. {
  54. public:
  55. //////////////////////////////////////////////////////////////
  56. // Public constructors/destructors
  57. //////////////////////////////////////////////////////////////
  58. EditScriptClass (void);
  59. EditScriptClass (const EditScriptClass &src);
  60. virtual ~EditScriptClass (void);
  61. //////////////////////////////////////////////////////////////
  62. // Public operators
  63. //////////////////////////////////////////////////////////////
  64. const EditScriptClass & operator= (const EditScriptClass &src);
  65. bool operator== (const EditScriptClass &src);
  66. //////////////////////////////////////////////////////////////
  67. // Public methods
  68. //////////////////////////////////////////////////////////////
  69. EditScriptClass * Clone (void) { return new EditScriptClass (*this); }
  70. ScriptClass * Create_Script (void);
  71. //
  72. // Name/string methods
  73. //
  74. LPCTSTR Get_Name (void) const;
  75. void Set_Name (LPCTSTR name);
  76. void Set_Param_Desc (LPCTSTR param_desc);
  77. void Lookup_Param_Description (void);
  78. CString Get_Composite_String (void) { return Build_Composite_String (); }
  79. void Set_Composite_Values (LPCTSTR values);
  80. //
  81. // Param methods
  82. //
  83. int Get_Param_Count (void);
  84. LPCTSTR Get_Param_Value (int index);
  85. LPCTSTR Get_Param_Name (int index);
  86. PARAM_TYPES Get_Param_Type (int index);
  87. void Set_Param_Value (int index, LPCTSTR value);
  88. //
  89. // Persistance methods
  90. //
  91. bool Save (ChunkSaveClass &csave);
  92. bool Load (ChunkLoadClass &cload);
  93. protected:
  94. //////////////////////////////////////////////////////////////
  95. // Protected data types
  96. //////////////////////////////////////////////////////////////
  97. typedef struct _PARAM_VALUE
  98. {
  99. CString name;
  100. CString value;
  101. PARAM_TYPES type;
  102. bool operator== (const _PARAM_VALUE &src) { return (type == src.type) && (value == src.value) && (name == src.name); }
  103. bool operator!= (const _PARAM_VALUE &src) { return !(*this == src); }
  104. } PARAM_VALUE;
  105. //////////////////////////////////////////////////////////////
  106. // Protected methods
  107. //////////////////////////////////////////////////////////////
  108. bool Load_Variables (ChunkLoadClass &cload);
  109. CString Build_Composite_String (void) const;
  110. void Update_Data (void);
  111. PARAM_TYPES String_To_Type (LPCTSTR type_name);
  112. bool Valid_Index (int index) const { return (index >= 0) && (index < m_ParamValues.Count ()); }
  113. private:
  114. /////////////////////////////////////////////////////////////////////
  115. // Private methods
  116. /////////////////////////////////////////////////////////////////////
  117. StringClass m_Name;
  118. DynamicVectorClass<PARAM_VALUE> m_ParamValues;
  119. StringClass m_ParamDescription;
  120. };
  121. //////////////////////////////////////////////////////////////
  122. // Set_Param_Desc
  123. //////////////////////////////////////////////////////////////
  124. inline void
  125. EditScriptClass::Set_Param_Desc (LPCTSTR param_desc)
  126. {
  127. m_ParamDescription = param_desc;
  128. Update_Data ();
  129. return ;
  130. }
  131. //////////////////////////////////////////////////////////////
  132. // Get_Param_Count
  133. //////////////////////////////////////////////////////////////
  134. inline int
  135. EditScriptClass::Get_Param_Count (void)
  136. {
  137. return m_ParamValues.Count ();;
  138. }
  139. //////////////////////////////////////////////////////////////
  140. // Get_Param_Value
  141. //////////////////////////////////////////////////////////////
  142. inline LPCTSTR
  143. EditScriptClass::Get_Param_Value (int index)
  144. {
  145. LPCTSTR value = NULL;
  146. if (Valid_Index (index)) {
  147. value = m_ParamValues[index].value;
  148. }
  149. return value;
  150. }
  151. //////////////////////////////////////////////////////////////
  152. // Get_Param_Name
  153. //////////////////////////////////////////////////////////////
  154. inline LPCTSTR
  155. EditScriptClass::Get_Param_Name (int index)
  156. {
  157. LPCTSTR name = NULL;
  158. if (Valid_Index (index)) {
  159. name = m_ParamValues[index].name;
  160. }
  161. return name;
  162. }
  163. //////////////////////////////////////////////////////////////
  164. // Get_Param_Type
  165. //////////////////////////////////////////////////////////////
  166. inline PARAM_TYPES
  167. EditScriptClass::Get_Param_Type (int index)
  168. {
  169. PARAM_TYPES type = PARAM_TYPE_INT;
  170. if (Valid_Index (index)) {
  171. type = m_ParamValues[index].type;
  172. }
  173. return type;
  174. }
  175. //////////////////////////////////////////////////////////////
  176. // Set_Param_Value
  177. //////////////////////////////////////////////////////////////
  178. inline void
  179. EditScriptClass::Set_Param_Value (int index, LPCTSTR value)
  180. {
  181. if (Valid_Index (index)) {
  182. m_ParamValues[index].value = value;
  183. }
  184. return ;
  185. }
  186. INLINE_ACCESSOR_CONST (LPCTSTR, EditScriptClass, Name);
  187. #endif //__EDIT_SCRIPT_H