~kikoodx/sle

cb9bc1e9ba0ff74ea57078d84257c5f81dd312c0 — KikooDX 2 years ago fc21450 main
shift level data w/ arr keys
4 files changed, 58 insertions(+), 1 deletions(-)

M README
M include/editing_area/level.h
M src/editing_area/level.c
M src/editing_area/main.c
M README => README +5 -0
@@ 43,6 43,11 @@ Middle click: pick a tile
Click on a first tile while holding nothing, then click on another tile
holding Left Control and the area between the two points will be filled.

Left arrow key: shift the level data towards the left
Right arrow key: shift the level data towards the right
Up arrow key: shift the level data towards the top
Down arrow key: shift the level data towards the bottom

Secondary window - Tile Picker
------------------------------
Left click on the tile you want to select.

M include/editing_area/level.h => include/editing_area/level.h +3 -1
@@ 17,4 17,6 @@ int level_read(struct Level *, char *path);
int level_create(struct Level *, struct Options options);
void level_free(struct Level *);
/* return -1 if error */
int level_write(struct Level level, char *path);
int level_write(struct Level, char *path);
void level_rotate_r(struct Level, int n);
void level_rotate_l(struct Level, int n);

M src/editing_area/level.c => src/editing_area/level.c +24 -0
@@ 183,6 183,30 @@ int level_write(struct Level level, char *path)
	return 0;
}

void level_rotate_r(struct Level l, int n)
{
	while (n-- > 0) {
		const int size = l.width * l.height;
		int i = size;
		int last = l.data[size - 1];
		while (--i > 0)
			l.data[i] = l.data[i - 1];
		l.data[0] = last;
	}
}

void level_rotate_l(struct Level l, int n)
{
	while (n-- > 0) {
		const int size = l.width * l.height;
		int i = -1;
		int first = l.data[0];
		while (++i < size - 1)
			l.data[i] = l.data[i + 1];
		l.data[size - 1] = first;
	}
}

/* Read a single byte safely (handle EOF). Return -1 if error. */
static int read_byte(FILE *file)
{

M src/editing_area/main.c => src/editing_area/main.c +26 -0
@@ 134,6 134,22 @@ static void update_mouse(int *mouse_x, int *mouse_y, struct Level level,
	const bool right_click = IsMouseButtonDown(1);
	const bool middle_click = IsMouseButtonPressed(2);
	const bool k_lctrl = IsKeyDown(KEY_LEFT_CONTROL);
	static bool pk_left = false;
	const bool k_left = IsKeyDown(KEY_LEFT);
	const bool kp_left = !pk_left && k_left;
	static bool pk_right = false;
	const bool k_right = IsKeyDown(KEY_RIGHT);
	const bool kp_right = !pk_right && k_right;
	static bool pk_up = false;
	const bool k_up = IsKeyDown(KEY_UP);
	const bool kp_up = !pk_up && k_up;
	static bool pk_down = false;
	const bool k_down = IsKeyDown(KEY_DOWN);
	const bool kp_down = !pk_down && k_down;
	pk_left = k_left;
	pk_right = k_right;
	pk_up = k_up;
	pk_down = k_down;

	update_mouse_position(mouse_x, mouse_y, level.width - 1,
	                      level.height - 1);


@@ 170,6 186,16 @@ static void update_mouse(int *mouse_x, int *mouse_y, struct Level level,
		shared_data->selected_tile =
		    level.data[*mouse_x + *mouse_y * level.width];
	}

	/* rotate data */
	if (kp_left)
		level_rotate_l(level, 1);
	if (kp_right)
		level_rotate_r(level, 1);
	if (kp_up)
		level_rotate_l(level, level.width);
	if (kp_down)
		level_rotate_r(level, level.width);
}

static void set_tile(struct Level l, int x, int y, int v)