Collab_RPG/src/events.h
2024-07-29 11:36:11 +02:00

60 lines
1.6 KiB
C

#ifndef EVENTS_H
#define EVENTS_H
/* The max amount of variables that can be bound. */
#define MAX_VARIABLES 32
/* The max. size of the message buffer.
* WARNING: Bigger messages will be truncated! */
#define MESSAGE_BUFFER_SZ 1024
/* The maximal size of a token. Bigger tokens will be truncated. */
#define TOKEN_MAX_SZ 1024
typedef struct {
int *variables[MAX_VARIABLES];
char *var_names[MAX_VARIABLES];
unsigned int vars;
} EventHandler;
typedef enum { T_NULL, T_VAR_EDIT, T_AMOUNT } Token;
typedef enum {
OP_NULL,
OP_SET,
OP_ADD,
OP_SUB,
OP_DIV,
OP_MUL,
OP_MOD,
OP_AMOUNT
} Operation;
/* events_init_handler()
*
* Initialize an event handler.
* handler: The Event handler to initialize.
*/
void events_init_handler(EventHandler *handler);
/* events_bind_variable()
*
* Bind a variable. Binding a variable allows it to be modified by messages
* passed to the event handler using tags written as following:
* `variable+number` (The backticks delimit the tag). Available operators:
* '=': Assign a value to the variable.
* '+': Addition.
* '-': Substraction.
* '*': Multiplication.
* '/': Division.
* '%': Modulo.
* handler: The event handler.
* var: A pointer to the variable to bind.
* name: The name of the variable. This is the name that will be used to
* refer to this variable in a tag.
*/
int events_bind_variable(EventHandler *handler, int *var, char *name);
/* events_parse_string()
* handler: The event handler.
* message: The message to parse.
*/
char *events_parse_string(EventHandler *handler, char *message);
#endif