| … | … | @@ -0,0 +1,36 @@ |
| 1 | extends HTTPRequest | |
| 2 | ||
| 3 | signal loaded_data(data) | |
| 4 | signal loading_data(url) | |
| 5 | signal failed_load(url, error) | |
| 6 | ||
| 7 | # Declare member variables here. Examples: | |
| 8 | # var a = 2 | |
| 9 | # var b = "text" | |
| 10 | ||
| 11 | ||
| 12 | # Called when the node enters the scene tree for the first time. | |
| 13 | func _ready(): | |
| 14 | pass # Replace with function body. | |
| 15 | ||
| 16 | ||
| 17 | # Called every frame. 'delta' is the elapsed time since the previous frame. | |
| 18 | #func _process(delta): | |
| 19 | # pass | |
| 20 | ||
| 21 | func requestHyper(url): | |
| 22 | var toload = url.replace("hyper://", "http://127.0.0.1:4973/hyper/") | |
| 23 | print("Loading " + toload) | |
| 24 | request(toload) | |
| 25 | pass | |
| 26 | ||
| 27 | ||
| 28 | func _on_request_completed(result, response_code, headers, body): | |
| 29 | print("Result", result) | |
| 30 | print("Response Code", response_code) | |
| 31 | if response_code != 200: | |
| 32 | var message = body.get_string_from_utf8() | |
| 33 | print("Error message:", message) | |
| 34 | emit_signal("failed_load", result, message) | |
| 35 | else: emit_signal("loaded_data", body.get_string_from_utf8()) | |
| 36 | pass # Replace with function body. |
| … | … | @@ -0,0 +1,79 @@ |
| 1 | [gd_scene load_steps=5 format=2] | |
| 2 | ||
| 3 | [ext_resource path="res://GatewayRequest.gd" type="Script" id=1] | |
| 4 | [ext_resource path="res://Output.gd" type="Script" id=2] | |
| 5 | [ext_resource path="res://StatusLabel.gd" type="Script" id=3] | |
| 6 | [ext_resource path="res://URLBar.gd" type="Script" id=4] | |
| 7 | ||
| 8 | [node name="Control" type="Control"] | |
| 9 | anchor_right = 1.0 | |
| 10 | anchor_bottom = 1.0 | |
| 11 | __meta__ = { | |
| 12 | "_edit_use_anchors_": false | |
| 13 | } | |
| 14 | ||
| 15 | [node name="Title" type="Label" parent="."] | |
| 16 | margin_left = 210.512 | |
| 17 | margin_top = 29.217 | |
| 18 | margin_right = 490.512 | |
| 19 | margin_bottom = 43.217 | |
| 20 | text = "Enter your `hyper://` URL and press `Load`" | |
| 21 | __meta__ = { | |
| 22 | "_edit_use_anchors_": false | |
| 23 | } | |
| 24 | ||
| 25 | [node name="URLBar" type="LineEdit" parent="."] | |
| 26 | margin_left = 16.0 | |
| 27 | margin_top = 68.0 | |
| 28 | margin_right = 570.0 | |
| 29 | margin_bottom = 92.0 | |
| 30 | text = "hyper://blog.mauve.moe/" | |
| 31 | script = ExtResource( 4 ) | |
| 32 | __meta__ = { | |
| 33 | "_edit_use_anchors_": false | |
| 34 | } | |
| 35 | ||
| 36 | [node name="LoadButton" type="Button" parent="."] | |
| 37 | margin_left = 585.838 | |
| 38 | margin_top = 70.4204 | |
| 39 | margin_right = 627.838 | |
| 40 | margin_bottom = 90.4204 | |
| 41 | text = "Load" | |
| 42 | __meta__ = { | |
| 43 | "_edit_use_anchors_": false | |
| 44 | } | |
| 45 | ||
| 46 | [node name="Output" type="Label" parent="."] | |
| 47 | margin_left = 24.0 | |
| 48 | margin_top = 109.0 | |
| 49 | margin_right = 639.0 | |
| 50 | margin_bottom = 623.0 | |
| 51 | autowrap = true | |
| 52 | clip_text = true | |
| 53 | script = ExtResource( 2 ) | |
| 54 | __meta__ = { | |
| 55 | "_edit_use_anchors_": false | |
| 56 | } | |
| 57 | ||
| 58 | [node name="StatusLabel" type="Label" parent="."] | |
| 59 | margin_left = 33.2978 | |
| 60 | margin_top = 636.226 | |
| 61 | margin_right = 73.2978 | |
| 62 | margin_bottom = 650.226 | |
| 63 | text = "Status: Waiting" | |
| 64 | script = ExtResource( 3 ) | |
| 65 | __meta__ = { | |
| 66 | "_edit_use_anchors_": false | |
| 67 | } | |
| 68 | ||
| 69 | [node name="HyperLoad" type="HTTPRequest" parent="."] | |
| 70 | script = ExtResource( 1 ) | |
| 71 | ||
| 72 | [connection signal="text_entered" from="URLBar" to="URLBar" method="_on_URLBar_text_entered"] | |
| 73 | [connection signal="url" from="URLBar" to="HyperLoad" method="requestHyper"] | |
| 74 | [connection signal="pressed" from="LoadButton" to="URLBar" method="navigate"] | |
| 75 | [connection signal="failed_load" from="HyperLoad" to="StatusLabel" method="setError"] | |
| 76 | [connection signal="loaded_data" from="HyperLoad" to="StatusLabel" method="setLoaded"] | |
| 77 | [connection signal="loaded_data" from="HyperLoad" to="Output" method="setContent"] | |
| 78 | [connection signal="loading_data" from="HyperLoad" to="StatusLabel" method="setLoadingData"] | |
| 79 | [connection signal="request_completed" from="HyperLoad" to="HyperLoad" method="_on_request_completed"] |
| … | … | @@ -0,0 +1,21 @@ |
| 1 | extends Label | |
| 2 | ||
| 3 | ||
| 4 | # Declare member variables here. Examples: | |
| 5 | # var a = 2 | |
| 6 | # var b = "text" | |
| 7 | ||
| 8 | ||
| 9 | # Called when the node enters the scene tree for the first time. | |
| 10 | func _ready(): | |
| 11 | pass # Replace with function body. | |
| 12 | ||
| 13 | ||
| 14 | # Called every frame. 'delta' is the elapsed time since the previous frame. | |
| 15 | #func _process(delta): | |
| 16 | # pass | |
| 17 | ||
| 18 | ||
| 19 | func setContent(data): | |
| 20 | text = data | |
| 21 | pass # Replace with function body. |
| … | … | @@ -6,22 +6,16 @@ A Godot plugin and example project for loading assets from the [hypercore-protoc |
| 6 | 6 | |
| 7 | 7 | ## Plans: |
| 8 | 8 | |
| 9 | - Create a node-js based daemon using the `hypercore-fetch` module listening on UNIX domain sockets / Windows named pipes listening on HTTPs | |
| 10 | - Use HTTPClient in GDScript to connect over the unix socket | |
| 9 | - Create a node-js based gateway using the `hypercore-fetch` module listening on http://localhost/ | |
| 10 | - Use HTTPClient in GDScript to connect to the gateway | |
| 11 | - Spawn gateway from within Godot in a singleton | |
| 11 | 12 | - Intercept the resource loading code to support `hyper://`? |
| 12 | - Spawn daemon from within Godot in a singleton | |
| 13 | 13 | |
| 14 | 14 | ## Research: |
| 15 | 15 | |
| 16 | ### How to communicate over UNIX sockets | |
| 17 | ||
| 18 | - StreamPeer seems to [imply UNIX sockets are supported](https://docs.godotengine.org/en/stable/classes/class_streampeer.html#description) | |
| 19 | - Looks like it isn't actually supported: https://github.com/godotengine/godot/issues/48862 | |
| 20 | - Also no support for windows sockets | |
| 21 | - Could implement, or go with something else. | |
| 22 | ||
| 23 | 16 | ### How to spawn the daemon |
| 24 | 17 | |
| 18 | - [Use pkg](https://www.npmjs.com/package/pkg) to compile [hyper-gateway](https://github.com/RangerMauve/hyper-gateway) | |
| 25 | 19 | - Bundle daemon binaries with the project |
| 26 | 20 | - Use [OS.execute](https://docs.godotengine.org/en/stable/classes/class_os.html#class-os-method-execute) with non-blocking mode enabled. |
| 27 | 21 | - Ensure the process is killed before exiting? |
| … | … | @@ -0,0 +1,29 @@ |
| 1 | extends Label | |
| 2 | ||
| 3 | ||
| 4 | # Declare member variables here. Examples: | |
| 5 | # var a = 2 | |
| 6 | # var b = "text" | |
| 7 | ||
| 8 | ||
| 9 | # Called when the node enters the scene tree for the first time. | |
| 10 | func _ready(): | |
| 11 | pass # Replace with function body. | |
| 12 | ||
| 13 | ||
| 14 | # Called every frame. 'delta' is the elapsed time since the previous frame. | |
| 15 | #func _process(delta): | |
| 16 | # pass | |
| 17 | ||
| 18 | func setLoaded(data): | |
| 19 | text = "Status: Loaded" | |
| 20 | pass # Replace with function body. | |
| 21 | ||
| 22 | func setLoading(url): | |
| 23 | text = "Status: Loading " + url | |
| 24 | pass # Replace with function body. | |
| 25 | ||
| 26 | ||
| 27 | func setError(url, error): | |
| 28 | text = "Status: Failed Load" + error | |
| 29 | pass # Replace with function body. |
| … | … | @@ -0,0 +1,29 @@ |
| 1 | extends LineEdit | |
| 2 | ||
| 3 | signal url(url) | |
| 4 | ||
| 5 | # Declare member variables here. Examples: | |
| 6 | # var a = 2 | |
| 7 | # var b = "text" | |
| 8 | ||
| 9 | ||
| 10 | # Called when the node enters the scene tree for the first time. | |
| 11 | func _ready(): | |
| 12 | pass # Replace with function body. | |
| 13 | ||
| 14 | ||
| 15 | # Called every frame. 'delta' is the elapsed time since the previous frame. | |
| 16 | #func _process(delta): | |
| 17 | # pass | |
| 18 | ||
| 19 | ||
| 20 | func navigate(): | |
| 21 | var url = text | |
| 22 | if url.begins_with("hyper://"): | |
| 23 | emit_signal("url", url) | |
| 24 | pass # Replace with function body. | |
| 25 | ||
| 26 | ||
| 27 | func _on_URLBar_text_entered(new_text): | |
| 28 | navigate() | |
| 29 | pass # Replace with function body. |
| … | … | @@ -1,5 +1,7 @@ |
| 1 | 1 | [gd_resource type="Environment" load_steps=2 format=2] |
| 2 | ||
| 2 | 3 | [sub_resource type="ProceduralSky" id=1] |
| 4 | ||
| 3 | 5 | [resource] |
| 4 | 6 | background_mode = 2 |
| 5 | 7 | background_sky = SubResource( 1 ) |
| … | … | @@ -11,8 +11,14 @@ config_version=4 |
| 11 | 11 | [application] |
| 12 | 12 | |
| 13 | 13 | config/name="HyperGodot" |
| 14 | run/main_scene="res://HyperLoad.tscn" | |
| 14 | 15 | config/icon="res://icon.png" |
| 15 | 16 | |
| 17 | [display] | |
| 18 | ||
| 19 | window/size/width=666 | |
| 20 | window/size/height=666 | |
| 21 | ||
| 16 | 22 | [physics] |
| 17 | 23 | |
| 18 | 24 | common/enable_pause_aware_picking=true |