<commit_before>#include <assert.h> // assert
#include <stdlib.h> // malloc free

#include "shoveler/view/resources.h"
#include "shoveler/view/tilemap.h"
#include "shoveler/view/tileset.h"
#include "shoveler/log.h"

typedef struct {
	ShovelerViewTilemapConfiguration configuration;
	int numLayers;
	ShovelerTexture **layers;
	int numTilesets;
	ShovelerMaterialTilemapTileset **tilesets;
} ComponentData;

static bool activateComponent(ShovelerViewComponent *component, void *componentDataPointer);
static void deactivateComponent(ShovelerViewComponent *component, void *componentDataPointer);
static void freeComponent(ShovelerViewComponent *component, void *componentDataPointer);

bool shovelerViewEntityAddTilemap(ShovelerViewEntity *entity, ShovelerViewTilemapConfiguration configuration)
{
	ShovelerViewComponent *component = shovelerViewEntityGetComponent(entity, shovelerViewTilemapComponentName);
	if(component != NULL) {
		shovelerLogWarning("Trying to add tilemap to entity %lld which already has a tilemap, ignoring.", entity->entityId);
		return false;
	}

	ComponentData *componentData = malloc(sizeof(ComponentData));
	componentData->configuration = configuration;
	componentData->numLayers = 0;
	componentData->layers = NULL;
	componentData->numTilesets = 0;
	componentData->tilesets = NULL;

	component = shovelerViewEntityAddComponent(entity, shovelerViewTilemapComponentName, componentData, activateComponent, deactivateComponent, freeComponent);
	assert(component != NULL);

	for(int i = 0; i < configuration.numLayers; i++) {
		shovelerViewComponentAddDependency(component, configuration.layerImageResourceEntityIds[i], shovelerViewResourceComponentName);
	}
	for(int i = 0; i < configuration.numTilesets; i++) {
		shovelerViewComponentAddDependency(component, configuration.tilesetEntityIds[i], shovelerViewTilesetComponentName);
	}

	shovelerViewComponentActivate(component);
	return true;
}

bool shovelerViewEntityGetTilemapLayers(ShovelerViewEntity *entity, int *numLayersPointer, ShovelerTexture ***layersPointer)
{
	ShovelerViewComponent *component = shovelerViewEntityGetComponent(entity, shovelerViewTilemapComponentName);
	if(component == NULL) {
		return false;
	}

	ComponentData *componentData = component->data;
	*numLayersPointer = componentData->numLayers;
	*layersPointer = componentData->layers;
	return true;
}

bool shovelerViewEntityGetTilemapTilesets(ShovelerViewEntity *entity, int *numTilesetsPointer, ShovelerMaterialTilemapTileset ***tilesetsPointer)
{
	ShovelerViewComponent *component = shovelerViewEntityGetComponent(entity, shovelerViewTilemapComponentName);
	if(component == NULL) {
		return false;
	}

	ComponentData *componentData = component->data;
	*numTilesetsPointer = componentData->numLayers;
	*tilesetsPointer = componentData->tilesets;
	return true;
}

const ShovelerViewTilemapConfiguration *shovelerViewEntityGetTilemapConfiguration(ShovelerViewEntity *entity)
{
	ShovelerViewComponent *component = shovelerViewEntityGetComponent(entity, shovelerViewTilemapComponentName);
	if(component == NULL) {
		return false;
	}

	ComponentData *componentData = component->data;
	return &componentData->configuration;
}

bool shovelerViewEntityUpdateTilemap(ShovelerViewEntity *entity, ShovelerViewTilemapConfiguration configuration)
{<commit_msg>fixed invalid number of tilesets being returned by tilemap component in view<commit_after>#include <assert.h> // assert
#include <stdlib.h> // malloc free

#include "shoveler/view/resources.h"
#include "shoveler/view/tilemap.h"
#include "shoveler/view/tileset.h"
#include "shoveler/log.h"

typedef struct {
	ShovelerViewTilemapConfiguration configuration;
	int numLayers;
	ShovelerTexture **layers;
	int numTilesets;
	ShovelerMaterialTilemapTileset **tilesets;
} ComponentData;

static bool activateComponent(ShovelerViewComponent *component, void *componentDataPointer);
static void deactivateComponent(ShovelerViewComponent *component, void *componentDataPointer);
static void freeComponent(ShovelerViewComponent *component, void *componentDataPointer);

bool shovelerViewEntityAddTilemap(ShovelerViewEntity *entity, ShovelerViewTilemapConfiguration configuration)
{
	ShovelerViewComponent *component = shovelerViewEntityGetComponent(entity, shovelerViewTilemapComponentName);
	if(component != NULL) {
		shovelerLogWarning("Trying to add tilemap to entity %lld which already has a tilemap, ignoring.", entity->entityId);
		return false;
	}

	ComponentData *componentData = malloc(sizeof(ComponentData));
	componentData->configuration = configuration;
	componentData->numLayers = 0;
	componentData->layers = NULL;
	componentData->numTilesets = 0;
	componentData->tilesets = NULL;

	component = shovelerViewEntityAddComponent(entity, shovelerViewTilemapComponentName, componentData, activateComponent, deactivateComponent, freeComponent);
	assert(component != NULL);

	for(int i = 0; i < configuration.numLayers; i++) {
		shovelerViewComponentAddDependency(component, configuration.layerImageResourceEntityIds[i], shovelerViewResourceComponentName);
	}
	for(int i = 0; i < configuration.numTilesets; i++) {
		shovelerViewComponentAddDependency(component, configuration.tilesetEntityIds[i], shovelerViewTilesetComponentName);
	}

	shovelerViewComponentActivate(component);
	return true;
}

bool shovelerViewEntityGetTilemapLayers(ShovelerViewEntity *entity, int *numLayersPointer, ShovelerTexture ***layersPointer)
{
	ShovelerViewComponent *component = shovelerViewEntityGetComponent(entity, shovelerViewTilemapComponentName);
	if(component == NULL) {
		return false;
	}

	ComponentData *componentData = component->data;
	*numLayersPointer = componentData->numLayers;
	*layersPointer = componentData->layers;
	return true;
}

bool shovelerViewEntityGetTilemapTilesets(ShovelerViewEntity *entity, int *numTilesetsPointer, ShovelerMaterialTilemapTileset ***tilesetsPointer)
{
	ShovelerViewComponent *component = shovelerViewEntityGetComponent(entity, shovelerViewTilemapComponentName);
	if(component == NULL) {
		return false;
	}

	ComponentData *componentData = component->data;
	*numTilesetsPointer = componentData->numTilesets;
	*tilesetsPointer = componentData->tilesets;
	return true;
}

const ShovelerViewTilemapConfiguration *shovelerViewEntityGetTilemapConfiguration(ShovelerViewEntity *entity)
{
	ShovelerViewComponent *component = shovelerViewEntityGetComponent(entity, shovelerViewTilemapComponentName);
	if(component == NULL) {
		return false;
	}

	ComponentData *componentData = component->data;
	return &componentData->configuration;
}

bool shovelerViewEntityUpdateTilemap(ShovelerViewEntity *entity, ShovelerViewTilemapConfiguration configuration)
{
{'fraction_non_alphanumeric': 0.08830154677879562, 'fraction_numerical': 0.0012013815888271512, 'mean_word_length': 8.541547277936962, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3917912', 'n_tokens_mistral': 2002, 'n_tokens_neox': 1926, 'n_words': 383}