Skip to content

Commit 9da6d1d

Browse files
committed
Adds tilde (~) expansion to map load and save
1 parent f07dd01 commit 9da6d1d

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

map.lua

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@ local info = Util.info
88
local Map = {}
99
Map.__index = Map
1010

11+
local function expand_tilde(path)
12+
if path:find("^~") ~= nil then
13+
return format("%s%s", os.getenv("HOME"), path:sub(2))
14+
else
15+
return path
16+
end
17+
end
18+
1119
function Map.new(name)
1220
local ret = setmetatable({}, Map)
1321

@@ -137,6 +145,7 @@ function Map:save(path, suffix)
137145
local area_count = table_len(self.areas)
138146
local obj = {}
139147
local data_to_save = false
148+
path = expand_tilde(path)
140149
local fname = format("%s.map_%s%s.lua", path, self.name, suffix)
141150
info("MAP", format("Saving to '%s'", fname))
142151
if area_count > 10 then
@@ -165,6 +174,7 @@ end
165174
function Map:load(path, suffix)
166175
self.areas = {}
167176
suffix = suffix or ""
177+
path = expand_tilde(path)
168178
local fname = format("%s.map_%s%s.lua", path, self.name, suffix)
169179
info("MAP", format("Loading from '%s'", fname))
170180
local ok, obj = false, {}

0 commit comments

Comments
 (0)