Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow reading files from data_static #1057

Merged
merged 3 commits into from
Oct 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ All notable changes to TTT2 will be documented here. Inspired by [keep a changel

- Updated Simplified Chinese and Traditional Chinese localization files (by @sbzlzh):
- Add the missing `L.c4_disarm_t` translation in C4
- Updated file code to read from `data_static` as fallback in new location allowed in .gma (by @EntranceJew)

## [v0.11.7b](https://github.com/TTT-2/TTT2/tree/v0.11.7b) (2022-08-27)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@ local path = dir .. "/" .. game.GetMap() .. ".json"
local function ReadMapConfig()
file.CreateDir(dir)

local modTime = (not file.Exists(path, "DATA") and (lastRead + 1)) or file.Time(path, "DATA")
local modTime = (not file.Exists("data_static/" .. path, "GAME") and (lastRead + 1)) or file.Time("data_static/" .. path, "GAME")
modTime = modTime <= lastRead and (not file.Exists(path, "DATA") and (lastRead + 1)) or file.Time(path, "DATA")

if modTime <= lastRead then
return TButtonMapConfig
end

lastRead = modTime
local content = file.Read(path, "DATA")
local content = (file.Exists(path, "DATA") and file.Read(path, "DATA")) or file.Read("data_static/" .. path, "GAME")

if not content then
return TButtonMapConfig
Expand Down
10 changes: 8 additions & 2 deletions lua/ttt2/libraries/entspawnscript.lua
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,8 @@ if SERVER then
-- @return boolean Returns true if the spawnn script already exists
-- @realm server
function entspawnscript.Exists(dir)
return fileExists(dir .. gameGetMap() .. ".json", "DATA")
local fullDir = dir .. gameGetMap() .. ".json"
return fileExists(fullDir, "DATA") or fileExists("data_static/" .. fullDir, "GAME")
end


Expand All @@ -353,7 +354,12 @@ if SERVER then
-- @internal
-- @realm server
function entspawnscript.ReadFile(dir)
return utilJSONToTable(fileRead(dir .. gameGetMap() .. ".json", "DATA"))
local fullDir = dir .. gameGetMap() .. ".json"
if fileExists(fullDir, "DATA") then
return utilJSONToTable( fileRead(fullDir, "DATA") )
else
return utilJSONToTable( fileRead("data_static/" .. fullDir, "GAME") )
end
end

---
Expand Down