Skip to content

Commit 186da17

Browse files
committed
feat: Config read & default
1 parent 210e7bb commit 186da17

File tree

7 files changed

+169
-14
lines changed

7 files changed

+169
-14
lines changed
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
local SteamApp = require("../../Classes/SteamApp")
2+
3+
export type GameConfiguration = {
4+
appID : number,
5+
version : number,
6+
7+
settings : {
8+
dgpu : boolean,
9+
zink : boolean,
10+
sdl_wayland : boolean
11+
},
12+
13+
utilities : {
14+
gamemode : boolean,
15+
mangohud : {
16+
enabled : boolean,
17+
},
18+
gamescope : {
19+
enabled : boolean,
20+
general : {
21+
resolution : {
22+
enabled : boolean;
23+
internal : {
24+
width : number,
25+
height : number,
26+
},
27+
external : {
28+
width : number,
29+
height : number,
30+
},
31+
},
32+
frame_limit : {
33+
enabled : boolean,
34+
normal : number,
35+
unfocused : number,
36+
},
37+
fullscreen : boolean,
38+
borderless : boolean
39+
},
40+
filtering : {
41+
enabled : boolean,
42+
filter : "Linear" | "Nearest" | "FSR" | "NIS" | "Pixel",
43+
sharpness : number,
44+
}
45+
},
46+
}
47+
}
48+
49+
local Default = {}
50+
51+
function Default.getDefaultGameConfiguration(appData : SteamApp.SteamApp) : GameConfiguration
52+
return {
53+
appID = appData.appID,
54+
version = 1,
55+
56+
settings = {
57+
dgpu = true,
58+
zink = false,
59+
sdl_wayland = true
60+
},
61+
62+
utilities = {
63+
gamemode = true,
64+
mangohud = {
65+
enabled = true,
66+
},
67+
gamescope = {
68+
enabled = false,
69+
general = {
70+
resolution = {
71+
enabled = false,
72+
internal = {
73+
width = 1280,
74+
height = 720,
75+
},
76+
external = {
77+
width = 1920,
78+
height = 1080,
79+
},
80+
},
81+
frame_limit = {
82+
enabled = false,
83+
normal = 60,
84+
unfocused = 5,
85+
},
86+
fullscreen = false,
87+
borderless = false
88+
},
89+
filtering = {
90+
enabled = false,
91+
filter = "FSR",
92+
sharpness = 5,
93+
}
94+
},
95+
}
96+
}
97+
end
98+
99+
return Default

src/Configuration/Games/init.luau

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
local fs = require("@lune/fs")
2+
local serde = require("@lune/serde")
3+
4+
local SteamApp = require("../../Classes/SteamApp")
5+
local Default = require("./Default")
6+
local Metadata = require("../../Metadata")
7+
local Logging = require("../../Utilities/Logging")
8+
9+
local function createGameConfiguration(appData : SteamApp.SteamApp) : Default.GameConfiguration
10+
local newConfig = Default.getDefaultGameConfiguration(appData)
11+
12+
Logging.write("info", "Creating default configuration for game " .. appData.name .. " (" .. appData.appID .. ")...")
13+
local configString = serde.encode("toml", newConfig, true)
14+
fs.writeFile(string.format(
15+
"%s/%s.toml",
16+
Metadata.folders.gamesConfig,
17+
tostring(appData.appID)
18+
), configString)
19+
20+
return newConfig
21+
end
22+
23+
local GameConfigurations = {}
24+
25+
function GameConfigurations.getGameConfiguration(appData : SteamApp.SteamApp) : Default.GameConfiguration
26+
local configPath = string.format(
27+
"%s/%s.toml",
28+
Metadata.folders.gamesConfig,
29+
tostring(appData.appID)
30+
)
31+
32+
if fs.metadata(configPath).exists then
33+
local configString = fs.readFile(configPath)
34+
return serde.decode("toml", configString)
35+
else
36+
return createGameConfiguration(appData)
37+
end
38+
end
39+
40+
return GameConfigurations

src/Configuration/init.luau

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
return {
2+
Games = require("./Games")
3+
}

src/Launcher/init.luau

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
local SteamApp = require("../Classes/SteamApp")
2+
3+
local GameConfiguration = require("../Configuration").Games
4+
5+
local Launcher = {}
6+
7+
function Launcher.prepareLaunchCommand(appData : SteamApp.SteamApp) : {string}
8+
-- First and foremost, we recover the configuration of the game.
9+
local ok, appConfig = pcall(GameConfiguration.getGameConfiguration, appData)
10+
if not ok then
11+
error("Failed to get game configuration for " .. appData.name .. " (" .. appData.appID .. ").")
12+
end
13+
14+
error("Not implemented.")
15+
end
16+
17+
return Launcher

src/Metadata/init.luau

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ local Metadata = {
1111
executable = "stweaks",
1212
folders = {
1313
config = process.env.HOME .. "/.config/Stweaks",
14-
gamesConfig = process.env.HOME .. "/.config/Stweaks/games",
14+
gamesConfig = process.env.HOME .. "/.config/Stweaks/Games",
1515
storage = process.env.HOME .. "/.local/share/Stweaks",
1616
cache = process.env.HOME .. "/.cache/Stweaks",
1717
},

src/Steam/Configuration.luau

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,6 @@ type compat_vdf = {
133133
},
134134
}
135135

136-
-- STweaker
137-
138-
-- TODO
139-
140136
-- --------------------------- Script -----------------------------
141137

142138
local Configuration = {}

src/init.luau

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,9 @@ local Filesystem = Utilities.Filesystem
99
local Logging = Utilities.Logging
1010
local System = Utilities.System
1111
local Steam = require("./Steam")
12+
local Launcher = require("./Launcher")
1213

1314
function Application.start()
14-
--[[
15-
Chapter 0 : Preparing the environment
16-
We need to create the config folder if it doesn't exist.
17-
]]
1815
-- Prepare folders if necessary
1916
for _, folder in ipairs({
2017
metadata.folders.config,
@@ -31,11 +28,7 @@ function Application.start()
3128
fs.writeFile(metadata.folders.cache .. "/arguments.txt", table.concat(process.args, "\n"))
3229
end
3330

34-
--[[
35-
Chapter 1 : Game management
36-
Is this being started through Steam or alone ?
37-
What's the Steam config then ?
38-
]]
31+
-- Check if we're launched through Steam, start the game with its settings if so
3932
local launchedAppID = Steam.Utilities.isSteamLaunch()
4033
if launchedAppID then
4134
Logging.write("info", "Launched through Steam (AppID " .. launchedAppID .. ").")
@@ -57,10 +50,17 @@ function Application.start()
5750
process.exit(1)
5851
end
5952

53+
-- Tell the user we found the game
6054
Logging.write("success", 'Detected "' .. gameData.name .. '" (' .. gameData.appID .. ") !")
6155
System.sendNotification(metadata.name, "Detected " .. gameData.name .. ".", "normal", true)
56+
57+
-- Go into the Game Launcher module.
58+
local command: {string} = Launcher.prepareLaunchCommand(gameData)
59+
print(command)
6260
else
6361
Logging.write("info", "Launched without Steam.")
62+
63+
-- :( - Lune FFI is not implemented yet, so no interface.
6464
System.sendNotification(metadata.name, "No graphical interface implemented yet.", "critical", true)
6565
error("No graphical interface implemented yet.")
6666
end

0 commit comments

Comments
 (0)