Formatted chat text, syncronizing player_info between peers (not working reliably)

pull/50/head
unfa 2021-06-19 03:40:10 +02:00
parent e8b9acb761
commit 9e3f60a4f1
15 changed files with 114 additions and 47 deletions

View File

@ -29,14 +29,26 @@ class PlayerInfo:
var name: String
var team: int
var color: Color
var is_typing: bool
func _init(name: String, team: int, color: Color):
self.name = name
self.team = team
self.color = color
self.is_typing = false
func serialize():
return {
'name': self.name,
'team': str(self.team),
'color': self.color.to_html(),
'is_typing': self.is_typing,
}
var input_active = false
@remotesync var player_info: PlayerInfo
var player_info: PlayerInfo
var base_fov = 90
var view_zoom := 1.0 :
set(zoom):
@ -80,22 +92,29 @@ var jump := 14
var velocity := Vector3.ZERO
var gravity_vec := Vector3.ZERO
@remotesync func set_info(info):
player_info = PlayerInfo.new(info['name'], info['team'].to_int(), Color(info['color']))
@master func generate_info() -> void:
var player_name = ""
for i in range(0, 4):
player_name += ['a','b','c', 'd', 'e', 'f'][randi() % 5]
var color = Color(randf(),randf(),randf())
rpc(&'set_info', PlayerInfo.new(player_name, 0, color).serialize() )
func _ready() -> void:
#Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
view_zoom = 1.0
# generate random names for testing
var player_name = ""
for i in range(0, 4):
player_name += ['a','b','c'][randi() % 2]
player_info = PlayerInfo.new(player_name, 0, Color("#CE0000"))
generate_info()
rpc_config(&"move_and_slide", MultiplayerAPI.RPC_MODE_PUPPETSYNC)
rpc_config(&"aim", MultiplayerAPI.RPC_MODE_PUPPETSYNC)
rpc_config(&"set_global_transform", MultiplayerAPI.RPC_MODE_PUPPET)
rpc_config(&"set_linear_velocity", MultiplayerAPI.RPC_MODE_PUPPET)
head.rpc_config(&"set_rotation", MultiplayerAPI.RPC_MODE_PUPPETSYNC)
#rpc_config(&"set_info", MultiplayerAPI.RPC_MODE_PUPPETSYNC)
func aim(event) -> void:
var mouse_motion = event as InputEventMouseMotion
@ -122,6 +141,7 @@ func _input(event) -> void:
tween.start()
rpc_unreliable(&'aim', event)
# rpc(&'aim', event)
if Input.is_action_just_pressed("trigger_primary"):
weapon.rpc(&'trigger', 0, true)
@ -135,6 +155,8 @@ func _input(event) -> void:
func _physics_process(delta):
rpc_unreliable(&'set_global_transform', global_transform)
head.rpc_unreliable(&'set_rotation', head.get_rotation())
# rpc(&'set_global_transform', global_transform)
# head.rpc(&'set_rotation', head.get_rotation())
direction = Vector3.ZERO
@ -173,6 +195,8 @@ func _physics_process(delta):
#slide = move_and_slide_with_snap(movement, snap, Vector3.UP)
rpc_unreliable(&'set_linear_velocity', linear_velocity)
rpc_unreliable(&"move_and_slide")
# rpc(&'set_linear_velocity', linear_velocity)
# rpc(&"move_and_slide")
#move_and_slide()
if not is_on_floor() and not ground_check.is_colliding(): # while in mid-air collisions affect momentum

Binary file not shown.

Before

Width:  |  Height:  |  Size: 519 KiB

View File

@ -1,36 +0,0 @@
[remap]
importer="texture"
type="StreamTexture2D"
path.s3tc="res://.godot/imported/Flame.png-7c44abd65ae181a5818470a5b3268f30.s3tc.stex"
path.etc2="res://.godot/imported/Flame.png-7c44abd65ae181a5818470a5b3268f30.etc2.stex"
metadata={
"imported_formats": [ "s3tc", "etc2" ],
"vram_texture": true
}
[deps]
source_file="res://Assets/Effects/Flame.png"
dest_files=[ "res://.godot/imported/Flame.png-7c44abd65ae181a5818470a5b3268f30.s3tc.stex", "res://.godot/imported/Flame.png-7c44abd65ae181a5818470a5b3268f30.etc2.stex" ]
[params]
compress/mode=2
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/bptc_ldr=0
compress/normal_map=0
compress/channel_pack=0
compress/streamed=false
mipmaps/generate=true
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/size_limit=0
detect_3d/compress_to=0
svg/scale=1.0

View File

@ -0,0 +1,47 @@
SIL Open Font License
Digitized data copyright (c) 2010 Google Corporation
with Reserved Font Arimo, Tinos and Cousine.
Copyright (c) 2012 Red Hat, Inc.
with Reserved Font Name Liberation.
This Font Software is licensed under the SIL Open Font License, Version 1.1.
This license is copied below, and is also available with a FAQ at: http://scripts.sil.org/OFL
—————————————————————————————-
SIL OPEN FONT LICENSE Version 1.1 26 February 2007
—————————————————————————————-
PREAMBLE
The goals of the Open Font License (OFL) are to stimulate worldwide development of collaborative font projects, to support the font creation efforts of academic and linguistic communities, and to provide a free and open framework in which fonts may be shared and improved in partnership with others.
The OFL allows the licensed fonts to be used, studied, modified and redistributed freely as long as they are not sold by themselves. The fonts, including any derivative works, can be bundled, embedded, redistributed and/or sold with any software provided that any reserved names are not used by derivative works. The fonts and derivatives, however, cannot be released under any other type of license. The requirement for fonts to remain under this license does not apply to any document created using the fonts or their derivatives.
DEFINITIONS
“Font Software” refers to the set of files released by the Copyright Holder(s) under this license and clearly marked as such. This may include source files, build scripts and documentation.
“Reserved Font Name” refers to any names specified as such after the copyright statement(s).
“Original Version” refers to the collection of Font Software components as distributed by the Copyright Holder(s).
“Modified Version” refers to any derivative made by adding to, deleting, or substituting—in part or in whole—any of the components of the Original Version, by changing formats or by porting the Font Software to a new environment.
“Author” refers to any designer, engineer, programmer, technical writer or other person who contributed to the Font Software.
PERMISSION & CONDITIONS
Permission is hereby granted, free of charge, to any person obtaining a copy of the Font Software, to use, study, copy, merge, embed, modify, redistribute, and sell modified and unmodified copies of the Font Software, subject to the following conditions:
1) Neither the Font Software nor any of its individual components, in Original or Modified Versions, may be sold by itself.
2) Original or Modified Versions of the Font Software may be bundled, redistributed and/or sold with any software, provided that each copy contains the above copyright notice and this license. These can be included either as stand-alone text files, human-readable headers or in the appropriate machine-readable metadata fields within text or binary files as long as those fields can be easily viewed by the user.
3) No Modified Version of the Font Software may use the Reserved Font Name(s) unless explicit written permission is granted by the corresponding Copyright Holder. This restriction only applies to the primary font name as presented to the users.
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font Software shall not be used to promote, endorse or advertise any Modified Version, except to acknowledge the contribution(s) of the Copyright Holder(s) and the Author(s) or with their explicit written permission.
5) The Font Software, modified or unmodified, in part or in whole, must be distributed entirely under this license, and must not be distributed under any other license. The requirement for fonts to remain under this license does not apply to any document created using the Font Software.
TERMINATION
This license becomes null and void if any of the above conditions are not met.
DISCLAIMER
THE FONT SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM OTHER DEALINGS IN THE FONT SOFTWARE.

View File

@ -54,8 +54,9 @@ func _unhandled_input(_event) -> void:
# doesn't work over network due to missing RPC implementation in Godot 4
@remotesync func chat_message(sender_id: int, recipient_team, message: String) -> void:
var sender_name = main.get_node("Players").get_node(str(sender_id)).player_info.name
chat_history.text += '\n' + str(sender_name) + " | " + message
var sender_info = main.get_node("Players").get_node(str(sender_id)).player_info
chat_history.append_bbcode('\n' + '[b][color=' + sender_info.color.to_html() +']' + str(sender_info.name) + '[/color][/b] : [i]' + message + '[/i]')
func _on_LineEdit_text_entered(new_text):
# RPC is currently not implemented in the engine

View File

@ -1,4 +1,4 @@
[gd_scene load_steps=10 format=2]
[gd_scene load_steps=11 format=2]
[ext_resource path="res://Assets/HUD/Vignette.png" type="Texture2D" id=1]
[ext_resource path="res://Assets/HUD/Crosshair.png" type="Texture2D" id=2]
@ -6,6 +6,7 @@
[ext_resource path="res://Assets/SFX/UI_Confirm_Hit.wav" type="AudioStream" id=4]
[ext_resource path="res://Assets/HUD/Crosshair.gd" type="Script" id=5]
[ext_resource path="res://Assets/HUD/Chat.gd" type="Script" id=6]
[ext_resource path="res://Assets/HUD/Theme.tres" type="Theme" id=7]
[sub_resource type="Animation" id=1]
resource_name = "Default"
@ -166,10 +167,12 @@ offset_top = 37.0
offset_right = 300.0
offset_bottom = 507.0
rect_min_size = Vector2( 0, 470 )
theme = ExtResource( 7 )
bbcode_enabled = true
scroll_active = false
scroll_following = true
custom_effects = [ ]
structured_text_bidi_override_options = [ ]
structured_text_bidi_override_options = [ @"" ]
script = null
__meta__ = {
"_edit_use_anchors_": false

View File

@ -0,0 +1,28 @@
[gd_resource type="Theme" load_steps=10 format=2]
[ext_resource path="res://Assets/Fonts/Liberation Sans/LiberationSans-Italic.ttf" type="FontData" id=1]
[ext_resource path="res://Assets/Fonts/Liberation Sans/LiberationSans-Bold.ttf" type="FontData" id=2]
[ext_resource path="res://Assets/Fonts/Liberation Sans/LiberationMono-Regular.ttf" type="FontData" id=3]
[ext_resource path="res://Assets/Fonts/Liberation Sans/LiberationSans-Regular.ttf" type="FontData" id=4]
[sub_resource type="Font" id=1]
data/0 = ExtResource( 2 )
[sub_resource type="Font" id=2]
data/0 = ExtResource( 1 )
[sub_resource type="Font" id=3]
data/0 = ExtResource( 1 )
[sub_resource type="Font" id=4]
data/0 = ExtResource( 3 )
[sub_resource type="Font" id=5]
data/0 = ExtResource( 4 )
[resource]
RichTextLabel/fonts/bold_font = SubResource( 1 )
RichTextLabel/fonts/bold_italics_font = SubResource( 2 )
RichTextLabel/fonts/italics_font = SubResource( 3 )
RichTextLabel/fonts/mono_font = SubResource( 4 )
RichTextLabel/fonts/normal_font = SubResource( 5 )