Skip to content

Commit 4490657

Browse files
committed
Steamworks Updates
1 parent 8b85caa commit 4490657

7 files changed

Lines changed: 396 additions & 0 deletions

File tree

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# steamworks.deleteFile
2+
3+
> --------------------- ------------------------------------------------------------------------------------------
4+
> **Type** [Function][api.type.Function]
5+
> **Return value** [Boolean][api.type.Boolean]
6+
> **Revision** [REVISION_LABEL](REVISION_URL)
7+
> **Keywords** steam, steamworks, deleteFile, cloud storage
8+
> **See also** [steamworks.*][plugin.steamworks], [steamworks.writeFile][plugin.steamworks.writeFile], [steamworks.fileExists][plugin.steamworks.fileExists]
9+
> --------------------- ------------------------------------------------------------------------------------------
10+
11+
## Overview
12+
13+
This function deletes a file from Steam Cloud storage. It returns `true` if the file was successfully deleted, `false` otherwise.
14+
15+
<div class="guide-notebox-imp">
16+
<div class="notebox-title-imp">Important</div>
17+
This API is only available on 2025.3722+
18+
</div>
19+
20+
When a file is deleted from Steam Cloud, the deletion is synchronized across all devices where the user has the game installed. The file will be permanently removed from cloud storage.
21+
22+
It's recommended to check if a file exists using `steamworks.fileExists()` before attempting to delete it to avoid unnecessary operations.
23+
24+
## Syntax
25+
26+
```lua
27+
steamworks.deleteFile( filename )
28+
```
29+
30+
### Parameters
31+
32+
- **filename** (required): [String][api.type.String]. The name of the file to delete from Steam Cloud storage.
33+
34+
### Return Value
35+
36+
[Boolean][api.type.Boolean]. Returns `true` if the file was successfully deleted from Steam Cloud, `false` if the operation failed or the file doesn't exist.
37+
38+
## Example
39+
40+
```lua
41+
local steamworks = require( "plugin.steamworks" )
42+
43+
local function deletePlayerData()
44+
if steamworks.fileExists("playerData.json") then
45+
if steamworks.deleteFile("playerData.json") then
46+
print("Player data deleted from Steam Cloud.")
47+
else
48+
print("Failed to delete player data.")
49+
end
50+
else
51+
print("No file to delete.")
52+
end
53+
end
54+
55+
-- Call the delete function
56+
deletePlayerData()
57+
```
58+
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# steamworks.fileExists
2+
3+
> --------------------- ------------------------------------------------------------------------------------------
4+
> **Type** [Function][api.type.Function]
5+
> **Return value** [Boolean][api.type.Boolean]
6+
> **Revision** [REVISION_LABEL](REVISION_URL)
7+
> **Keywords** steam, steamworks, fileExists, cloud storage
8+
> **See also** [steamworks.*][plugin.steamworks], [steamworks.writeFile][plugin.steamworks.writeFile], [steamworks.deleteFile][plugin.steamworks.deleteFile]
9+
> --------------------- ------------------------------------------------------------------------------------------
10+
11+
## Overview
12+
13+
This function checks if a file exists in Steam Cloud storage. It returns `true` if the file exists, `false` otherwise.
14+
15+
<div class="guide-notebox-imp">
16+
<div class="notebox-title-imp">Important</div>
17+
This API is only available on 2025.3722+
18+
</div>
19+
20+
This function is commonly used to verify the presence of save files before attempting to load, delete, or overwrite them. It provides a safe way to check for file existence without attempting to read the file contents.
21+
22+
The function queries Steam's Remote Storage API to determine if the specified file is present in the user's cloud storage.
23+
24+
## Syntax
25+
26+
```lua
27+
steamworks.fileExists( filename )
28+
```
29+
30+
### Parameters
31+
32+
- **filename** (required): [String][api.type.String]. The name of the file to check for in Steam Cloud storage.
33+
34+
### Return Value
35+
36+
[Boolean][api.type.Boolean]. Returns `true` if the file exists in Steam Cloud storage, `false` if the file doesn't exist or if the operation failed.
37+
38+
## Example
39+
40+
```lua
41+
local steamworks = require( "plugin.steamworks" )
42+
43+
-- Load player data
44+
local function loadPlayerData()
45+
if not steamworks.fileExists("playerData.json") then
46+
print("No saved data found.")
47+
return
48+
end
49+
50+
-- File exists, proceed with loading
51+
local fileData = steamworks.readFile("playerData.json")
52+
if fileData then
53+
local saveData = json.decode(fileData)
54+
print("Player data loaded: Level " .. saveData.level)
55+
else
56+
print("Failed to read player data.")
57+
end
58+
end
59+
60+
-- Check for save file before showing load option
61+
if steamworks.fileExists("playerData.json") then
62+
print("Save file found - Load Game option available")
63+
else
64+
print("No save file - Starting new game")
65+
end
66+
```
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
# steamworks.getUserStorage
2+
3+
> --------------------- ------------------------------------------------------------------------------------------
4+
> **Type** [Function][api.type.Function]
5+
> **Return value** [Table][api.type.Table] or [nil][api.type.nil]
6+
> **Revision** [REVISION_LABEL](REVISION_URL)
7+
> **Keywords** steam, steamworks, getUserStorage, cloud storage, quota
8+
> **See also** [steamworks.*][plugin.steamworks], [steamworks.writeFile][plugin.steamworks.writeFile]
9+
> --------------------- ------------------------------------------------------------------------------------------
10+
11+
## Overview
12+
13+
This function retrieves information about the user's Steam Cloud storage quota. It returns a table containing total and available storage bytes, or `nil` if the operation failed.
14+
15+
<div class="guide-notebox-imp">
16+
<div class="notebox-title-imp">Important</div>
17+
This API is only available on 2025.3722+
18+
</div>
19+
20+
Steam Cloud storage has limits per application, and this function allows you to check how much storage space is available before writing large files. This is useful for managing save data and preventing storage-related errors.
21+
22+
The function queries Steam's Remote Storage API to get the current quota information for the user's cloud storage.
23+
24+
## Syntax
25+
26+
```lua
27+
steamworks.getUserStorage()
28+
```
29+
30+
### Parameters
31+
32+
None.
33+
34+
### Return Value
35+
36+
[Table][api.type.Table] or [nil][api.type.nil]. Returns a table with storage information if successful, or `nil` if the operation failed.
37+
38+
The returned table contains the following fields:
39+
- **totalBytes** ([Number][api.type.Number]): Total cloud storage space allocated to the application in bytes
40+
- **availableBytes** ([Number][api.type.Number]): Remaining available storage space in bytes
41+
42+
## Example
43+
44+
```lua
45+
local steamworks = require( "plugin.steamworks" )
46+
47+
local function checkStorageSpace()
48+
local storageInfo = steamworks.getUserStorage()
49+
if storageInfo then
50+
local totalMB = storageInfo.totalBytes / (1024 * 1024)
51+
local availableMB = storageInfo.availableBytes / (1024 * 1024)
52+
local usedMB = totalMB - availableMB
53+
54+
print("Steam Cloud Storage:")
55+
print("Total: " .. string.format("%.2f MB", totalMB))
56+
print("Used: " .. string.format("%.2f MB", usedMB))
57+
print("Available: " .. string.format("%.2f MB", availableMB))
58+
59+
-- Check if we have enough space for a save file
60+
local saveDataSize = 1024 -- Estimated save file size in bytes
61+
if storageInfo.availableBytes >= saveDataSize then
62+
print("Sufficient storage space available")
63+
return true
64+
else
65+
print("Warning: Low storage space!")
66+
return false
67+
end
68+
else
69+
print("Failed to retrieve storage information.")
70+
return false
71+
end
72+
end
73+
74+
-- Before saving large data, check available space
75+
local function safeSavePlayerData(saveData)
76+
local storageInfo = steamworks.getUserStorage()
77+
if not storageInfo then
78+
print("Cannot check storage - proceeding anyway")
79+
else
80+
local jsonData = json.encode(saveData)
81+
local dataSize = string.len(jsonData)
82+
83+
if storageInfo.availableBytes < dataSize then
84+
print("Error: Not enough cloud storage space!")
85+
print("Need: " .. dataSize .. " bytes")
86+
print("Available: " .. storageInfo.availableBytes .. " bytes")
87+
return false
88+
end
89+
end
90+
91+
-- Proceed with save
92+
return steamworks.writeFile("playerData.json", json.encode(saveData))
93+
end
94+
```

markdown/plugin/steamworks/index.markdown

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,20 @@ application =
113113

114114
#### [steamworks.getAuthSessionTicket()][plugin.steamworks.getAuthSessionTicket]
115115

116+
#### [steamworks.isSteamDeck()][plugin.steamworks.isSteamDeck] *
117+
118+
#### [steamworks.getUserStorage()][plugin.steamworks.getUserStorage] *
119+
120+
#### [steamworks.fileExists()][plugin.steamworks.fileExists] *
121+
122+
#### [steamworks.readFile()][plugin.steamworks.readFile] *
123+
124+
#### [steamworks.writeFile()][plugin.steamworks.writeFile] *
125+
126+
#### [steamworks.deleteFile()][plugin.steamworks.deleteFile] *
127+
128+
* Only Avaiable on 2025.3722+
129+
116130
## Properties
117131

118132
#### [steamworks.appId][plugin.steamworks.appId]
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# steamworks.isSteamDeck
2+
3+
> --------------------- ------------------------------------------------------------------------------------------
4+
> __Type__ [Boolean][api.type.Boolean]
5+
> __Revision__ [REVISION_LABEL](REVISION_URL)
6+
> __Keywords__ steam, steamworks, isSteamDeck
7+
> __See also__ [steamworks.*][plugin.steamworks]
8+
> --------------------- ------------------------------------------------------------------------------------------
9+
10+
## Overview
11+
12+
This property will be `true` if the current system is running Steam Deck hardware.
13+
14+
<div class="guide-notebox-imp"> <div class="notebox-title-imp">Important</div>
15+
This api is only available on 2025.3722+
16+
</div>
17+
18+
If this property returns `false`, you should assume the user is not on a Steam Deck. You can still run Steam-specific APIs, but any Steam Deck-specific optimizations or input handling should be skipped.
19+
This property is read-only and determined at application startup; it cannot change during the application's lifetime.
20+
21+
22+
## Example
23+
24+
``````lua
25+
local steamworks = require( "plugin.steamworks" )
26+
27+
if steamworks.isSteamDeck then
28+
print("Running on Steam Deck! Adjusting UI and input settings for deck...")
29+
-- Example: Enable on-screen keyboard or adjust layout
30+
else
31+
print("Not a Steam Deck. Running normal desktop mode.")
32+
end
33+
``````
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# steamworks.readFile
2+
3+
> --------------------- ------------------------------------------------------------------------------------------
4+
> **Type** [Function][api.type.Function]
5+
> **Return value** [String][api.type.String] or [nil][api.type.nil]
6+
> **Revision** [REVISION_LABEL](REVISION_URL)
7+
> **Keywords** steam, steamworks, readFile, cloud storage
8+
> **See also** [steamworks.*][plugin.steamworks], [steamworks.writeFile][plugin.steamworks.writeFile], [steamworks.fileExists][plugin.steamworks.fileExists]
9+
> --------------------- ------------------------------------------------------------------------------------------
10+
11+
## Overview
12+
13+
This function reads the contents of a file from Steam Cloud storage. It returns the file contents as a string if successful, or `nil` if the operation failed.
14+
15+
<div class="guide-notebox-imp">
16+
<div class="notebox-title-imp">Important</div>
17+
This API is only available on 2025.3722+
18+
</div>
19+
20+
Steam Cloud automatically synchronizes files across all devices where the user has the game installed. This function retrieves the most current version of the file from cloud storage.
21+
22+
It's recommended to check if a file exists using `steamworks.fileExists()` before attempting to read it, though this function will return `nil` for non-existent files.
23+
24+
## Syntax
25+
26+
```lua
27+
steamworks.readFile( filename )
28+
```
29+
30+
### Parameters
31+
32+
- **filename** (required): [String][api.type.String]. The name of the file to read from Steam Cloud storage.
33+
34+
### Return Value
35+
36+
[String][api.type.String] or [nil][api.type.nil]. Returns the file contents as a string if successful, or `nil` if the file doesn't exist or the operation failed.
37+
38+
## Example
39+
40+
```lua
41+
local steamworks = require( "plugin.steamworks" )
42+
local json = require( "json" )
43+
44+
local function loadPlayerData()
45+
local contents = steamworks.readFile("playerData.json")
46+
if contents then
47+
local saveData = json.decode(contents)
48+
print("Loaded player data:")
49+
print("Level:", saveData.level)
50+
print("Score:", saveData.score)
51+
print("Items:", table.concat(saveData.items, ", "))
52+
else
53+
print("Failed to read player data.")
54+
end
55+
end
56+
57+
-- Complete load example with existence check
58+
local function safeLoadPlayerData()
59+
if steamworks.fileExists("playerData.json") then
60+
local contents = steamworks.readFile("playerData.json")
61+
if contents then
62+
local saveData = json.decode(contents)
63+
return saveData
64+
end
65+
end
66+
return nil -- No data or failed to load
67+
end
68+
```

0 commit comments

Comments
 (0)