Skip to content

Commit 9adb3c7

Browse files
authored
Merge pull request #5753 from ab9rf/hack-path
replace hardcoded `hack` path with `getHackPath()`
2 parents c2e2cae + 0b56dc8 commit 9adb3c7

8 files changed

Lines changed: 19 additions & 19 deletions

File tree

library/include/modules/Textures.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ DFHACK_EXPORT TexposHandle loadTexture(SDL_Surface* surface, bool reserved = fal
3232
* Load tileset from image file.
3333
* Return vector of handles to obtain valid texposes.
3434
*/
35-
DFHACK_EXPORT std::vector<TexposHandle> loadTileset(const std::string& file,
35+
DFHACK_EXPORT std::vector<TexposHandle> loadTileset(const std::filesystem::path file,
3636
int tile_px_w = TILE_WIDTH_PX,
3737
int tile_px_h = TILE_HEIGHT_PX,
3838
bool reserved = false);

library/lua/gui/textures.lua

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,16 @@ local _ENV = mkmodule('gui.textures')
88
-- Use these handles if you need to get dfhack standard textures.
99
---@type table<string, TexposHandle[]>
1010
local texpos_handles = {
11-
green_pin = dfhack.textures.loadTileset('hack/data/art/green-pin.png', 8, 12, true),
12-
red_pin = dfhack.textures.loadTileset('hack/data/art/red-pin.png', 8, 12, true),
13-
icons = dfhack.textures.loadTileset('hack/data/art/icons.png', 8, 12, true),
14-
on_off = dfhack.textures.loadTileset('hack/data/art/on-off.png', 8, 12, true),
15-
control_panel = dfhack.textures.loadTileset('hack/data/art/control-panel.png', 8, 12, true),
16-
border_thin = dfhack.textures.loadTileset('hack/data/art/border-thin.png', 8, 12, true),
17-
border_medium = dfhack.textures.loadTileset('hack/data/art/border-medium.png', 8, 12, true),
18-
border_bold = dfhack.textures.loadTileset('hack/data/art/border-bold.png', 8, 12, true),
19-
border_panel = dfhack.textures.loadTileset('hack/data/art/border-panel.png', 8, 12, true),
20-
border_window = dfhack.textures.loadTileset('hack/data/art/border-window.png', 8, 12, true),
11+
green_pin = dfhack.textures.loadTileset(dfhack.getHackPath()..'/data/art/green-pin.png', 8, 12, true),
12+
red_pin = dfhack.textures.loadTileset(dfhack.getHackPath()..'/data/art/red-pin.png', 8, 12, true),
13+
icons = dfhack.textures.loadTileset(dfhack.getHackPath()..'/data/art/icons.png', 8, 12, true),
14+
on_off = dfhack.textures.loadTileset(dfhack.getHackPath()..'/data/art/on-off.png', 8, 12, true),
15+
control_panel = dfhack.textures.loadTileset(dfhack.getHackPath()..'/data/art/control-panel.png', 8, 12, true),
16+
border_thin = dfhack.textures.loadTileset(dfhack.getHackPath()..'/data/art/border-thin.png', 8, 12, true),
17+
border_medium = dfhack.textures.loadTileset(dfhack.getHackPath()..'/data/art/border-medium.png', 8, 12, true),
18+
border_bold = dfhack.textures.loadTileset(dfhack.getHackPath()..'/data/art/border-bold.png', 8, 12, true),
19+
border_panel = dfhack.textures.loadTileset(dfhack.getHackPath()..'/data/art/border-panel.png', 8, 12, true),
20+
border_window = dfhack.textures.loadTileset(dfhack.getHackPath()..'/data/art/border-window.png', 8, 12, true),
2121
}
2222

2323
-- Get valid texpos for preloaded texture in tileset

library/modules/Textures.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ static ReservedRange reserved_range{};
5454
static std::unordered_map<TexposHandle, long> g_handle_to_texpos;
5555
static std::unordered_map<TexposHandle, long> g_handle_to_reserved_texpos;
5656
static std::unordered_map<TexposHandle, SDL_Surface*> g_handle_to_surface;
57-
static std::unordered_map<std::string, std::vector<TexposHandle>> g_tileset_to_handles;
57+
static std::unordered_map<std::filesystem::path, std::vector<TexposHandle>> g_tileset_to_handles;
5858
static std::vector<TexposHandle> g_delayed_regs;
5959
static std::mutex g_adding_mutex;
6060
static std::atomic<bool> loading_state = false;
@@ -195,14 +195,14 @@ TexposHandle Textures::loadTexture(SDL_Surface* surface, bool reserved) {
195195
return handle;
196196
}
197197

198-
std::vector<TexposHandle> Textures::loadTileset(const std::string& file, int tile_px_w,
198+
std::vector<TexposHandle> Textures::loadTileset(const std::filesystem::path file, int tile_px_w,
199199
int tile_px_h, bool reserved) {
200200
if (g_tileset_to_handles.contains(file))
201201
return g_tileset_to_handles[file];
202202
if (!enabler)
203203
return std::vector<TexposHandle>{};
204204

205-
SDL_Surface* surface = DFIMG_Load(file.c_str());
205+
SDL_Surface* surface = DFIMG_Load(file.string().c_str());
206206
if (!surface) {
207207
ERR(textures).printerr("unable to load textures from '{}'\n", file);
208208
return std::vector<TexposHandle>{};

plugins/dig.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ static bool is_painting_warm = false;
6868
static bool is_painting_damp = false;
6969

7070
DFhackCExport command_result plugin_init ( color_ostream &out, std::vector <PluginCommand> &commands) {
71-
textures = Textures::loadTileset("hack/data/art/damp_dig_map.png", 32, 32, true);
71+
textures = Textures::loadTileset(Core::getInstance().getHackPath() / "data" / "art" / "damp_dig_map.png", 32, 32, true);
7272

7373
commands.push_back(PluginCommand(
7474
"digv",

plugins/lua/dig.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ local gui = require('gui')
44
local overlay = require('plugins.overlay')
55
local widgets = require('gui.widgets')
66

7-
local toolbar_textures = dfhack.textures.loadTileset('hack/data/art/damp_dig_toolbar.png', 8, 12, true)
7+
local toolbar_textures = dfhack.textures.loadTileset(dfhack.getHackPath()..'/data/art/damp_dig_toolbar.png', 8, 12, true)
88

99
local main_if = df.global.game.main_interface
1010
local selection_rect = df.global.selection_rect

plugins/lua/hotkeys.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ local helpdb = require('helpdb')
55
local overlay = require('plugins.overlay')
66
local widgets = require('gui.widgets')
77

8-
local logo_textures = dfhack.textures.loadTileset('hack/data/art/logo.png', 8, 12, true)
8+
local logo_textures = dfhack.textures.loadTileset(dfhack.getHackPath()..'/data/art/logo.png', 8, 12, true)
99

1010
local function get_command(cmdline)
1111
local first_word = cmdline:trim():split(' +')[1]

plugins/lua/suspendmanager.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ end
155155

156156
-- suspend overlay (formerly in unsuspend.lua)
157157

158-
local textures = dfhack.textures.loadTileset('hack/data/art/unsuspend.png', 32, 32, true)
158+
local textures = dfhack.textures.loadTileset(dfhack.getHackPath()..'/data/art/unsuspend.png', 32, 32, true)
159159

160160
local ok, buildingplan = pcall(require, 'plugins.buildingplan')
161161
if not ok then

plugins/pathable.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ namespace DFHack {
4242
static std::vector<TexposHandle> textures;
4343

4444
DFhackCExport command_result plugin_init(color_ostream &out, std::vector<PluginCommand> &commands) {
45-
textures = Textures::loadTileset("hack/data/art/pathable.png", 32, 32, true);
45+
textures = Textures::loadTileset(Core::getInstance().getHackPath() / "data" / "art" / "pathable.png", 32, 32, true);
4646
return CR_OK;
4747
}
4848

0 commit comments

Comments
 (0)