Skip to content

Commit

Permalink
refactor: replace raw api call with toolchain calls (#164)
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanFlurry committed Aug 1, 2024
1 parent d96fe3d commit 449d8ff
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 254 deletions.
117 changes: 0 additions & 117 deletions godot/addons/rivet/api/rivet_api.gd

This file was deleted.

57 changes: 0 additions & 57 deletions godot/addons/rivet/api/rivet_request.gd

This file was deleted.

27 changes: 0 additions & 27 deletions godot/addons/rivet/api/rivet_response.gd

This file was deleted.

24 changes: 5 additions & 19 deletions godot/addons/rivet/rivet_global.gd
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,14 @@ class_name RivetGlobal
## @tutorial: https://rivet.gg/learn/godot
## @experimental

const _api = preload("api/rivet_api.gd")

const ApiResponse = preload("api/rivet_response.gd")
const ApiRequest = preload("api/rivet_request.gd")

const _RivetTask = preload("rivet_task.gd")

var api_endpoint: String
var game_version: String
var cloud_token: String
var game_id: String
var backend_project
var backend_environments

enum EnvType { LOCAL, REMOTE }

Expand All @@ -36,7 +33,7 @@ var remote_env_id = null:
var remote_env = null:
get:
if env_type == EnvType.REMOTE:
for x in RivetPluginBridge.instance.game_environments:
for x in backend_environments:
if x.environment_id == remote_env_id:
return x

Expand Down Expand Up @@ -67,7 +64,8 @@ var backend_endpoint: String:
static func get_remote_env_endpoint(env) -> String:
if env != null:
# TODO: Replace with data from API endpoint
return "https://%s--%s.backend.nathan16.gameinc.io" % [RivetPluginBridge.instance.game_project.name_id, env.name_id]
var plugin = RivetPluginBridge.get_plugin()
return "https://%s--%s.backend.nathan16.gameinc.io" % [plugin.backend_project.name_id, env.name_id]
else:
return "unknown"

Expand All @@ -89,18 +87,6 @@ signal backend_state_change(running: bool)

signal env_update()

## @experimental
func POST(path: String, body: Dictionary) -> _api.RivetRequest:
return _api.POST(self, path, body)

## @experimental
func GET(path: String, body: Dictionary = {}) -> _api.RivetRequest:
return _api.GET(self, path, body)

## @experimental
func PUT(path: String, body: Dictionary = {}) -> _api.RivetRequest:
return _api.PUT(self, path, body)

## Helper func to spawn a task and show an alert on failure.
func run_toolchain_task(name: String, input: Variant = {}) -> Variant:
var output = await _RivetTask.new(name, input).task_output
Expand Down
35 changes: 2 additions & 33 deletions godot/addons/rivet/rivet_plugin_bridge.gd
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ signal bootstrapped
const _global := preload("rivet_global.gd")
const _RivetEditorSettings = preload("rivet_editor_settings.gd")

static var game_project = null
static var game_environments: Array = []

static var instance = RivetPluginBridge.new()

static func _find_plugin():
Expand Down Expand Up @@ -84,40 +81,12 @@ func bootstrap() -> Error:
plugin.api_endpoint = result.api_endpoint
plugin.cloud_token = result.token
plugin.game_id = result.game_id
plugin.backend_project = result.backend_project
plugin.backend_environments = result.backend_environments

save_configuration()

# Fetch environments
var fetch_result = await _fetch_envs()
if fetch_result != OK:
return fetch_result

emit_signal("bootstrapped")

return OK

## Fetch the project's environments.
func _fetch_envs() -> Error:
var plugin = get_plugin()

# Get project
var proj_response = await plugin.GET("/cloud/games/%s/project" % plugin.game_id).wait_completed()
if proj_response.response_code != HTTPClient.ResponseCode.RESPONSE_OK:
return FAILED

if "project" not in proj_response.body:
RivetPluginBridge.log("TODO: Project does not exist, needs to be auto-created")
return FAILED
game_project = proj_response.body.project
self.log("Loaded project: %s" % game_project)

# Get environments
var envs_response = await plugin.GET("/cloud/backend/projects/%s/environments" % game_project.project_id).wait_completed()
if envs_response.response_code != HTTPClient.ResponseCode.RESPONSE_OK:
return FAILED

game_environments = envs_response.body.environments
self.log("Loaded environments")

return OK

7 changes: 6 additions & 1 deletion godot/addons/rivet/ui/elements/env_menu_button.gd
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@ var _envs_idx_offset:
return 3

var environments: Array:
get: return RivetPluginBridge.instance.game_environments
get:
var plugin = RivetPluginBridge.get_plugin()
if plugin.backend_environments != null:
return plugin.backend_environments
else:
return []

func _ready():
super()
Expand Down

0 comments on commit 449d8ff

Please sign in to comment.