Initial commit for testing/fixing a deprecated godot-colyseus addon
This commit is contained in:
BIN
addons/godot_colyseus/demo/blur.png
Normal file
BIN
addons/godot_colyseus/demo/blur.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 3.7 KiB |
34
addons/godot_colyseus/demo/blur.png.import
Normal file
34
addons/godot_colyseus/demo/blur.png.import
Normal file
@@ -0,0 +1,34 @@
|
||||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="CompressedTexture2D"
|
||||
uid="uid://bdhx6b3h4tkao"
|
||||
path="res://.godot/imported/blur.png-4563c8475376415b661c69b2b9f1d2d4.ctex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://addons/godot_colyseus/demo/blur.png"
|
||||
dest_files=["res://.godot/imported/blur.png-4563c8475376415b661c69b2b9f1d2d4.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
|
||||
8
addons/godot_colyseus/demo/char.tscn
Normal file
8
addons/godot_colyseus/demo/char.tscn
Normal file
@@ -0,0 +1,8 @@
|
||||
[gd_scene load_steps=2 format=2]
|
||||
|
||||
[ext_resource path="res://addons/godot_colyseus/demo/blur.png" type="Texture2D" id=1]
|
||||
|
||||
[node name="char" type="Sprite2D"]
|
||||
position = Vector2( 0, -16 )
|
||||
scale = Vector2( 0.6, 1 )
|
||||
texture = ExtResource( 1 )
|
||||
32
addons/godot_colyseus/demo/chat.gd
Normal file
32
addons/godot_colyseus/demo/chat.gd
Normal file
@@ -0,0 +1,32 @@
|
||||
extends Control
|
||||
|
||||
const colyseus = preload("res://addons/godot_colyseus/lib/colyseus.gd")
|
||||
var room: colyseus.Room
|
||||
|
||||
func _ready():
|
||||
var client = colyseus.Client.new("ws://localhost:2567")
|
||||
var promise = client.join_or_create(colyseus.Schema, "chat")
|
||||
await promise.completed
|
||||
if promise.get_state() == promise.State.Failed:
|
||||
print("Failed")
|
||||
return
|
||||
var room: colyseus.Room = promise.get_data()
|
||||
room.on_message("messages").on(Callable(self, "_on_messages"))
|
||||
$label.text += "Connected"
|
||||
self.room = room
|
||||
|
||||
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
#func _process(delta):
|
||||
# pass
|
||||
|
||||
func _on_messages(data):
|
||||
$label.text += "\n" + data
|
||||
|
||||
|
||||
func _on_send_pressed():
|
||||
if $input.text.is_empty():
|
||||
return
|
||||
room.send("message", $input.text)
|
||||
$input.text = ""
|
||||
1
addons/godot_colyseus/demo/chat.gd.uid
Normal file
1
addons/godot_colyseus/demo/chat.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://cj7jhyoe2eluq
|
||||
48
addons/godot_colyseus/demo/chat.tscn
Normal file
48
addons/godot_colyseus/demo/chat.tscn
Normal file
@@ -0,0 +1,48 @@
|
||||
[gd_scene load_steps=2 format=3 uid="uid://dpxco2ygtk2bx"]
|
||||
|
||||
[ext_resource type="Script" path="res://addons/godot_colyseus/demo/chat.gd" id="1"]
|
||||
|
||||
[node name="Control" type="Control"]
|
||||
layout_mode = 3
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
script = ExtResource("1")
|
||||
|
||||
[node name="input" type="TextEdit" parent="."]
|
||||
layout_mode = 1
|
||||
anchors_preset = -1
|
||||
anchor_top = 0.927
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
offset_top = -0.200012
|
||||
offset_right = -110.0
|
||||
|
||||
[node name="send" type="Button" parent="."]
|
||||
layout_mode = 1
|
||||
anchors_preset = 3
|
||||
anchor_left = 1.0
|
||||
anchor_top = 1.0
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
offset_left = -104.0
|
||||
offset_top = -42.0
|
||||
offset_right = 1.0
|
||||
offset_bottom = -4.0
|
||||
grow_horizontal = 0
|
||||
grow_vertical = 0
|
||||
text = "Send"
|
||||
|
||||
[node name="label" type="Label" parent="."]
|
||||
layout_mode = 1
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
offset_right = -2.0
|
||||
offset_bottom = -54.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
|
||||
[connection signal="pressed" from="send" to="." method="_on_send_pressed"]
|
||||
27
addons/godot_colyseus/demo/control.tscn
Normal file
27
addons/godot_colyseus/demo/control.tscn
Normal file
@@ -0,0 +1,27 @@
|
||||
[gd_scene load_steps=2 format=3 uid="uid://cxtq2mh35wwc5"]
|
||||
|
||||
[sub_resource type="GDScript" id="GDScript_uosag"]
|
||||
script/source = "extends Control
|
||||
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready():
|
||||
print(\"test \", await test_await())
|
||||
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(delta):
|
||||
pass
|
||||
|
||||
func test_await():
|
||||
return 2
|
||||
"
|
||||
|
||||
[node name="Control" type="Control"]
|
||||
layout_mode = 3
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
script = SubResource("GDScript_uosag")
|
||||
68
addons/godot_colyseus/demo/main.gd
Normal file
68
addons/godot_colyseus/demo/main.gd
Normal file
@@ -0,0 +1,68 @@
|
||||
extends Node2D
|
||||
|
||||
const colyseus = preload("res://addons/godot_colyseus/lib/colyseus.gd")
|
||||
const Char = preload("./char.tscn")
|
||||
|
||||
class Player extends colyseus.Schema:
|
||||
static func define_fields():
|
||||
return [
|
||||
colyseus.Field.new("x", colyseus.NUMBER),
|
||||
colyseus.Field.new("y", colyseus.NUMBER)
|
||||
]
|
||||
|
||||
var node
|
||||
|
||||
func _to_string():
|
||||
return str("(",self.x,",",self.y,")")
|
||||
|
||||
class RoomState extends colyseus.Schema:
|
||||
static func define_fields():
|
||||
return [
|
||||
colyseus.Field.new("players", colyseus.MAP, Player),
|
||||
]
|
||||
|
||||
var room: colyseus.Room
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready():
|
||||
var client = colyseus.Client.new("ws://localhost:2567")
|
||||
var promise = client.join_or_create(RoomState, "state_handler")
|
||||
await promise.completed
|
||||
if promise.get_state() == promise.State.Failed:
|
||||
print("Failed")
|
||||
return
|
||||
var room: colyseus.Room = promise.get_data()
|
||||
var state: RoomState = room.get_state()
|
||||
state.listen('players:add').on(Callable(self, "_on_players_add"))
|
||||
room.on_state_change.on(Callable(self, "_on_state"))
|
||||
room.on_message("hello").on(Callable(self, "_on_message"))
|
||||
self.room = room
|
||||
|
||||
func _on_message(data):
|
||||
print(str("hello:", data))
|
||||
|
||||
func _on_state(state):
|
||||
pass
|
||||
|
||||
func _on_players_add(target, value, key):
|
||||
print("Add:", " key:", key, " ", value)
|
||||
var ch = Char.instantiate()
|
||||
ch.position = Vector2(value.x, value.y)
|
||||
add_child(ch)
|
||||
value.node = ch
|
||||
value.listen(":change").on(Callable(self, "_on_player"))
|
||||
|
||||
func _on_player(target):
|
||||
print("Change ", target)
|
||||
var ch = target.node
|
||||
ch.position = Vector2(target.x, target.y)
|
||||
|
||||
func _physics_process(delta):
|
||||
if Input.is_action_pressed("ui_up"):
|
||||
room.send("move", { y = -1 });
|
||||
elif Input.is_action_pressed("ui_down"):
|
||||
room.send("move", { y = 1 });
|
||||
elif Input.is_action_pressed("ui_left"):
|
||||
room.send("move", { x = -1 });
|
||||
elif Input.is_action_pressed("ui_right"):
|
||||
room.send("move", { x = 1 });
|
||||
1
addons/godot_colyseus/demo/main.gd.uid
Normal file
1
addons/godot_colyseus/demo/main.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://ddjkvt52o2ggh
|
||||
6
addons/godot_colyseus/demo/main.tscn
Normal file
6
addons/godot_colyseus/demo/main.tscn
Normal file
@@ -0,0 +1,6 @@
|
||||
[gd_scene load_steps=2 format=3 uid="uid://ceqab8i8yqmjj"]
|
||||
|
||||
[ext_resource type="Script" path="res://addons/godot_colyseus/demo/main.gd" id="1"]
|
||||
|
||||
[node name="Node2D" type="Node2D"]
|
||||
script = ExtResource("1")
|
||||
Reference in New Issue
Block a user