Collab_RPG/src/events.h

61 lines
1.6 KiB
C
Raw Normal View History

2024-07-20 16:53:13 +02:00
#ifndef EVENTS_H
#define EVENTS_H
2024-07-24 21:43:21 +02:00
/* The max amount of variables that can be bound. */
2024-07-20 16:53:13 +02:00
#define MAX_VARIABLES 32
2024-07-24 21:43:21 +02:00
/* The max. size of the message buffer.
* WARNING: Bigger messages will be truncated! */
2024-07-20 17:44:44 +02:00
#define MESSAGE_BUFFER_SZ 1024
2024-07-24 21:43:21 +02:00
/* The maximal size of a token. Bigger tokens will be truncated. */
2024-07-20 17:44:44 +02:00
#define TOKEN_MAX_SZ 1024
2024-07-20 16:53:13 +02:00
typedef struct {
int *variables[MAX_VARIABLES];
char *var_names[MAX_VARIABLES];
unsigned int vars;
} EventHandler;
2024-07-29 11:36:11 +02:00
typedef enum { T_NULL, T_VAR_EDIT, T_AMOUNT } Token;
2024-07-20 16:53:13 +02:00
typedef enum {
OP_NULL,
OP_SET,
OP_ADD,
OP_SUB,
OP_DIV,
OP_MUL,
OP_MOD,
OP_AMOUNT
} Operation;
2024-07-24 21:43:21 +02:00
/* events_init_handler()
*
* Initialize an event handler.
* handler: The Event handler to initialize.
*/
2024-07-20 16:53:13 +02:00
void events_init_handler(EventHandler *handler);
2024-07-24 21:43:21 +02:00
/* events_bind_variable()
2024-07-29 11:36:11 +02:00
*
2024-07-24 21:43:21 +02:00
* 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.
*/
2024-07-20 16:53:13 +02:00
int events_bind_variable(EventHandler *handler, int *var, char *name);
2024-07-24 21:43:21 +02:00
/* events_parse_string()
* handler: The event handler.
* message: The message to parse.
*/
2024-07-20 16:53:13 +02:00
char *events_parse_string(EventHandler *handler, char *message);
#endif