Skip to content

Commit

Permalink
LNX-200 Add a list of agents
Browse files Browse the repository at this point in the history
  • Loading branch information
Krystian Jandy committed Oct 14, 2023
1 parent 9dc903c commit a361af5
Show file tree
Hide file tree
Showing 30 changed files with 712 additions and 94 deletions.
2 changes: 1 addition & 1 deletion .gut_editor_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@
"suffix": ".gd",
"tests": [],
"unit_test_name": null
}
}
23 changes: 22 additions & 1 deletion Camera2D.gd
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ extends Camera2D
@export var min_zoom = Vector2(1.0, 1.0)
var is_mouse_outside_screen = false
var is_mouse_on_gui = false
var target_position: Vector2 = Vector2()
var is_moving_to_target : bool = false
var object_to_follow: Node2D = null

func move_to_position(target: Vector2):
target_position = target
is_moving_to_target = true

func _notification(what):
if what == NOTIFICATION_WM_MOUSE_EXIT:
Expand All @@ -16,7 +23,7 @@ func _notification(what):
is_mouse_outside_screen = false

func _input(event):
if event is InputEventMouseButton:
if event is InputEventMouseButton and not is_mouse_on_gui:
if event.button_index == MOUSE_BUTTON_WHEEL_DOWN:
zoom = zoom / pow(1 + zoom_speed, 1)
zoom = clamp(zoom, min_zoom, max_zoom)
Expand All @@ -27,6 +34,15 @@ func _input(event):
self._reset_camera_position(get_viewport_rect())

func _process(delta):
follow_object(delta)
handle_target_movement(delta)
move_camera_at_screen_edge(delta)

func follow_object(delta):
if self.object_to_follow:
position = position.lerp(object_to_follow.global_position, smoothness * delta)

func move_camera_at_screen_edge(delta: float):
if is_mouse_outside_screen or self.is_mouse_on_gui:
return

Expand Down Expand Up @@ -61,6 +77,11 @@ func _process(delta):
if can_move:
position = camera_pos

func handle_target_movement(delta: float):
if is_moving_to_target:
position = position.lerp(target_position, smoothness * delta)
is_moving_to_target = position.distance_to(target_position) >= 1.0

func _reset_camera_position(viewport_rect):
position = Vector2(0, 0)

Expand Down
2 changes: 1 addition & 1 deletion addons/gut/utils.gd
Original file line number Diff line number Diff line change
Expand Up @@ -482,4 +482,4 @@ func get_scene_script_object(scene):

node_idx += 1

return to_return
return to_return
6 changes: 4 additions & 2 deletions addons/lynx_nodes/entity/action/print/Print.gd
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ extends LynxAction

var _text: String
var _user_id: String
var _object_id: int
@onready var _output_console = get_node("/root/Scene/CanvasLayer/UI/AgentCreator/ColorRect/OutputConsole")
@onready var _audio_sound = load("res://assets/Music/message.wav")

func _init():
self.accepted_attributes = ["text", "user_id"]
self.accepted_attributes = ["text", "user_id", "object_id"]

func _execute():
if _user_id == Globals.USER_ID:
self.play_global_action(self._audio_sound)
self._output_console.print(self._text, Color.WHITE)
var text = "[%s]: %s" % [str(self._object_id), self._text]
self._output_console.print(text, Color.WHITE)
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ func _init():
self.accepted_attributes = ["user_name", "points_updated"]

func _execute():
_resources_panel.update_points(self._points_updated)
if _user_name == Globals.USER_ID:
_resources_panel.update_resources(self._points_updated)

Binary file added addons/lynx_nodes/utils/icons/bin.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 34 additions & 0 deletions addons/lynx_nodes/utils/icons/bin.png.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[remap]

importer="texture"
type="CompressedTexture2D"
uid="uid://5pq2gi5lihnn"
path="res://.godot/imported/bin.png-50ddeb5072c240279418245d92f9d814.ctex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://addons/lynx_nodes/utils/icons/bin.png"
dest_files=["res://.godot/imported/bin.png-50ddeb5072c240279418245d92f9d814.ctex"]

[params]

compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1
Binary file added addons/lynx_nodes/utils/icons/information.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 34 additions & 0 deletions addons/lynx_nodes/utils/icons/information.png.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[remap]

importer="texture"
type="CompressedTexture2D"
uid="uid://dymxgco2w8mdk"
path="res://.godot/imported/information.png-f7bc1290fcb30f248bc76b6b6e4542b1.ctex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://addons/lynx_nodes/utils/icons/information.png"
dest_files=["res://.godot/imported/information.png-f7bc1290fcb30f248bc76b6b6e4542b1.ctex"]

[params]

compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1
Binary file added addons/lynx_nodes/utils/icons/map.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 34 additions & 0 deletions addons/lynx_nodes/utils/icons/map.png.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[remap]

importer="texture"
type="CompressedTexture2D"
uid="uid://df3bkrrtrsypx"
path="res://.godot/imported/map.png-c370e3587c91d4d5c2727c9a027a46b5.ctex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://addons/lynx_nodes/utils/icons/map.png"
dest_files=["res://.godot/imported/map.png-c370e3587c91d4d5c2727c9a027a46b5.ctex"]

[params]

compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1
Binary file added addons/lynx_nodes/utils/icons/remove.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 34 additions & 0 deletions addons/lynx_nodes/utils/icons/remove.png.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[remap]

importer="texture"
type="CompressedTexture2D"
uid="uid://bnrohp1hv8ugw"
path="res://.godot/imported/remove.png-1c33a507190c7dd20d9e4f3071c88a30.ctex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://addons/lynx_nodes/utils/icons/remove.png"
dest_files=["res://.godot/imported/remove.png-1c33a507190c7dd20d9e4f3071c88a30.ctex"]

[params]

compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1
4 changes: 2 additions & 2 deletions globals.gd
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ var DEFAULT_ACTION_SPEED: float = 0.5
var ACTION_SPEED_MULTIPLIER: int
var OBJECTS_IN_CREATION: Array[int] = []
var BUSY_HTTP_STATUSES: Array[int] = [HTTPClient.STATUS_CONNECTING, HTTPClient.STATUS_REQUESTING]
var USER_ID: String = ""
var USER_IS_LOGGED_IN: bool = false
var USER_ID: String = "XD"
var USER_IS_LOGGED_IN: bool = true
26 changes: 25 additions & 1 deletion scene.tscn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[gd_scene load_steps=19 format=3 uid="uid://ynmbka5a07qq"]
[gd_scene load_steps=22 format=3 uid="uid://ynmbka5a07qq"]

[ext_resource type="PackedScene" uid="uid://b1ele5lo5n6u1" path="res://scene/world_updater.tscn" id="1_0bk4q"]
[ext_resource type="PackedScene" uid="uid://bkm4i5405grrr" path="res://ui.tscn" id="1_sys4y"]
Expand All @@ -14,6 +14,9 @@
[ext_resource type="Script" path="res://scene/AgentDeleter.gd" id="12_3vloe"]
[ext_resource type="Script" path="res://scene/RankingFetcher.gd" id="12_11l3g"]
[ext_resource type="AudioStream" uid="uid://bo5mf8ngttnah" path="res://assets/Music/background_music.mp3" id="12_emngv"]
[ext_resource type="Script" path="res://scene/AgentsFetcher.gd" id="15_lya6r"]
[ext_resource type="Script" path="res://scene/AgentFetcher.gd" id="16_1kj1t"]
[ext_resource type="Script" path="res://scene/ResourcesFetcher.gd" id="17_hfgo1"]

[sub_resource type="TileSetAtlasSource" id="TileSetAtlasSource_udycp"]
texture = ExtResource("2_bxdqr")
Expand Down Expand Up @@ -992,11 +995,32 @@ autoplay = true

[node name="GlobalAudioEffect" type="AudioStreamPlayer" parent="."]

[node name="AgentsFetcher" type="Node" parent="."]
script = ExtResource("15_lya6r")

[node name="GetAgentsHTPPRequest" type="HTTPRequest" parent="AgentsFetcher"]

[node name="AgentFetcher" type="Node" parent="."]
script = ExtResource("16_1kj1t")

[node name="GetAgentHTTPRequest" type="HTTPRequest" parent="AgentFetcher"]

[node name="ResourcesFetcher" type="Node" parent="."]
script = ExtResource("17_hfgo1")

[node name="GetResourcesHTTPRequest" type="HTTPRequest" parent="ResourcesFetcher"]

[connection signal="create_agent_requested" from="CanvasLayer/UI" to="AgentCreator" method="_on_ui_create_agent_requested"]
[connection signal="delete_agent_requested" from="CanvasLayer/UI" to="AgentDeleter" method="_on_ui_delete_agent_requested"]
[connection signal="disable_camera_movement" from="CanvasLayer/UI" to="Camera2D" method="_on_ui_disable_camera_movement"]
[connection signal="enable_camera_movement" from="CanvasLayer/UI" to="Camera2D" method="_on_ui_enable_camera_movement"]
[connection signal="get_agent_requested" from="CanvasLayer/UI" to="AgentFetcher" method="_on_ui_get_agent_requested"]
[connection signal="get_agents_requested" from="CanvasLayer/UI" to="AgentsFetcher" method="_on_ui_get_agents_requested"]
[connection signal="get_ranking_requested" from="CanvasLayer/UI" to="RankingFetcher" method="_on_ui_get_ranking_requested"]
[connection signal="get_resources_requested" from="CanvasLayer/UI" to="ResourcesFetcher" method="_on_ui_get_resources_requested"]
[connection signal="post_generate_debug_requested" from="CanvasLayer/UI" to="Generator" method="_on_ui_post_generate_debug_requested"]
[connection signal="post_generate_requested" from="CanvasLayer/UI" to="Generator" method="_on_ui_post_generate_requested"]
[connection signal="request_completed" from="RankingFetcher/GetRankingHTTPRequest" to="RankingFetcher" method="_on_get_ranking_http_request_request_completed"]
[connection signal="request_completed" from="AgentsFetcher/GetAgentsHTPPRequest" to="AgentsFetcher" method="_on_get_agents_htpp_request_request_completed"]
[connection signal="request_completed" from="AgentFetcher/GetAgentHTTPRequest" to="AgentFetcher" method="_on_get_agent_http_request_request_completed"]
[connection signal="request_completed" from="ResourcesFetcher/GetResourcesHTTPRequest" to="ResourcesFetcher" method="_on_get_resources_http_request_request_completed"]
7 changes: 6 additions & 1 deletion scene/AgentDeleter.gd
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
extends Node

@onready var post_agent_http_request = get_node("DeleteAgentHTTPRequest")
@onready var camera = get_node("/root/Scene/Camera2D")

func delete_agent(agent_id):
if post_agent_http_request.get_http_client_status() not in Globals.BUSY_HTTP_STATUSES:
var url = "%sdelete_object?object_id=%s" % [Globals.SERVER_ADDRESS, str(agent_id)]
var url = "%sdelete_object/%s/%s" % [Globals.SERVER_ADDRESS,str(Globals.USER_ID), str(agent_id)]
var result = post_agent_http_request.request(
url,
[],
Expand All @@ -14,5 +15,9 @@ func delete_agent(agent_id):
push_error("[ERROR] Could not DELETE Agent: " + str(result))

func _on_ui_delete_agent_requested(agent_id: int):
var current_followed_object = camera.object_to_follow
if current_followed_object._id == agent_id:
camera.object_to_follow = null

delete_agent(agent_id)

28 changes: 28 additions & 0 deletions scene/AgentFetcher.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
extends Node

@onready var get_agent_http_request = get_node("GetAgentHTTPRequest")
@onready var agent_panel = get_node("/root/Scene/CanvasLayer/UI/AgentPanel")
var json = JSON.new()

func get_agent(agent_id: String):
if self.get_agent_http_request.get_http_client_status() not in Globals.BUSY_HTTP_STATUSES:
var url = "%splayer-agents/%s/%s" % [Globals.SERVER_ADDRESS, str(Globals.USER_ID), agent_id]
var result = self.get_agent_http_request.request(
url,
[],
HTTPClient.METHOD_GET
)
if result != OK:
push_error("[ERROR] Could not GET Agent: %s" % [result])


func _on_get_agent_http_request_request_completed(result, response_code, headers, body):
if response_code == 200:
json.parse(body.get_string_from_utf8())
var agent = json.get_data()
self.agent_panel.display(agent)
return


func _on_ui_get_agent_requested(agent_id: int):
self.get_agent(str(agent_id))
27 changes: 27 additions & 0 deletions scene/AgentsFetcher.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
extends Node

@onready var get_agents_http_request = get_node("GetAgentsHTPPRequest")
@onready var agents = get_node("/root/Scene/CanvasLayer/UI/Agents")
var json = JSON.new()

func get_agents():
if self.get_agents_http_request.get_http_client_status() not in Globals.BUSY_HTTP_STATUSES:
var url = "%splayer-agents/%s" % [Globals.SERVER_ADDRESS, str(Globals.USER_ID)]
var result = self.get_agents_http_request.request(
url,
[],
HTTPClient.METHOD_GET
)
if result != OK:
push_error("[ERROR] Could not GET Agents: %s" % [result])

func _on_get_agents_htpp_request_request_completed(result, response_code, headers, body):
var agents = []
if response_code == 200:
json.parse(body.get_string_from_utf8())
agents = json.get_data()

self.agents.populate(agents)

func _on_ui_get_agents_requested():
self.get_agents()
26 changes: 26 additions & 0 deletions scene/ResourcesFetcher.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
extends Node

@onready var get_resources_http_request = get_node("GetResourcesHTTPRequest")
@onready var resources_panel = get_node("/root/Scene/CanvasLayer/UI/ResourcesPanel")
var json = JSON.new()

func _ready():
self.get_resources()

func get_resources():
if get_resources_http_request.get_http_client_status() not in Globals.BUSY_HTTP_STATUSES:
var url = "%splayer-resources/%s" % [Globals.SERVER_ADDRESS, str(Globals.USER_ID)]
print(url)
var result = self.get_resources_http_request.request(
url,
[],
HTTPClient.METHOD_GET
)
if result != OK:
push_error("[ERROR] Could not GET Resources: %s" % [result])

func _on_get_resources_http_request_request_completed(result, response_code, headers, body):
if response_code == 200:
json.parse(body.get_string_from_utf8())
var response = json.get_data()
self.resources_panel.update_resources(json.get_data())
Loading

0 comments on commit a361af5

Please sign in to comment.