Skip to content

Commit 046f434

Browse files
API: Move Steam to dedicated dir (#158)
1 parent 61132dd commit 046f434

File tree

4 files changed

+62
-54
lines changed

4 files changed

+62
-54
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
class_name ModLoaderSteam
2+
extends Node
3+
4+
const LOG_NAME := "ModLoader:ThirdParty:Steam"
5+
6+
# Methods related to Steam and the Steam Workshop
7+
8+
9+
# Get the path to the Steam workshop folder. Only works for Steam games, as it
10+
# traverses directories relative to where a Steam game and its workshop content
11+
# would be installed. Based on code by Blobfish (developer of Brotato).
12+
# For reference, these are the paths of a Steam game and its workshop folder:
13+
# GAME = Steam/steamapps/common/GameName
14+
# WORKSHOP = Steam/steamapps/workshop/content/AppID
15+
# Eg. Brotato:
16+
# GAME = Steam/steamapps/common/Brotato
17+
# WORKSHOP = Steam/steamapps/workshop/content/1942280
18+
static func get_steam_workshop_dir() -> String:
19+
var game_install_directory := ModLoaderUtils.get_local_folder_dir()
20+
var path := ""
21+
22+
# Traverse up to the steamapps directory (ie. `cd ..\..\` on Windows)
23+
var path_array := game_install_directory.split("/")
24+
path_array.resize(path_array.size() - 2)
25+
26+
# Reconstruct the path, now that it has "common/GameName" removed
27+
path = "/".join(path_array)
28+
29+
# Append the workgame's workshop path
30+
path = path.plus_file("workshop/content/" + get_steam_app_id())
31+
32+
return path
33+
34+
35+
# Gets the steam app ID from steam_data.json, which should be in the root
36+
# directory (ie. res://steam_data.json). This file is used by Godot Workshop
37+
# Utility (GWU), which was developed by Brotato developer Blobfish:
38+
# https://github.com/thomasgvd/godot-workshop-utility
39+
static func get_steam_app_id() -> String:
40+
var game_install_directory := ModLoaderUtils.get_local_folder_dir()
41+
var steam_app_id := ""
42+
var file := File.new()
43+
44+
if file.open(game_install_directory.plus_file("steam_data.json"), File.READ) == OK:
45+
var file_content: Dictionary = parse_json(file.get_as_text())
46+
file.close()
47+
48+
if not file_content.has("app_id"):
49+
ModLoaderUtils.log_error("The steam_data file does not contain an app ID. Mod uploading will not work.", LOG_NAME)
50+
return ""
51+
52+
steam_app_id = file_content.app_id
53+
else :
54+
ModLoaderUtils.log_error("Can't open steam_data file, \"%s\". Please make sure the file exists and is valid." % game_install_directory.plus_file("steam_data.json"), LOG_NAME)
55+
56+
return steam_app_id

addons/mod_loader/mod_loader.gd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ func _load_zips_in_folder(folder_path: String) -> int:
352352
# inside each workshop item's folder
353353
func _load_steam_workshop_zips() -> int:
354354
var temp_zipped_mods_count := 0
355-
var workshop_folder_path := ModLoaderUtils.get_steam_workshop_dir()
355+
var workshop_folder_path := ModLoaderSteam.get_steam_workshop_dir()
356356

357357
if not ml_options.steam_workshop_path_override == "":
358358
workshop_folder_path = ml_options.steam_workshop_path_override

addons/mod_loader/mod_loader_setup.gd

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ const new_global_classes := [
4040
"class": "ModLoaderOptionsProfile",
4141
"language": "GDScript",
4242
"path": "res://addons/mod_loader/options/classes/options_profile.gd"
43+
}, {
44+
"base": "Node",
45+
"class": "ModLoaderSteam",
46+
"language": "GDScript",
47+
"path": "res://addons/mod_loader/api/third_party/steam.gd"
4348
}, {
4449
"base": "Node",
4550
"class": "ModLoaderDeprecated",

addons/mod_loader/mod_loader_utils.gd

Lines changed: 0 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -532,56 +532,3 @@ static func save_string_to_file(save_string: String, filepath: String) -> bool:
532532
static func save_dictionary_to_json_file(data: Dictionary, filepath: String) -> bool:
533533
var json_string = JSON.print(data, "\t")
534534
return save_string_to_file(json_string, filepath)
535-
536-
537-
# Steam
538-
# =============================================================================
539-
540-
# Get the path to the Steam workshop folder. Only works for Steam games, as it
541-
# traverses directories relative to where a Steam game and its workshop content
542-
# would be installed. Based on code by Blobfish (developer of Brotato).
543-
# For reference, these are the paths of a Steam game and its workshop folder:
544-
# GAME = Steam/steamapps/common/GameName
545-
# WORKSHOP = Steam/steamapps/workshop/content/AppID
546-
# Eg. Brotato:
547-
# GAME = Steam/steamapps/common/Brotato
548-
# WORKSHOP = Steam/steamapps/workshop/content/1942280
549-
static func get_steam_workshop_dir() -> String:
550-
var game_install_directory := get_local_folder_dir()
551-
var path := ""
552-
553-
# Traverse up to the steamapps directory (ie. `cd ..\..\` on Windows)
554-
var path_array := game_install_directory.split("/")
555-
path_array.resize(path_array.size() - 2)
556-
557-
# Reconstruct the path, now that it has "common/GameName" removed
558-
path = "/".join(path_array)
559-
560-
# Append the workgame's workshop path
561-
path = path.plus_file("workshop/content/" + get_steam_app_id())
562-
563-
return path
564-
565-
566-
# Gets the steam app ID from steam_data.json, which should be in the root
567-
# directory (ie. res://steam_data.json). This file is used by Godot Workshop
568-
# Utility (GWU), which was developed by Brotato developer Blobfish:
569-
# https://github.com/thomasgvd/godot-workshop-utility
570-
static func get_steam_app_id() -> String:
571-
var game_install_directory := get_local_folder_dir()
572-
var steam_app_id := ""
573-
var file := File.new()
574-
575-
if file.open(game_install_directory.plus_file("steam_data.json"), File.READ) == OK:
576-
var file_content: Dictionary = parse_json(file.get_as_text())
577-
file.close()
578-
579-
if not file_content.has("app_id"):
580-
log_error("The steam_data file does not contain an app ID. Mod uploading will not work.", LOG_NAME)
581-
return ""
582-
583-
steam_app_id = file_content.app_id
584-
else :
585-
log_error("Can't open steam_data file, \"%s\". Please make sure the file exists and is valid." % game_install_directory.plus_file("steam_data.json"), LOG_NAME)
586-
587-
return steam_app_id

0 commit comments

Comments
 (0)