Skip to content
This repository has been archived by the owner on Dec 13, 2024. It is now read-only.

Commit

Permalink
Update godot plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
AngelOnFira committed Jun 25, 2024
1 parent 0597561 commit a440861
Show file tree
Hide file tree
Showing 21 changed files with 350 additions and 155 deletions.
53 changes: 35 additions & 18 deletions godot/bomber/addons/rivet/api/rivet_api.gd
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,25 @@ const RivetRequest = preload("rivet_request.gd")

static var CONFIGURATION_CACHE

# This is needed to make sure that at runtime,
static func _get_bridge() -> Variant:
if Engine.is_editor_hint():
return load("res://addons/rivet/devtools/rivet_plugin_bridge.gd")
else:
return null

static func _get_configuration():
if CONFIGURATION_CACHE:
return CONFIGURATION_CACHE

if FileAccess.file_exists(RivetPluginBridge.RIVET_CONFIGURATION_FILE_PATH):
var config_file = ResourceLoader.load(RivetPluginBridge.RIVET_CONFIGURATION_FILE_PATH)
if FileAccess.file_exists(RivetConstants.RIVET_CONFIGURATION_FILE_PATH):
var config_file = ResourceLoader.load(RivetConstants.RIVET_CONFIGURATION_FILE_PATH)
if config_file and 'new' in config_file:
CONFIGURATION_CACHE = config_file.new()
return CONFIGURATION_CACHE

if FileAccess.file_exists(RivetPluginBridge.RIVET_DEPLOYED_CONFIGURATION_FILE_PATH):
var deployed_config_file = ResourceLoader.load(RivetPluginBridge.RIVET_DEPLOYED_CONFIGURATION_FILE_PATH)
if FileAccess.file_exists(RivetConstants.RIVET_DEPLOYED_CONFIGURATION_FILE_PATH):
var deployed_config_file = ResourceLoader.load(RivetConstants.RIVET_DEPLOYED_CONFIGURATION_FILE_PATH)
if deployed_config_file and 'new' in deployed_config_file:
CONFIGURATION_CACHE = deployed_config_file.new()
return CONFIGURATION_CACHE
Expand All @@ -25,9 +32,11 @@ static func _get_configuration():

static func _get_api_url():
# Use plugin config if available
var plugin = RivetPluginBridge.get_plugin()
if plugin:
return plugin.api_endpoint
var bridge = _get_bridge()
if bridge != null:
var plugin = bridge.get_plugin()
if plugin:
return plugin.api_endpoint

# Override shipped configuration endpoint
var url_env = OS.get_environment("RIVET_API_ENDPOINT")
Expand All @@ -46,11 +55,15 @@ static func _get_api_url():
## actions.
static func _get_cloud_token():
# Use plugin config if available
var plugin = RivetPluginBridge.get_plugin()
if plugin:
return plugin.cloud_token

OS.crash("Rivet cloud token not found, this should only be called within the plugin")
var bridge = _get_bridge()
if bridge != null:
var plugin = bridge.get_plugin()
if plugin:
return plugin.cloud_token
# Explicit else, since if OS.crash is called from the engine, it will just
# crash the editor.
else:
OS.crash("Rivet cloud token not found, this should only be called within the plugin")

## Get authorization token used for making requests from within the game.
##
Expand All @@ -61,9 +74,11 @@ static func _get_cloud_token():
## - Assume config is provided by the game client
static func _get_runtime_token():
# Use plugin config if available
var plugin = RivetPluginBridge.get_plugin()
if plugin:
return plugin.namespace_token
var bridge = _get_bridge()
if bridge != null:
var plugin = bridge.get_plugin()
if plugin:
return plugin.namespace_token

# Use configuration shipped with game
var token_env = OS.get_environment("RIVET_TOKEN")
Expand All @@ -72,10 +87,12 @@ static func _get_runtime_token():

# Use configuration shipped with game
var config = _get_configuration()
if config:
if config and config.namespace_token:
return config.namespace_token

OS.crash("Rivet token not found, validate a config is shipped with the game in the .rivet folder")
# Explicit else, since if OS.crash is called from the engine, it will just
# crash the editor.
else:
OS.crash("Rivet token not found, validate a config is shipped with the game in the .rivet folder")

## Builds the headers for a request, including the authorization token
static func _build_headers(service: String) -> PackedStringArray:
Expand Down
87 changes: 68 additions & 19 deletions godot/bomber/addons/rivet/devtools/dock/deploy_tab.gd
Original file line number Diff line number Diff line change
@@ -1,33 +1,82 @@
@tool extends MarginContainer

@onready var namespace_selector: OptionButton = %DeployNamespaceSelector
@onready var manage_versions_button: Button = %ManageVersionButton
@onready var build_deploy_button: Button = %BuildDeployButton
@onready var manage_versions_button: Button = %ManageVersionButton
@onready var logs_button: Button = %LogsButton
@onready var lobbies_button: Button = %LobbiesButton

func _ready() -> void:
manage_versions_button.pressed.connect(_on_manage_versions_button_pressed)
build_deploy_button.pressed.connect(_on_build_deploy_button_pressed)
build_deploy_button.pressed.connect(_on_build_deploy_button_pressed)
manage_versions_button.pressed.connect(_on_manage_versions_button_pressed)
logs_button.pressed.connect(_on_logs_button_pressed)
lobbies_button.pressed.connect(_on_lobbies_button_pressed)

func _on_manage_versions_button_pressed() -> void:
_all_actions_set_disabled(true)

var result = await RivetPluginBridge.get_plugin().cli.run_command(["sidekick", "get-version", "--namespace", namespace_selector.current_value.namespace_id])
if result.exit_code != 0 or !("Ok" in result.output):
RivetPluginBridge.display_cli_error(self, result)
_all_actions_set_disabled(true)

var result = await RivetPluginBridge.get_plugin().cli.run_and_wait(["sidekick", "get-version", "--namespace", namespace_selector.current_value.namespace_id])
if result.exit_code != 0 or !("Ok" in result.output):
RivetPluginBridge.display_cli_error(self, result)

OS.shell_open(result.output["Ok"]["output"])
_all_actions_set_disabled(false)

func _on_logs_button_pressed() -> void:
_all_actions_set_disabled(true)

var result = await RivetPluginBridge.get_plugin().cli.run_and_wait(["sidekick", "get-logs", "--namespace", namespace_selector.current_value.namespace_id])
if result.exit_code != 0 or !("Ok" in result.output):
RivetPluginBridge.display_cli_error(self, result)

OS.shell_open(result.output["Ok"]["output"])
_all_actions_set_disabled(false)

func _on_lobbies_button_pressed() -> void:
_all_actions_set_disabled(true)

OS.shell_open(result.output["Ok"]["output"])
_all_actions_set_disabled(false)
var result = await RivetPluginBridge.get_plugin().cli.run_and_wait(["sidekick", "get-lobbies", "--namespace", namespace_selector.current_value.namespace_id])
if result.exit_code != 0 or !("Ok" in result.output):
RivetPluginBridge.display_cli_error(self, result)

OS.shell_open(result.output["Ok"]["output"])
_all_actions_set_disabled(false)

func _on_build_deploy_button_pressed() -> void:
_all_actions_set_disabled(true)
# First, ask the user if they want to save their scenes
var dialog = ConfirmationDialog.new()
dialog.dialog_text = "Would you like to save before building and deploying?"
dialog.connect("confirmed", save_before_build_and_deploy)
dialog.get_cancel_button().pressed.connect(build_and_deploy)
dialog.cancel_button_text = "No, just build and deploy"
self.add_child(dialog)
dialog.popup_centered()


func save_before_build_and_deploy() -> void:
# Save all
EditorInterface.save_all_scenes()
EditorInterface.get_script_editor().save_all_scripts()

# Now, build and deploy
build_and_deploy()


func build_and_deploy() -> void:
_all_actions_set_disabled(true)

var result = await RivetPluginBridge.get_plugin().cli.run_and_wait(["sidekick", "--show-terminal", "deploy", "--namespace", namespace_selector.current_value.name_id])
if result.exit_code != 0:
RivetPluginBridge.display_cli_error(self, result)

var result = await RivetPluginBridge.get_plugin().cli.run_command(["sidekick", "--show-terminal", "deploy", "--namespace", namespace_selector.current_value.name_id])
if result.exit_code != 0:
RivetPluginBridge.display_cli_error(self, result)
# Update the namespaces list
RivetPluginBridge.instance.bootstrap()

_all_actions_set_disabled(false)
_all_actions_set_disabled(false)
func _all_actions_set_disabled(disabled: bool) -> void:
namespace_selector.disabled = disabled
manage_versions_button.disabled = disabled
build_deploy_button.disabled = disabled
namespace_selector.disabled = disabled
manage_versions_button.disabled = disabled
build_deploy_button.disabled = disabled
logs_button.disabled = disabled
lobbies_button.disabled = disabled
40 changes: 28 additions & 12 deletions godot/bomber/addons/rivet/devtools/dock/deploy_tab.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ offset_right = 734.0
offset_bottom = 109.0
script = ExtResource("1_7k6ip")

[node name="Deployment Fieds" type="VBoxContainer" parent="."]
[node name="Deployment Fields" type="VBoxContainer" parent="."]
layout_mode = 2

[node name="Deployment Label" type="RichTextLabel" parent="Deployment Fieds"]
[node name="Deployment Label" type="RichTextLabel" parent="Deployment Fields"]
layout_mode = 2
theme_override_styles/normal = SubResource("StyleBoxEmpty_dfadg")
bbcode_enabled = true
Expand All @@ -22,35 +22,51 @@ fit_content = true
scroll_active = false
shortcut_keys_enabled = false

[node name="DeployNamespaceSelector" parent="Deployment Fieds" instance=ExtResource("2_5hxk2")]
[node name="DeployNamespaceSelector" parent="Deployment Fields" instance=ExtResource("2_5hxk2")]
layout_mode = 2
selected = -1
current_value = {
"create_ts": "2023-11-19T05:46:56.378Z",
"create_ts": "1970-01-01T00:00:00Z",
"display_name": "Production",
"name_id": "prod",
"namespace_id": "215bd313-b4c7-4932-b9bd-64f8f09b7fe8",
"namespace_id": "00000000-0000-0000-0000-000000000000",
"version": {
"create_ts": "2023-11-19T05:46:56.171Z",
"create_ts": "1970-01-01T00:00:00Z",
"display_name": "0.0.1",
"version_id": "73881376-21fa-4fb2-93f2-2f76fb3bac19"
"version_id": "00000000-0000-0000-0000-000000000000"
},
"version_id": "73881376-21fa-4fb2-93f2-2f76fb3bac19"
"version_id": "00000000-0000-0000-0000-000000000000"
}

[node name="Actions" type="HBoxContainer" parent="Deployment Fieds"]
[node name="Actions" type="HBoxContainer" parent="Deployment Fields"]
layout_mode = 2

[node name="BuildDeployButton" type="Button" parent="Deployment Fieds/Actions"]
[node name="BuildDeployButton" type="Button" parent="Deployment Fields/Actions"]
unique_name_in_owner = true
layout_mode = 2
size_flags_horizontal = 3
mouse_default_cursor_shape = 2
text = "Build & Deploy"

[node name="ManageVersionButton" type="Button" parent="Deployment Fieds/Actions"]
[node name="ManageVersionButton" type="Button" parent="Deployment Fields/Actions"]
unique_name_in_owner = true
layout_mode = 2
size_flags_horizontal = 3
mouse_default_cursor_shape = 2
text = "Manage Versions"

[node name="Links" type="HBoxContainer" parent="Deployment Fields"]
layout_mode = 2

[node name="LogsButton" type="Button" parent="Deployment Fields/Links"]
unique_name_in_owner = true
layout_mode = 2
size_flags_horizontal = 3
mouse_default_cursor_shape = 2
text = "Logs"

[node name="LobbiesButton" type="Button" parent="Deployment Fields/Links"]
unique_name_in_owner = true
layout_mode = 2
size_flags_horizontal = 3
mouse_default_cursor_shape = 2
text = "Lobbies"
6 changes: 3 additions & 3 deletions godot/bomber/addons/rivet/devtools/dock/dock.gd
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
enum Screen {
Login,
Settings,
Loading,
LinkingPending,
Installer,
}

Expand All @@ -19,10 +19,10 @@ func reload() -> void:
instance.grab_focus()


func change_current_screen(scene: Screen):
func change_current_screen(scene: Screen, args: Dictionary = {}):
for idx in get_child_count():
var child := get_child(idx)
if "visible" in child:
child.visible = idx == scene
if idx == scene and child.has_method("prepare"):
child.prepare()
child.prepare(args)
6 changes: 3 additions & 3 deletions godot/bomber/addons/rivet/devtools/dock/dock.tscn
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
[gd_scene load_steps=6 format=3 uid="uid://l8cfdaru7ibw"]
[gd_scene load_steps=5 format=3 uid="uid://l8cfdaru7ibw"]

[ext_resource type="Script" path="res://addons/rivet/devtools/dock/dock.gd" id="1_xspk7"]
[ext_resource type="PackedScene" uid="uid://mag2n5yvyus8" path="res://addons/rivet/devtools/dock/login.tscn" id="2_qo12a"]
[ext_resource type="PackedScene" uid="uid://ceovepvn1782o" path="res://addons/rivet/devtools/dock/settings.tscn" id="3_8srmc"]
[ext_resource type="PackedScene" uid="uid://cpiafwq88eamc" path="res://addons/rivet/devtools/dock/loading.tscn" id="4_mdhqv"]
[ext_resource type="PackedScene" uid="uid://cpiafwq88eamc" path="res://addons/rivet/devtools/dock/linking_pending.tscn" id="4_mdhqv"]
[ext_resource type="PackedScene" uid="uid://d3l0arylk0h43" path="res://addons/rivet/devtools/dock/installer.tscn" id="5_gdmi1"]

[node name="Rivet" type="MarginContainer"]
Expand All @@ -26,7 +26,7 @@ layout_mode = 2
visible = false
layout_mode = 2

[node name="Loading" parent="." instance=ExtResource("4_mdhqv")]
[node name="LinkingPending" parent="." instance=ExtResource("4_mdhqv")]
visible = false
layout_mode = 2

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
@tool extends RichTextLabel

var _spinner_tween: Tween

func _ready():
add_theme_stylebox_override(&"normal", get_theme_stylebox(&"bg", &"AssetLib"))
add_theme_font_override(&"mono_font", get_theme_font(&"output_source_mono", &"EditorFonts"))
add_theme_font_override(&"bold_font", get_theme_font(&"bold", &"EditorFonts"))

meta_clicked.connect(func(meta): OS.shell_open(str(meta)))

func _exit_tree() -> void:
if _spinner_tween:
_spinner_tween.kill()

func append_spinner():
if _spinner_tween:
_spinner_tween.kill()
add_image(get_theme_icon(&"Progress1", &"EditorIcons"), 0, 0, Color(1, 1, 1, 1), 5, Rect2(0,0,0,0), "loading")
_spinner_tween = get_tree().create_tween()
_spinner_tween.tween_method(_on_spinner_tween_method, 1, 8, 1).set_delay(0.1)
_spinner_tween.set_loops()

func _on_spinner_tween_method(frame: int):
update_image("loading", ImageUpdateMask.UPDATE_TEXTURE, get_theme_icon("Progress" + str(frame), "EditorIcons"))
4 changes: 2 additions & 2 deletions godot/bomber/addons/rivet/devtools/dock/installer.gd
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
@onready var InstallDialog: AcceptDialog = %InstallDialog
@onready var InstallLabel: RichTextLabel = %InstallLabel

func prepare() -> void:
func prepare(_args: Dictionary) -> void:
InstallLabel.add_theme_font_override(&"mono_font", get_theme_font(&"output_source_mono", &"EditorFonts"))
InstallLabel.add_theme_font_override(&"bold_font", get_theme_font(&"bold", &"EditorFonts"))
InstallLabel.add_theme_stylebox_override(&"normal", get_theme_stylebox(&"bg", &"AssetLib"))
Expand Down Expand Up @@ -34,4 +34,4 @@ func _on_install_button_pressed() -> void:
InstallDialog.title = &"Error!"
InstallDialog.dialog_text = &"Rivet installation failed! Please try again.\n\n%s" % result.output
InstallDialog.popup_centered()
InstallButton.loading = false
InstallButton.loading = false
25 changes: 25 additions & 0 deletions godot/bomber/addons/rivet/devtools/dock/linking_pending.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
@tool extends VBoxContainer

@onready var link_line_edit: LineEdit = %LinkLineEdit
@onready var link_instructions: RichTextLabel = %LinkInstructions

var _on_cancel: Callable

func _ready() -> void:
%CancelButton.pressed.connect(_on_cancel_button_pressed)

func prepare(args: Dictionary) -> void:
if 'link' in args:
link_line_edit.text = args['link']
link_instructions.clear()
link_instructions.push_paragraph(HORIZONTAL_ALIGNMENT_CENTER)
link_instructions.append_spinner()
link_instructions.append_text(" Linking game in browser...\n\n")
link_instructions.append_text("If your browser does not open, click [url={link}]here[/url], or use link below.".format({"link": args['link']}))
link_instructions.pop()
if 'on_cancel' in args:
_on_cancel = args['on_cancel']

func _on_cancel_button_pressed() -> void:
if _on_cancel.is_valid():
_on_cancel.call()
Loading

0 comments on commit a440861

Please sign in to comment.