Blamite Game Engine - Blam (Core)
haloscript.h
Go to the documentation of this file.
1 #pragma once
2 
4 
5 #include <string>
6 #include <map>
7 #include <vector>
8 
9 #define GVARS_FILE "./gvars.xml"
10 
11 
12 #ifndef BLAM
13 #define BLAM
14 #endif
15 
16 #ifndef HSC
17 #define HSC
18 #endif
19 
20 namespace Blam
21 {
28  {
29  public:
30  std::string name;
31  std::string description;
32  std::string action;
33  };
34 
38  BLAM command_object CreateCommandFromFile(std::string filename);
39 
43  BLAM std::string get_csc_cmd_name(std::string filename);
44 
48  BLAM std::string csc_var_process(std::string const& s);
49 
53  BLAM std::string csc_var_process(std::string const& s, char read_until);
54 }
55 
56 namespace BlamScript
57 {
61  namespace Globals
62  {
67  {
70  Ok,
74  };
75 
79  enum GvarType
80  {
82  Real,
84  Long,
87  Int,
90  };
91 
103  {
105  std::string name = "";
106  std::string info = "";
107  std::string value_raw = "";
108  bool read_only = false;
109 
111  // Additional value storage types, these are used in place of value_raw based on type. //
113 
114  bool boolean_value = false;
115  short short_value = 0;
116  long long_value = 0;
117  int int_value = 0;
118  float float_value = 0.0f;
120  };
121 
130  HSC std::map<std::string, ScriptGlobal>* GetGlobalsList();
131 
137  HSC bool LoadGlobalsFromFile();
138 
146  HSC std::string GetGvarTypeLabel(GvarType type);
147 
155  HSC bool GlobalExists(std::string id);
156 
162  HSC void RegisterGvar(ScriptGlobal var);
163 
171  HSC void RegisterGvar(std::string name, std::string value_raw, GvarType type);
172 
181  HSC void RegisterGvar(std::string name, std::string value_raw, GvarType type, std::string info);
182 
190  HSC ScriptGlobal* GetGlobal(std::string name);
191 
200  HSC GvarUpdateResult UpdateGlobalWrap(std::string name, std::string new_value);
201 
210  HSC GvarUpdateResult UpdateGlobal(std::string name, std::string new_value);
211 
220  HSC GvarUpdateResult UpdateGlobal(std::string name, bool new_value);
221 
230  HSC GvarUpdateResult UpdateGlobal(std::string name, int new_value);
231 
240  HSC GvarUpdateResult UpdateGlobal(std::string name, short new_value);
241 
250  HSC GvarUpdateResult UpdateGlobal(std::string name, long new_value);
251 
260  HSC GvarUpdateResult UpdateGlobal(std::string name, float new_value);
261 
270  HSC GvarUpdateResult UpdateGlobal(std::string name, BlamColor new_value);
271 
279  HSC bool* GetGlobalAsBoolean(std::string name);
280 
288  HSC std::string* GetGlobalAsString(std::string name);
289 
297  HSC short* GetGlobalAsShort(std::string name);
298 
306  HSC long* GetGlobalAsLong(std::string name);
307 
315  HSC int* GetGlobalAsInteger(std::string name);
316 
324  HSC float* GetGlobalAsFloat(std::string name);
325 
333  HSC BlamColor* GetGlobalAsColor(std::string name);
334  }
335 
336  // old garbage below this line, cool new shit above this line
337 
339  // Everything here is used for parsing BlamScript/HaloScript files (.hsc) //
341 
342  //Classes
343 
348  public:
349  std::string type;
350  std::vector<std::string> arguments;
351  };
352 
357  public:
358  std::string name;
359  std::string description;
360  std::vector<script_action> actions;
361  };
362 
366  class script_gvar {
367  public:
368  std::string name;
369  std::vector<std::string> arguments;
370  };
371 
376  public:
377  std::vector<script_gvar> global_vars;
378  std::vector<script_action> actions;
379  };
380 
381  //Functions
382 
386  HSC cmd_script_object parse_cmd_script(std::string filename); //Reads a script as a command
387 
391  HSC std::string get_cmd_name(std::string filename); //Gets ONLY the command name from a HSC file
392 
396  HSC std::vector<std::string> getCommandsCSC();
397 
401  HSC std::vector<cmd_script_object> getCommandsHSC();
402 
406  HSC std::vector<std::string> get_csc_data();
407 
411  HSC std::vector<cmd_script_object> get_hsc_data();
412 
416  HSC void InitCSC();
417 
421  HSC void InitHSC();
422 }
Blam
Namespace surrounding all major engine components.
Definition: blam_api.h:17
Blam::CreateCommandFromFile
BLAM command_object CreateCommandFromFile(std::string filename)
Definition: command_script.cpp:84
BlamScript::Globals::GetGlobalAsBoolean
HSC bool * GetGlobalAsBoolean(std::string name)
Retrieves a global's value as a boolean.
Definition: script_globals.cpp:337
Blam::command_object::description
std::string description
Definition: haloscript.h:31
BlamScript::Globals::GetGvarTypeLabel
HSC std::string GetGvarTypeLabel(GvarType type)
Retrieves a string representation of a global's type, for use in UI.
Definition: script_globals.cpp:40
BlamScript::Globals::ScriptGlobal::long_value
long long_value
The long value of the global.
Definition: haloscript.h:116
BlamScript::script_action
Definition: haloscript.h:347
BlamScript::Globals::InvalidType
@ InvalidType
The provided value was of an invalid type.
Definition: haloscript.h:68
BlamScript::script_gvar::arguments
std::vector< std::string > arguments
Definition: haloscript.h:369
BlamScript::Globals::ScriptGlobal::color_value
BlamColor color_value
The color value of the global.
Definition: haloscript.h:119
BlamScript::Globals::Color
@ Color
Represents a BlamColor. See BlamColor for details.
Definition: haloscript.h:89
BlamScript::cmd_script_object::name
std::string name
Definition: haloscript.h:358
BlamScript::Globals::ScriptGlobal::boolean_value
bool boolean_value
The boolean value of the global.
Definition: haloscript.h:114
BlamScript::Globals::GetGlobalAsFloat
HSC float * GetGlobalAsFloat(std::string name)
Retrieves a global's value as a float.
Definition: script_globals.cpp:403
BlamScript::parse_cmd_script
HSC cmd_script_object parse_cmd_script(std::string filename)
Definition: blamscript.cpp:75
BlamScript::cmd_script_object
Definition: haloscript.h:356
Blam::command_object::name
std::string name
Definition: haloscript.h:30
BlamScript::getCommandsCSC
HSC std::vector< std::string > getCommandsCSC()
Definition: command_script.cpp:20
BlamScript::Globals::ScriptGlobal::type
GvarType type
The type of the global.
Definition: haloscript.h:104
BlamScript::script_object::global_vars
std::vector< script_gvar > global_vars
Definition: haloscript.h:377
BlamScript::Globals::GetGlobalAsLong
HSC long * GetGlobalAsLong(std::string name)
Retrieves a global's value as a long.
Definition: script_globals.cpp:377
Blam::command_object
Legacy class representing a CommandScript command.
Definition: haloscript.h:27
BlamScript::Globals::RegisterGvar
HSC void RegisterGvar(ScriptGlobal var)
Registers a new engine global.
Definition: script_globals.cpp:65
BlamScript::Globals::Int
@ Int
Represents an int.
Definition: haloscript.h:87
BlamScript::Globals::UnknownGlobal
@ UnknownGlobal
The specified global does not exist.
Definition: haloscript.h:69
Blam::command_object::action
std::string action
Definition: haloscript.h:32
BlamScript::Globals::ScriptGlobal::name
std::string name
The name of the global.
Definition: haloscript.h:105
BlamScript::Globals::InvalidArgs
@ InvalidArgs
The provided arguments were invalid.
Definition: haloscript.h:71
BlamScript::Globals::Boolean
@ Boolean
Represents a boolean. Can be true or false.
Definition: haloscript.h:81
BlamScript::Globals::GetGlobalsList
HSC std::map< std::string, ScriptGlobal > * GetGlobalsList()
Retrieves the list of loaded globals.
Definition: script_globals.cpp:22
BlamScript::script_object
Definition: haloscript.h:375
BlamScript::Globals::GetGlobalAsColor
HSC BlamColor * GetGlobalAsColor(std::string name)
Retrieves a global's value as a BlamColor.
Definition: script_globals.cpp:416
BlamScript::script_action::arguments
std::vector< std::string > arguments
Definition: haloscript.h:350
BlamScript::Globals::Object
@ Object
Unknown. Referenced within the hs_doc from Halo 2 Sapien.
Definition: haloscript.h:85
BlamScript::script_action::type
std::string type
Definition: haloscript.h:349
BlamScript::get_hsc_data
HSC std::vector< cmd_script_object > get_hsc_data()
Definition: blamscript.cpp:444
Blam::get_csc_cmd_name
BLAM std::string get_csc_cmd_name(std::string filename)
Definition: command_script.cpp:172
BlamScript::Globals::UpdateGlobal
HSC GvarUpdateResult UpdateGlobal(std::string name, std::string new_value)
Updates the value of a String global.
Definition: script_globals.cpp:576
BlamScript::Globals::ScriptGlobal::read_only
bool read_only
Whether or not the global is protected from modification.
Definition: haloscript.h:108
BlamScript
Definition: haloscript.h:56
BlamScript::Globals::LoadGlobalsFromFile
HSC bool LoadGlobalsFromFile()
Loads any globals from GVARS_FILE.
Definition: script_globals.cpp:206
BlamScript::Globals::GlobalIsProtected
@ GlobalIsProtected
The specified global is protected and cannot be modified during runtime.
Definition: haloscript.h:73
BlamScript::script_gvar::name
std::string name
Definition: haloscript.h:368
BlamScript::Globals::OutOfBounds
@ OutOfBounds
The provided value was too small or too large for the globals' data type.
Definition: haloscript.h:72
BlamScript::Globals::GetGlobalAsInteger
HSC int * GetGlobalAsInteger(std::string name)
Retrieves a global's value as an int.
Definition: script_globals.cpp:390
BlamScript::get_csc_data
HSC std::vector< std::string > get_csc_data()
Definition: command_script.cpp:443
BlamScript::Globals::ScriptGlobal::float_value
float float_value
The float value of the global.
Definition: haloscript.h:118
BlamScript::getCommandsHSC
HSC std::vector< cmd_script_object > getCommandsHSC()
Definition: blamscript.cpp:20
BlamScript::Globals::ScriptGlobal::value_raw
std::string value_raw
The raw value of the global as a string.
Definition: haloscript.h:107
colors.h
BlamScript::Globals::Float
@ Float
Represents a float.
Definition: haloscript.h:88
BlamScript::InitCSC
HSC void InitCSC()
Definition: command_script.cpp:14
BlamScript::Globals::Long
@ Long
Represents a long.
Definition: haloscript.h:84
BlamScript::script_gvar
Definition: haloscript.h:366
BlamScript::Globals::GetGlobal
HSC ScriptGlobal * GetGlobal(std::string name)
Retrieves a global with the specified ID.
Definition: script_globals.cpp:193
BlamScript::Globals::UpdateGlobalWrap
HSC GvarUpdateResult UpdateGlobalWrap(std::string name, std::string new_value)
Updates a global's raw value.
Definition: script_globals.cpp:433
BlamScript::Globals::ScriptGlobal
Structure containing data for a game engine global.
Definition: haloscript.h:102
BLAM
#define BLAM
Definition: haloscript.h:13
BlamScript::Globals::GetGlobalAsString
HSC std::string * GetGlobalAsString(std::string name)
Retrieves a global's value as a string.
Definition: script_globals.cpp:350
BlamScript::script_object::actions
std::vector< script_action > actions
Definition: haloscript.h:378
BlamScript::Globals::GetGlobalAsShort
HSC short * GetGlobalAsShort(std::string name)
Retrieves a global's value as a short.
Definition: script_globals.cpp:364
BlamScript::cmd_script_object::description
std::string description
Definition: haloscript.h:359
BlamScript::InitHSC
HSC void InitHSC()
Definition: blamscript.cpp:14
BlamScript::Globals::Real
@ Real
Unknown. Referenced within the hs_doc from Halo 2 Sapien.
Definition: haloscript.h:82
Blam::csc_var_process
BLAM std::string csc_var_process(std::string const &s)
Definition: command_script.cpp:448
BlamScript::get_cmd_name
HSC std::string get_cmd_name(std::string filename)
Definition: blamscript.cpp:387
BlamScript::Globals::GlobalExists
HSC bool GlobalExists(std::string id)
Determines whether or not a global exists.
Definition: script_globals.cpp:27
BlamScript::cmd_script_object::actions
std::vector< script_action > actions
Definition: haloscript.h:360
BlamColor
Structure representing a color.
Definition: colors.h:18
BlamScript::Globals::ScriptGlobal::info
std::string info
An optional description of the global.
Definition: haloscript.h:106
BlamScript::Globals::ScriptGlobal::int_value
int int_value
The int value of the global.
Definition: haloscript.h:117
BlamScript::Globals::String
@ String
Represents a std::string.
Definition: haloscript.h:86
HSC
#define HSC
Definition: haloscript.h:17
BlamScript::Globals::Ok
@ Ok
The global was updated successfully.
Definition: haloscript.h:70
BlamScript::Globals::GvarUpdateResult
GvarUpdateResult
Enumerator for the result of a global update attempt.
Definition: haloscript.h:66
BlamScript::Globals::ScriptGlobal::short_value
short short_value
The short value of the global.
Definition: haloscript.h:115
BlamScript::Globals::Short
@ Short
Represents a short.
Definition: haloscript.h:83
BlamScript::Globals::GvarType
GvarType
Enumerator for the type of global variable.
Definition: haloscript.h:79