This repository has been archived by the owner on Jun 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b731ee5
commit 48988a3
Showing
12 changed files
with
564 additions
and
114 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
[gd_scene load_steps=2 format=2] | ||
|
||
[ext_resource path="res://scripts/NetworkTrainer.gd" type="Script" id=1] | ||
|
||
[node name="NetworkTrainer" type="Node"] | ||
script = ExtResource( 1 ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
[gd_scene load_steps=2 format=2] | ||
|
||
[ext_resource path="res://scripts/TradeScreen.gd" type="Script" id=1] | ||
|
||
[node name="Trade" type="Panel"] | ||
anchor_right = 1.0 | ||
anchor_bottom = 1.0 | ||
script = ExtResource( 1 ) | ||
|
||
[node name="Trainer" type="Panel" parent="."] | ||
anchor_right = 1.0 | ||
anchor_bottom = 1.0 | ||
|
||
[node name="RichTextLabel" type="RichTextLabel" parent="Trainer"] | ||
anchor_left = 0.382813 | ||
anchor_top = 0.28 | ||
anchor_right = 0.617188 | ||
anchor_bottom = 0.72 | ||
margin_bottom = -3.05176e-05 | ||
__meta__ = { | ||
"_edit_use_anchors_": true | ||
} | ||
|
||
[node name="Connecting" type="Panel" parent="."] | ||
anchor_right = 1.0 | ||
anchor_bottom = 1.0 | ||
|
||
[node name="Create_Server" type="Button" parent="Connecting"] | ||
anchor_left = 0.382813 | ||
anchor_top = 0.48 | ||
anchor_right = 0.492188 | ||
anchor_bottom = 0.52 | ||
text = "Create server" | ||
__meta__ = { | ||
"_edit_use_anchors_": true | ||
} | ||
|
||
[node name="Join_Server" type="Button" parent="Connecting"] | ||
anchor_left = 0.507813 | ||
anchor_top = 0.48 | ||
anchor_right = 0.617188 | ||
anchor_bottom = 0.52 | ||
text = "Join Server" | ||
__meta__ = { | ||
"_edit_use_anchors_": true | ||
} | ||
|
||
[node name="IP_Address" type="LineEdit" parent="Connecting"] | ||
anchor_left = 0.382813 | ||
anchor_top = 0.526667 | ||
anchor_right = 0.617188 | ||
anchor_bottom = 0.566667 | ||
align = 1 | ||
placeholder_text = "Enter IP Address" | ||
__meta__ = { | ||
"_edit_use_anchors_": true | ||
} | ||
|
||
[node name="Label" type="Label" parent="Connecting"] | ||
anchor_left = 0.382813 | ||
anchor_top = 0.44 | ||
anchor_right = 0.617188 | ||
anchor_bottom = 0.473333 | ||
__meta__ = { | ||
"_edit_use_anchors_": true | ||
} | ||
|
||
[node name="Trainers" type="Node" parent="."] | ||
|
||
[connection signal="pressed" from="Connecting/Create_Server" to="." method="_on_Create_Server_pressed"] | ||
[connection signal="pressed" from="Connecting/Join_Server" to="." method="_on_Join_Server_pressed"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
extends Node | ||
|
||
|
||
# Declare member variables here. Examples: | ||
# var a = 2 | ||
# var b = "text" | ||
puppet var profile_pic = null | ||
puppet var profile_name = "" | ||
|
||
func _ready(): | ||
pass # Replace with function body. | ||
|
||
|
||
# Called every frame. 'delta' is the elapsed time since the previous frame. | ||
#func _process(delta): | ||
# pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
extends Panel | ||
|
||
|
||
# Declare member variables here. Examples: | ||
# var a = 2 | ||
# var b = "text" | ||
|
||
var new_trainer = load("res://scenes/NetworkTrainer.tscn") | ||
# Called when the node enters the scene tree for the first time. | ||
func _ready(): | ||
get_tree().connect("network_peer_connected", self,"_player_connected") | ||
get_tree().connect("network_peer_disconnected", self,"_player_disconnected") | ||
get_tree().connect("connected_to_server", self, "_connected_to_server") | ||
$Connecting/Label.text = Trading.ip_address | ||
|
||
func _player_connected(id) -> void: | ||
instance_trainer({"name":Trainer.trainer_name,"pic":Trainer.trainer_picture},id) | ||
print("Player "+str(id)+" has connected") | ||
|
||
func _player_disconnected(id) -> void: | ||
print("Player "+str(id)+" has disconnected") | ||
|
||
func _connected_to_server() -> void: | ||
instance_trainer({"name":Trainer.trainer_name,"pic":Trainer.trainer_picture},get_tree().get_network_unique_id()) | ||
|
||
func _on_Create_Server_pressed(): | ||
$Connecting.visible = false | ||
Trading.create_server() | ||
instance_trainer({"name":Trainer.trainer_name,"pic":Trainer.trainer_picture},get_tree().get_network_unique_id()) | ||
|
||
|
||
func _on_Join_Server_pressed(): | ||
if $Connecting/IP_Address.text != "": | ||
$Connecting.visible = false | ||
Trading.ip_address = $Connecting/IP_Address.text | ||
Trading.join_server() | ||
|
||
func instance_trainer(info,id): | ||
var trainer_instance = new_trainer.instance() | ||
print("Player "+str(info["name"])+" has connected") | ||
trainer_instance.profile_name = info["name"] | ||
trainer_instance.profile_pic = info["pic"] | ||
trainer_instance.set_network_master(id) | ||
$Trainers.add_child(trainer_instance) | ||
listTrainers() | ||
|
||
func listTrainers(): | ||
var text = "" | ||
print(get_tree().get_network_connected_peers()) | ||
for trainer in get_tree().get_network_connected_peers(): | ||
var node = get_node(str(trainer)) | ||
text += node.profile_name+"\n" | ||
$Trainer/RichTextLabel.text = text |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
extends Node | ||
|
||
const DEFAULT_PORT = 28960 | ||
const MAX_CLIENTS = 2 | ||
|
||
var server = null | ||
var client = null | ||
|
||
var ip_address = "" | ||
# Called when the node enters the scene tree for the first time. | ||
func _ready(): | ||
for ip in IP.get_local_addresses(): | ||
if ip.begins_with("192.168."): | ||
ip_address = ip | ||
get_tree().connect("connected_to_server", self, "_connected_to_server") | ||
get_tree().connect("server_disconnected", self, "_server_disconnected") | ||
|
||
func create_server() -> void: | ||
server = NetworkedMultiplayerENet.new() | ||
server.create_server(DEFAULT_PORT, MAX_CLIENTS) | ||
get_tree().set_network_peer(server) | ||
|
||
func join_server() -> void: | ||
client = NetworkedMultiplayerENet.new() | ||
client.create_client(ip_address, DEFAULT_PORT) | ||
get_tree().set_network_peer(client) | ||
|
||
func _connect_to_server() -> void: | ||
print("Successfully connected to the server") | ||
|
||
func _server_disconnected() -> void: | ||
print("Disconnected from the server") |