Skip to content

Commit

Permalink
Add ingame support for loading new sound effects
Browse files Browse the repository at this point in the history
  • Loading branch information
crudelios committed Feb 2, 2025
1 parent b77e6bd commit c4ada34
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/building/count.c
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ int building_count_in_area(building_type type, int minx, int miny, int maxx, int
{
int grid_area = (abs(maxx - minx) + 1) * (abs(maxy - miny) + 1);
int array_size = grid_area < building_count() ? grid_area : building_count();
unsigned int *found_buildings = (int *) malloc(array_size * sizeof(unsigned int));
unsigned int *found_buildings = (unsigned int *) malloc(array_size * sizeof(unsigned int));
memset(found_buildings, 0, array_size * sizeof(unsigned int));

int total = 0;
Expand Down
3 changes: 3 additions & 0 deletions src/core/dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,9 @@ const dir_listing *dir_append_files_with_extension(const char *extension)

const char *dir_get_file(const char *filepath, int localizable)
{
if (strncmp(ASSETS_DIRECTORY, filepath, sizeof(ASSETS_DIRECTORY) - 1) == 0) {
return dir_get_file_at_location(filepath + sizeof(ASSETS_DIRECTORY), PATH_LOCATION_ASSET);
}
if (localizable != NOT_LOCALIZED) {
const char *custom_dir = config_get_string(CONFIG_STRING_UI_LANGUAGE_DIR);
if (*custom_dir) {
Expand Down
3 changes: 3 additions & 0 deletions src/core/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ FILE *file_open(const char *filename, const char *mode)
if (!filename) {
return 0;
}
if (strncmp(filename, ASSETS_DIRECTORY, sizeof(ASSETS_DIRECTORY) - 1) == 0) {
return platform_file_manager_open_asset(filename + sizeof(ASSETS_DIRECTORY), mode);
}
return platform_file_manager_open_file(filename, mode);
}

Expand Down
2 changes: 1 addition & 1 deletion src/sound/device.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef SOUND_DEVICE_H
#define SOUND_DEVICE_H

#define CHANNEL_FILENAME_MAX 32
#define CHANNEL_FILENAME_MAX 300

void sound_device_open(void);
void sound_device_close(void);
Expand Down
6 changes: 3 additions & 3 deletions src/sound/system.c
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,9 @@ static char channel_filenames[SOUND_CHANNEL_MAX][CHANNEL_FILENAME_MAX] = {
"wavs/coin.wav",
"wavs/river.wav",
"wavs/mission.wav",
"assets/sounds/brickworks.wav",
"assets/sounds/lighthouse.wav",
"assets/sounds/ox.wav",
ASSETS_DIRECTORY "/Sounds/Brickworks.wav",
ASSETS_DIRECTORY "/Sounds/Lighthouse.wav",
ASSETS_DIRECTORY "/Sounds/Ox.wav",
};

static void correct_channel_filenames(void)
Expand Down
3 changes: 2 additions & 1 deletion src/window/building/culture.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "city/festival.h"
#include "city/finance.h"
#include "city/trade_policy.h"
#include "core/dir.h"
#include "graphics/button.h"
#include "graphics/generic_button.h"
#include "graphics/image.h"
Expand Down Expand Up @@ -1201,7 +1202,7 @@ void window_building_draw_lighthouse(building_info_context *c)
building *b = building_get(c->building_id);
if (b->monument.phase == MONUMENT_FINISHED) {
c->advisor_button = ADVISOR_TRADE;
window_building_play_sound(c, "assets/sounds/lighthouse.wav");
window_building_play_sound(c, ASSETS_DIRECTORY "/Sounds/Lighthouse.wav");
outer_panel_draw(c->x_offset, c->y_offset, c->width_blocks, c->height_blocks);

image_draw(resource_get_data(RESOURCE_TIMBER)->image.icon, c->x_offset + 32, c->y_offset + 46,
Expand Down
3 changes: 2 additions & 1 deletion src/window/building/industry.c
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,8 @@ void window_building_draw_pottery_workshop(building_info_context *c)

void window_building_draw_brickworks(building_info_context *c)
{
draw_workshop(c, 1, "assets/sounds/brickworks.wav", CUSTOM_TRANSLATION, TR_BUILDING_BRICKWORKS, RESOURCE_BRICKS);
draw_workshop(c, 1, ASSETS_DIRECTORY "/Sounds/Brickworks.wav", CUSTOM_TRANSLATION,
TR_BUILDING_BRICKWORKS, RESOURCE_BRICKS);
}

void window_building_draw_concrete_maker(building_info_context *c)
Expand Down

0 comments on commit c4ada34

Please sign in to comment.