Refactored to allow hotseat and multiplayer. TODO: Create interface class for webrtc/enet multiplayer

This commit is contained in:
Sch1nken 2024-03-22 01:37:05 +01:00
parent d688eaf9c6
commit 5fe8f22ccb
27 changed files with 798 additions and 135 deletions

View file

@ -0,0 +1,41 @@
// NOTE: Shader automatically converted from Godot Engine 4.2.1.stable's StandardMaterial3D.
shader_type spatial;
render_mode blend_add,depth_draw_always,cull_back,diffuse_burley,specular_schlick_ggx;
uniform vec4 albedo : source_color;
uniform sampler2D texture_albedo : source_color,filter_linear_mipmap,repeat_enable;
uniform float distance_fade_min;
uniform float distance_fade_max;
uniform float roughness : hint_range(0,1);
uniform sampler2D texture_metallic : hint_default_white,filter_linear_mipmap,repeat_enable;
uniform vec4 metallic_texture_channel;
uniform sampler2D texture_roughness : hint_roughness_r,filter_linear_mipmap,repeat_enable;
uniform float specular;
uniform float metallic;
uniform vec3 uv1_scale;
uniform vec3 uv1_offset;
void vertex() {
UV=UV*uv1_scale.xy+uv1_offset.xy;
}
void fragment() {
vec2 base_uv = UV;
vec4 albedo_tex = texture(texture_albedo,base_uv);
ALBEDO = albedo.rgb * albedo_tex.rgb;
float metallic_tex = dot(texture(texture_metallic,base_uv),metallic_texture_channel);
METALLIC = metallic_tex * metallic;
vec4 roughness_texture_channel = vec4(1.0,0.0,0.0,0.0);
float roughness_tex = dot(texture(texture_roughness,base_uv),roughness_texture_channel);
ROUGHNESS = roughness_tex * roughness;
SPECULAR = specular;
ALPHA *= albedo.a * albedo_tex.a;
vec4 wrld_vertex = INV_VIEW_MATRIX * vec4(VERTEX, 1.0);
ALPHA *= clamp(smoothstep(distance_fade_min, distance_fade_max, length(wrld_vertex)), 0.0, 1.0);
}

57
Testbed/GridTest.gdshader Normal file
View file

@ -0,0 +1,57 @@
shader_type spatial;
uniform int scale_0 : hint_range(1, 1024, 1);
uniform int scale_1 : hint_range(1, 1024, 1);
uniform float line_scale_0 : hint_range(0.001, 1, 0.001);
uniform float line_scale_1 : hint_range(0.001, 1, 0.001);
uniform vec4 color_0 : source_color;
uniform vec4 color_1 : source_color;
render_mode blend_add;
float pristineGrid( vec2 uv, vec2 lineWidth)
{
vec2 ddx = dFdx(uv);
vec2 ddy = dFdy(uv);
vec2 uvDeriv = vec2(length(vec2(ddx.x, ddy.x)), length(vec2(ddx.y, ddy.y)));
bvec2 invertLine = bvec2(lineWidth.x > 0.5, lineWidth.y > 0.5);
vec2 targetWidth = vec2(
invertLine.x ? 1.0 - lineWidth.x : lineWidth.x,
invertLine.y ? 1.0 - lineWidth.y : lineWidth.y
);
vec2 drawWidth = clamp(targetWidth, uvDeriv, vec2(0.5));
vec2 lineAA = uvDeriv * 1.5;
vec2 gridUV = abs(fract(uv) * 2.0 - 1.0);
gridUV.x = invertLine.x ? gridUV.x : 1.0 - gridUV.x;
gridUV.y = invertLine.y ? gridUV.y : 1.0 - gridUV.y;
vec2 grid2 = smoothstep(drawWidth + lineAA, drawWidth - lineAA, gridUV);
grid2 *= clamp(targetWidth / drawWidth, 0.0, 1.0);
grid2 = mix(grid2, targetWidth, clamp(uvDeriv * 2.0 - 1.0, 0.0, 1.0));
grid2.x = invertLine.x ? 1.0 - grid2.x : grid2.x;
grid2.y = invertLine.y ? 1.0 - grid2.y : grid2.y;
return mix(grid2.x, 1.0, grid2.y);
}
void vertex()
{
//UV = VERTEX.xz;
}
void fragment()
{
vec3 grid_0 = vec3(pristineGrid(UV * float(scale_0), vec2(line_scale_0)));
vec3 grid_1 = vec3(pristineGrid(UV * float(scale_1), vec2(line_scale_1)));
vec3 grid_3 = mix(grid_1 * color_1.rgb, grid_0 * color_0.rgb, grid_0);
ALBEDO = grid_3;
ALPHA = 1.5;
}

53
Testbed/Rules.gd Normal file
View file

@ -0,0 +1,53 @@
extends Control
@onready var category_label = $Pivot/MarginContainer/PanelContainer/MarginContainer/VBoxContainer/HBoxContainer/VBoxContainer2/CategoryLabel
@onready var margin_container = $Pivot/MarginContainer/PanelContainer/MarginContainer/VBoxContainer/HBoxContainer/VBoxContainer2/ScrollContainer/PanelContainer/MarginContainer
@onready var panel_container = $PanelContainer
@onready var general = $Pivot/MarginContainer/PanelContainer/MarginContainer/VBoxContainer/HBoxContainer/VBoxContainer/General
@onready var margin_container2 = $Pivot/MarginContainer
var mat: ShaderMaterial
func show_panel() -> void:
margin_container2.position.y = 700
mat.set_shader_parameter("lod", 0)
visible = true
var tween = get_tree().create_tween()
tween.set_parallel(true)
tween.tween_method(tween_blur, 0.0, 1.0, 0.5).set_trans(Tween.TRANS_EXPO).set_ease(Tween.EASE_IN_OUT)
tween.tween_property(margin_container2, "position:y", 0.0, 0.5).set_trans(Tween.TRANS_SPRING).set_ease(Tween.EASE_OUT)
# Called when the node enters the scene tree for the first time.
func _ready():
mat = panel_container.material
pass # Replace with function body.
func tween_blur(val: float) -> void:
mat.set_shader_parameter("lod", val)
pass
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
pass
func _on_button_pressed(label: NodePath, category: String = ""):
for child in margin_container.get_children():
child.visible = false
category_label.text = category
# hacky
general.get_node(label).visible = true
func _on_ant_pressed(extra_arg_0, extra_arg_1):
pass # Replace with function body.
func _on_close_button_pressed():
visible = false

249
Testbed/Rules.tscn Normal file
View file

@ -0,0 +1,249 @@
[gd_scene load_steps=4 format=3 uid="uid://8ffmln680deh"]
[ext_resource type="Script" path="res://Testbed/Rules.gd" id="1_qbtgw"]
[ext_resource type="Shader" path="res://Testbed/UIBlur.gdshader" id="2_ux84o"]
[sub_resource type="ShaderMaterial" id="ShaderMaterial_h3smw"]
shader = ExtResource("2_ux84o")
shader_parameter/lod = 1.0
[node name="Rules" type="Control"]
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
size_flags_horizontal = 4
size_flags_vertical = 4
script = ExtResource("1_qbtgw")
[node name="PanelContainer" type="PanelContainer" parent="."]
self_modulate = Color(1, 1, 1, 0.392157)
material = SubResource("ShaderMaterial_h3smw")
layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
[node name="Pivot" type="Control" parent="."]
layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
[node name="MarginContainer" type="MarginContainer" parent="Pivot"]
layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
theme_override_constants/margin_left = 50
theme_override_constants/margin_top = 50
theme_override_constants/margin_right = 50
theme_override_constants/margin_bottom = 50
[node name="PanelContainer" type="PanelContainer" parent="Pivot/MarginContainer"]
layout_mode = 2
[node name="MarginContainer" type="MarginContainer" parent="Pivot/MarginContainer/PanelContainer"]
layout_mode = 2
theme_override_constants/margin_left = 15
theme_override_constants/margin_top = 15
theme_override_constants/margin_right = 15
theme_override_constants/margin_bottom = 15
[node name="VBoxContainer" type="VBoxContainer" parent="Pivot/MarginContainer/PanelContainer/MarginContainer"]
layout_mode = 2
[node name="HBoxContainer" type="HBoxContainer" parent="Pivot/MarginContainer/PanelContainer/MarginContainer/VBoxContainer"]
layout_mode = 2
size_flags_vertical = 3
theme_override_constants/separation = 15
[node name="VBoxContainer" type="VBoxContainer" parent="Pivot/MarginContainer/PanelContainer/MarginContainer/VBoxContainer/HBoxContainer"]
custom_minimum_size = Vector2(100, 0)
layout_mode = 2
[node name="General" type="Button" parent="Pivot/MarginContainer/PanelContainer/MarginContainer/VBoxContainer/HBoxContainer/VBoxContainer"]
layout_mode = 2
text = "General"
[node name="Placing" type="Button" parent="Pivot/MarginContainer/PanelContainer/MarginContainer/VBoxContainer/HBoxContainer/VBoxContainer"]
layout_mode = 2
text = "Placing"
[node name="Moving" type="Button" parent="Pivot/MarginContainer/PanelContainer/MarginContainer/VBoxContainer/HBoxContainer/VBoxContainer"]
layout_mode = 2
text = "Moving"
[node name="HSeparator" type="HSeparator" parent="Pivot/MarginContainer/PanelContainer/MarginContainer/VBoxContainer/HBoxContainer/VBoxContainer"]
layout_mode = 2
[node name="Bee" type="Button" parent="Pivot/MarginContainer/PanelContainer/MarginContainer/VBoxContainer/HBoxContainer/VBoxContainer"]
layout_mode = 2
text = "Bee"
[node name="Beetle" type="Button" parent="Pivot/MarginContainer/PanelContainer/MarginContainer/VBoxContainer/HBoxContainer/VBoxContainer"]
layout_mode = 2
text = "Beetle"
[node name="Grasshopper" type="Button" parent="Pivot/MarginContainer/PanelContainer/MarginContainer/VBoxContainer/HBoxContainer/VBoxContainer"]
layout_mode = 2
text = "Grasshopper"
[node name="Spider" type="Button" parent="Pivot/MarginContainer/PanelContainer/MarginContainer/VBoxContainer/HBoxContainer/VBoxContainer"]
layout_mode = 2
text = "Spider"
[node name="Ant" type="Button" parent="Pivot/MarginContainer/PanelContainer/MarginContainer/VBoxContainer/HBoxContainer/VBoxContainer"]
layout_mode = 2
text = "Ant"
[node name="Ladybug" type="Button" parent="Pivot/MarginContainer/PanelContainer/MarginContainer/VBoxContainer/HBoxContainer/VBoxContainer"]
layout_mode = 2
disabled = true
text = "Ladybug"
[node name="Mosquito" type="Button" parent="Pivot/MarginContainer/PanelContainer/MarginContainer/VBoxContainer/HBoxContainer/VBoxContainer"]
layout_mode = 2
disabled = true
text = "Mosquito"
[node name="Pillbug" type="Button" parent="Pivot/MarginContainer/PanelContainer/MarginContainer/VBoxContainer/HBoxContainer/VBoxContainer"]
layout_mode = 2
disabled = true
text = "Pillbug"
[node name="VBoxContainer2" type="VBoxContainer" parent="Pivot/MarginContainer/PanelContainer/MarginContainer/VBoxContainer/HBoxContainer"]
layout_mode = 2
size_flags_horizontal = 3
[node name="CategoryLabel" type="Label" parent="Pivot/MarginContainer/PanelContainer/MarginContainer/VBoxContainer/HBoxContainer/VBoxContainer2"]
layout_mode = 2
text = "General"
[node name="ScrollContainer" type="ScrollContainer" parent="Pivot/MarginContainer/PanelContainer/MarginContainer/VBoxContainer/HBoxContainer/VBoxContainer2"]
layout_mode = 2
size_flags_horizontal = 3
size_flags_vertical = 3
[node name="PanelContainer" type="PanelContainer" parent="Pivot/MarginContainer/PanelContainer/MarginContainer/VBoxContainer/HBoxContainer/VBoxContainer2/ScrollContainer"]
layout_mode = 2
size_flags_horizontal = 3
size_flags_vertical = 3
[node name="MarginContainer" type="MarginContainer" parent="Pivot/MarginContainer/PanelContainer/MarginContainer/VBoxContainer/HBoxContainer/VBoxContainer2/ScrollContainer/PanelContainer"]
layout_mode = 2
theme_override_constants/margin_left = 10
theme_override_constants/margin_top = 10
theme_override_constants/margin_right = 10
theme_override_constants/margin_bottom = 10
[node name="GeneralLabel" type="RichTextLabel" parent="Pivot/MarginContainer/PanelContainer/MarginContainer/VBoxContainer/HBoxContainer/VBoxContainer2/ScrollContainer/PanelContainer/MarginContainer"]
layout_mode = 2
text = "The pieces in play define the playing surface, known as the Hive.
Play begings with one player placing a piece from their hand in the center of the table and the next player joining one of their own pieces to it edge to edge.
Players then take turns to either place or move any one of their pieces."
fit_content = true
[node name="PlacingLabel" type="RichTextLabel" parent="Pivot/MarginContainer/PanelContainer/MarginContainer/VBoxContainer/HBoxContainer/VBoxContainer2/ScrollContainer/PanelContainer/MarginContainer"]
visible = false
layout_mode = 2
text = "A new piece can be introduced into the game at any time. However, with the exception of the first piece placed by each player, pieces may not be placed next to a piece of the opponent's color.
It is possible to win the game without placing all your pieces but once a piece has been placed it can't be removed.
Your Queen Bee can be placed at any time from your first to your fourth turn. You must place your Queen Bee on your fourth turn if you have not placed it before."
fit_content = true
[node name="MovingLabel" type="RichTextLabel" parent="Pivot/MarginContainer/PanelContainer/MarginContainer/VBoxContainer/HBoxContainer/VBoxContainer2/ScrollContainer/PanelContainer/MarginContainer"]
visible = false
layout_mode = 2
text = "Once your Queen Bee has been placed (but not before), you can decide whether to use each turn after that to place another tile or to move one of the pieces that have already been placed.
Each creature has its own way of moving about the Hive and it's possible to move pieces to a position where they touch one or more of your opponent's tiles.
Note: All pieces must always touch at least one other piece. If a piece the only connection between two parts of the Hive, it may not be moved."
fit_content = true
[node name="BeeLabel" type="RichTextLabel" parent="Pivot/MarginContainer/PanelContainer/MarginContainer/VBoxContainer/HBoxContainer/VBoxContainer2/ScrollContainer/PanelContainer/MarginContainer"]
visible = false
layout_mode = 2
bbcode_enabled = true
text = "The Queen Bee can move only one space per turn. Even though it is restricted in this way, if moved at the right time it can severely disrupt your opponent's plans.
[img]res://Testbed/queenbeemove.png[/img]
From this position, the black Queen Bee is able to move into one of four spaces."
fit_content = true
[node name="BeetleLabel" type="RichTextLabel" parent="Pivot/MarginContainer/PanelContainer/MarginContainer/VBoxContainer/HBoxContainer/VBoxContainer2/ScrollContainer/PanelContainer/MarginContainer"]
visible = false
layout_mode = 2
text = "The Beetle, like the Queen Bee, moves only one space per turn.
Unlike any other creature though, it can also move on top of the Hive.
A piece with a beetle on top of it is unable to move and for the purposes of the placing rules, the stack takes on the color of the Beetle.
From its position on top of the Hive, the Beetle can move from tile to tile across the top of the Hive. It can also drop into spaces that are surrounded and therefore not accessible to most other creatures.
From its position, the white Beetle is able to move into one of four positions.
The only way to block a Beetle that is on top of the Hive is to move another Beetle on top of it. All four Beetles can be stacked on top of each other.
Note: When it is first placed, the Beetle is placed in the same way as all other pieces. It can't be placed directly on top of the Hive, even though it can be moved there later."
fit_content = true
[node name="GrasshopperLabel" type="RichTextLabel" parent="Pivot/MarginContainer/PanelContainer/MarginContainer/VBoxContainer/HBoxContainer/VBoxContainer2/ScrollContainer/PanelContainer/MarginContainer"]
visible = false
layout_mode = 2
text = "The Grasshopper does not move around the outside of the Hive like the other creatures. Instead, it jumps from its space over any number of pieces (but at least one) to the next unoccupied space along a straight row of joined pieces.
This gives it the advantage of being able to fill in a space which is surrounded by other tiles.
From its position, the white Grasshopper can jump to one of three spaces. Note: It can't jump across the gap to the space marked x."
fit_content = true
[node name="SpiderLabel" type="RichTextLabel" parent="Pivot/MarginContainer/PanelContainer/MarginContainer/VBoxContainer/HBoxContainer/VBoxContainer2/ScrollContainer/PanelContainer/MarginContainer"]
visible = false
layout_mode = 2
text = "The Spider moves three spaces per turn - no more, no less.
It must move in a direct path and can't backtrack on itself. It may only move around pieces that it is in direct contact with on each step of its move and it may not move across to a piece that it's not in direct contact with.
From its position, the black Spider can move into one of four spaces but is unable to move to the position on its left marked 2 on its first step.
"
fit_content = true
[node name="AntLabel" type="RichTextLabel" parent="Pivot/MarginContainer/PanelContainer/MarginContainer/VBoxContainer/HBoxContainer/VBoxContainer2/ScrollContainer/PanelContainer/MarginContainer"]
visible = false
layout_mode = 2
text = "The Soldier Ant can move from its position to any other position around the Hive provided the restrictions are adhered to. This freedom of movement makes the Ant one of the most valuable pieces.
In this case, the Ant can be moved into one of eleven positions but is unable to move into the position in the center of the Hive.
"
fit_content = true
[node name="CloseButton" type="Button" parent="Pivot/MarginContainer/PanelContainer/MarginContainer/VBoxContainer"]
layout_mode = 2
text = "Close"
[connection signal="pressed" from="Pivot/MarginContainer/PanelContainer/MarginContainer/VBoxContainer/HBoxContainer/VBoxContainer/General" to="." method="_on_button_pressed" binds= [NodePath("../../VBoxContainer2/ScrollContainer/PanelContainer/MarginContainer/GeneralLabel"), "General"]]
[connection signal="pressed" from="Pivot/MarginContainer/PanelContainer/MarginContainer/VBoxContainer/HBoxContainer/VBoxContainer/Placing" to="." method="_on_button_pressed" binds= [NodePath("../../VBoxContainer2/ScrollContainer/PanelContainer/MarginContainer/PlacingLabel"), "Placing"]]
[connection signal="pressed" from="Pivot/MarginContainer/PanelContainer/MarginContainer/VBoxContainer/HBoxContainer/VBoxContainer/Moving" to="." method="_on_button_pressed" binds= [NodePath("../../VBoxContainer2/ScrollContainer/PanelContainer/MarginContainer/MovingLabel")]]
[connection signal="pressed" from="Pivot/MarginContainer/PanelContainer/MarginContainer/VBoxContainer/HBoxContainer/VBoxContainer/Bee" to="." method="_on_button_pressed" binds= [NodePath("../../VBoxContainer2/ScrollContainer/PanelContainer/MarginContainer/BeeLabel"), "Bee"]]
[connection signal="pressed" from="Pivot/MarginContainer/PanelContainer/MarginContainer/VBoxContainer/HBoxContainer/VBoxContainer/Beetle" to="." method="_on_button_pressed" binds= [NodePath("../../VBoxContainer2/ScrollContainer/PanelContainer/MarginContainer/BeetleLabel"), "Beetle"]]
[connection signal="pressed" from="Pivot/MarginContainer/PanelContainer/MarginContainer/VBoxContainer/HBoxContainer/VBoxContainer/Grasshopper" to="." method="_on_button_pressed" binds= [NodePath("../../VBoxContainer2/ScrollContainer/PanelContainer/MarginContainer/GrasshopperLabel"), "Grasshopper"]]
[connection signal="pressed" from="Pivot/MarginContainer/PanelContainer/MarginContainer/VBoxContainer/HBoxContainer/VBoxContainer/Spider" to="." method="_on_button_pressed" binds= [NodePath("../../VBoxContainer2/ScrollContainer/PanelContainer/MarginContainer/SpiderLabel"), "Spider"]]
[connection signal="pressed" from="Pivot/MarginContainer/PanelContainer/MarginContainer/VBoxContainer/HBoxContainer/VBoxContainer/Ant" to="." method="_on_button_pressed" binds= [NodePath("../../VBoxContainer2/ScrollContainer/PanelContainer/MarginContainer/AntLabel"), "Ant"]]
[connection signal="pressed" from="Pivot/MarginContainer/PanelContainer/MarginContainer/VBoxContainer/CloseButton" to="." method="_on_close_button_pressed"]

22
Testbed/Table.tres Normal file
View file

@ -0,0 +1,22 @@
[gd_resource type="ShaderMaterial" load_steps=5 format=3 uid="uid://dv2oo7hlc5nyy"]
[ext_resource type="Shader" path="res://Testbed/DistanceFaceWorld.gdshader" id="1_edhah"]
[ext_resource type="Texture2D" uid="uid://cilgpyanfb3a8" path="res://Testbed/textures/wood_table_001_diff_4k.jpg" id="2_hb1x7"]
[ext_resource type="Texture2D" uid="uid://diamo44e2x4if" path="res://Testbed/textures/wood_table_001_disp_4k.png" id="3_eyslc"]
[ext_resource type="Texture2D" uid="uid://b6ejmikbfrprs" path="res://Testbed/textures/wood_table_001_rough_4k.jpg" id="4_r705j"]
[resource]
render_priority = 0
shader = ExtResource("1_edhah")
shader_parameter/albedo = Color(1, 1, 1, 1)
shader_parameter/distance_fade_min = 0.0
shader_parameter/distance_fade_max = 0.0
shader_parameter/roughness = 0.5
shader_parameter/metallic_texture_channel = null
shader_parameter/specular = 0.5
shader_parameter/metallic = 0.5
shader_parameter/uv1_scale = Vector3(1, 1, 1)
shader_parameter/uv1_offset = Vector3(0, 0, 0)
shader_parameter/texture_albedo = ExtResource("2_hb1x7")
shader_parameter/texture_metallic = ExtResource("3_eyslc")
shader_parameter/texture_roughness = ExtResource("4_r705j")

9
Testbed/UIBlur.gdshader Normal file
View file

@ -0,0 +1,9 @@
shader_type canvas_item;
uniform float lod: hint_range(0.0, 5.0) = 0.0;
uniform sampler2D SCREEN_TEXTURE: hint_screen_texture, filter_linear_mipmap;
void fragment() {
vec4 color = texture(SCREEN_TEXTURE, SCREEN_UV, lod);
COLOR = vec4(color.rgb, 1.0);
}

BIN
Testbed/queenbeemove.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 98 KiB

View file

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://ce3vdaa8y4pmc"
path="res://.godot/imported/queenbeemove.png-5c1df16cbe3c407ebc595b848eeffac1.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://Testbed/queenbeemove.png"
dest_files=["res://.godot/imported/queenbeemove.png-5c1df16cbe3c407ebc595b848eeffac1.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