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

Write missing examples from the addon's data folder #33

Merged
merged 7 commits into from
Jan 4, 2024
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 0 additions & 2 deletions lua/autorun/cpu_load.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ include("wire/gpulib.lua")
AddCSLuaFile("wire/cpu_default_data_decompressor.lua")
include("wire/cpu_default_data_decompressor.lua")

AddCSLuaFile("wire/cpu_default_data_files.lua")

if CLIENT then
include("wire/client/hlzasm/hc_compiler.lua")
end
27 changes: 16 additions & 11 deletions lua/wire/cpu_default_data_decompressor.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,43 +7,48 @@
["spuchip/tests"] = true
}

local checked_dirs = {
"cpuchip",
"gpuchip",
"spuchip"
}

-- Compress all files in addons/wire/data recursively into 1 json string
local function ReadDir(root)
if ignored_dirs[root] then return nil end
local tab = {}
local files,dirs = file.Find("addons/wire-cpu/data/"..root.."*","GAME")
local files,dirs = file.Find("addons/wire-cpu/data_static/"..root.."*","GAME")

Check warning on line 20 in lua/wire/cpu_default_data_decompressor.lua

View workflow job for this annotation

GitHub Actions / lint

"Whitespace style"

Style: Please put some whitespace before the operator

Check warning on line 20 in lua/wire/cpu_default_data_decompressor.lua

View workflow job for this annotation

GitHub Actions / lint

"Whitespace style"

Style: Please put some whitespace before the operator
for _, f in pairs(files) do
f = root..f

Check warning on line 22 in lua/wire/cpu_default_data_decompressor.lua

View workflow job for this annotation

GitHub Actions / lint

"Whitespace style"

Style: Please put some whitespace before the operator
tab[f] = file.Read("addons/wire-cpu/data/"..f, "GAME")
tab[f] = file.Read("addons/wire-cpu/data_static/"..f, "GAME")

Check warning on line 23 in lua/wire/cpu_default_data_decompressor.lua

View workflow job for this annotation

GitHub Actions / lint

"Whitespace style"

Style: Please put some whitespace before the operator
end
for _, f in pairs(dirs) do
f = root..f.."/"

Check warning on line 26 in lua/wire/cpu_default_data_decompressor.lua

View workflow job for this annotation

GitHub Actions / lint

"Whitespace style"

Style: Please put some whitespace before the operator

Check warning on line 26 in lua/wire/cpu_default_data_decompressor.lua

View workflow job for this annotation

GitHub Actions / lint

"Whitespace style"

Style: Please put some whitespace before the operator
tab[f] = ReadDir(f)
end
return tab
end

-- Uncomment and Rename this file to wire/lua/wire/default_data_files.lua to update it
-- file.Write("cpu_default_data_files.txt", "//"..util.TableToJSON(ReadDir("")))
-- file.Write("cpu_default_data_files.txt", "--"..util.TableToJSON(ReadDir("")))

-- Decompress the json string wire/lua/wire/default_data_files.lua into the corresponding 36+ default data files
local function WriteDir(tab)
for f, contents in pairs(tab) do
if isstring(contents) then
file.Write(f, contents)
if not file.Exists(f,"DATA") then
file.Write(f, contents)
end
else
file.CreateDir(f)
WriteDir(contents)
end
end
end

-- Only expand the files if they aren't present already
if CLIENT and not file.Exists("cpuchip/examples/helloworld.txt", "DATA") then
local compressed = file.Read("wire/cpu_default_data_files.lua","LUA")
-- The client cannot read lua files sent by the server (for security?), so clientside this'll only work
-- if the client actually has Wiremod installed, though with workshop autodownload that'll be common
if compressed ~= nil then
WriteDir(util.JSONToTable(string.sub(compressed, 3)))
-- Write any missing files to the folder
if CLIENT then
for _,dir in pairs(checked_dirs) do
WriteDir(ReadDir(dir..'/'), 3)

Check warning on line 52 in lua/wire/cpu_default_data_decompressor.lua

View workflow job for this annotation

GitHub Actions / lint

"Whitespace style"

Style: Please put some whitespace before the operator
end
end
1 change: 0 additions & 1 deletion lua/wire/cpu_default_data_files.lua

This file was deleted.

Loading