Skip to content

Commit

Permalink
Simplify map insertion into 'Match', closes #91
Browse files Browse the repository at this point in the history
  • Loading branch information
Scony committed Dec 13, 2023
1 parent 8b02cec commit 2525a13
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 153 deletions.
2 changes: 1 addition & 1 deletion source/main-menu/Loading.gd
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func _ready():
await get_tree().physics_frame
var a_match = match_prototype.instantiate()
a_match.settings = match_settings
a_match.map_to_plug = map
a_match.map = map
_progress_bar.value = 0.9

_label.text = tr("LOADING_STEP_STARTING_MATCH")
Expand Down
64 changes: 31 additions & 33 deletions source/match/Match.gd
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ const Drone = preload("res://source/match/units/Drone.tscn")
const Worker = preload("res://source/match/units/Worker.tscn")

@export var settings: Resource = null
@export var map_to_load_and_plug: PackedScene = null
@export var map_to_plug: Node = null

var map:
set = _set_map,
get = _get_map
var players = []
var controlled_player = null:
set = _set_controlled_player
Expand All @@ -25,7 +26,6 @@ var visible_players = null:
set = _ignore,
get = _get_visible_players

@onready var map = $Map
@onready var navigation = $Navigation
@onready var fog_of_war = $FogOfWar

Expand All @@ -35,9 +35,14 @@ var visible_players = null:
@onready var _terrain = $Terrain


func _enter_tree():
assert(settings != null, "match cannot start without settings, see examples in tests/manual/")
assert(map != null, "match cannot start without map, see examples in tests/manual/")


func _ready():
_try_setting_up_a_custom_map()
MatchSignals.setup_and_spawn_unit.connect(_setup_and_spawn_unit)
_setup_subsystems_dependent_on_map()
_create_players()
_choose_controlled_player()
visible_player = players[settings.visible_player]
Expand All @@ -55,14 +60,15 @@ func _unhandled_input(event):
MatchSignals.deselect_all_units.emit()


func _ignore(_value):
pass
func _set_map(a_map):
assert(get_node_or_null("Map") == null, "map already set")
a_map.name = "Map"
add_child(a_map)
a_map.owner = self


func _get_visible_players():
if settings.visibility == settings.Visibility.PER_PLAYER:
return [visible_player]
return players
func _get_map():
return get_node_or_null("Map")


func _set_controlled_player(player):
Expand Down Expand Up @@ -105,36 +111,28 @@ func _set_visible_player(player):
visible_player = player


func _try_setting_up_a_custom_map():
assert(
map_to_load_and_plug == null or map_to_plug == null,
"both 'map_to_load_and_plug' and 'map_to_plug' cannot be set at the same time"
)
if map_to_load_and_plug == null and map_to_plug == null:
return
var custom_map = map_to_plug if map_to_plug != null else map_to_load_and_plug.instantiate()
if custom_map != null:
_plug_custom_map(custom_map)
_terrain.update_shape(custom_map.find_child("Terrain").mesh)
fog_of_war.resize(custom_map.size)
_recalculate_camera_bounding_planes(custom_map.size)
navigation.rebake(custom_map)
func _ignore(_value):
pass


func _get_visible_players():
if settings.visibility == settings.Visibility.PER_PLAYER:
return [visible_player]
return players


func _setup_subsystems_dependent_on_map():
_terrain.update_shape(map.find_child("Terrain").mesh)
fog_of_war.resize(map.size)
_recalculate_camera_bounding_planes(map.size)
navigation.rebake(map)


func _recalculate_camera_bounding_planes(map_size: Vector2):
_camera.bounding_planes[1] = Plane(-1, 0, 0, -map_size.x)
_camera.bounding_planes[3] = Plane(0, 0, -1, -map_size.y)


func _plug_custom_map(custom_map):
map.name = map.name + "1"
map.add_sibling(custom_map)
remove_child(map)
map.queue_free()
map = custom_map
map.owner = self


func _create_players():
for player_settings in settings.players:
var player = Player.new()
Expand Down
58 changes: 1 addition & 57 deletions source/match/Match.tscn
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
[gd_scene load_steps=55 format=3 uid="uid://camns8fqod8d4"]
[gd_scene load_steps=44 format=3 uid="uid://camns8fqod8d4"]

[ext_resource type="Script" path="res://source/match/Match.gd" id="1_1555u"]
[ext_resource type="Script" path="res://source/match/IsometricCamera3D.gd" id="1_qb2ry"]
[ext_resource type="Script" path="res://source/data-model/PlayerSettings.gd" id="2_4dhvm"]
[ext_resource type="Script" path="res://source/data-model/MatchSettings.gd" id="3_wftgs"]
[ext_resource type="Script" path="res://source/match/FogOfWar.gd" id="5_eb52t"]
[ext_resource type="PackedScene" uid="uid://co800e4shs7bh" path="res://source/generic-scenes-and-nodes/3d/RectangularSelection3D.tscn" id="5_yi0pu"]
[ext_resource type="PackedScene" uid="uid://cbe63rdjw7y4p" path="res://source/match/maps/PlainAndSimple.tscn" id="6_au6gf"]
[ext_resource type="Material" uid="uid://co8vfcoqqs5i8" path="res://source/match/resources/materials/terrain.material.tres" id="6_u47mu"]
[ext_resource type="PackedScene" uid="uid://clbjgy724q2si" path="res://source/generic-scenes-and-nodes/2d/DynamicCircle2D.tscn" id="6_ux0ef"]
[ext_resource type="Script" path="res://source/match/Terrain.gd" id="7_ccpu4"]
[ext_resource type="Script" path="res://source/match/Navigation.gd" id="10_1wfp1"]
Expand All @@ -33,36 +29,6 @@
[ext_resource type="PackedScene" uid="uid://q5w474dvts3f" path="res://source/match/handlers/StructurePlacementHandler.tscn" id="26_7heso"]
[ext_resource type="PackedScene" uid="uid://b8p6lcwubx1tp" path="res://source/match/handlers/UnitVisibilityHandler.tscn" id="32_fci1c"]

[sub_resource type="Resource" id="Resource_hfc6q"]
script = ExtResource("2_4dhvm")
color = Color(0.4, 0.694118, 1, 1)
controller = 1
spawn_index = -1

[sub_resource type="Resource" id="Resource_6k4u7"]
script = ExtResource("2_4dhvm")
color = Color(1, 0.360784, 0.45098, 1)
controller = 2
spawn_index = -1

[sub_resource type="Resource" id="Resource_8ui6d"]
script = ExtResource("2_4dhvm")
color = Color(0.647059, 1, 0.6, 1)
controller = 2
spawn_index = -1

[sub_resource type="Resource" id="Resource_qphv2"]
script = ExtResource("2_4dhvm")
color = Color(0.929412, 0.521569, 1, 1)
controller = 2
spawn_index = -1

[sub_resource type="Resource" id="Resource_frabv"]
script = ExtResource("3_wftgs")
players = Array[Resource]([SubResource("Resource_hfc6q"), SubResource("Resource_6k4u7"), SubResource("Resource_8ui6d"), SubResource("Resource_qphv2")])
visibility = 1
visible_player = 0

[sub_resource type="ProceduralSkyMaterial" id="ProceduralSkyMaterial_ysb0j"]
sun_angle_max = 200.0

Expand All @@ -81,15 +47,6 @@ fog_density = 0.0016
fog_height = 0.25
fog_height_density = 1.2

[sub_resource type="PlaneMesh" id="PlaneMesh_fmyt8"]
resource_local_to_scene = true
material = ExtResource("6_u47mu")
size = Vector2(50, 50)
center_offset = Vector3(25, 0, 25)

[sub_resource type="ConcavePolygonShape3D" id="ConcavePolygonShape3D_3sb7f"]
data = PackedVector3Array(50, 0, 50, 0, 0, 50, 50, 0, 0, 0, 0, 50, 0, 0, 0, 50, 0, 0)

[sub_resource type="ShaderMaterial" id="ShaderMaterial_qw0ps"]
render_priority = 0
shader = ExtResource("10_weh6c")
Expand Down Expand Up @@ -130,8 +87,6 @@ size = Vector2(50, 50)
center_offset = Vector3(25, 0, 25)

[sub_resource type="NavigationMesh" id="NavigationMesh_8emvl"]
vertices = PackedVector3Array(0.8, 2.3, 0.8, 0.8, 2.3, 49.2, 49.2, 2.3, 49.2, 49.2, 2.3, 0.8)
polygons = [PackedInt32Array(3, 2, 0), PackedInt32Array(0, 2, 1)]
geometry_source_geometry_mode = 2
geometry_source_group_name = &"air_navigation_input"
cell_size = 0.4
Expand All @@ -141,8 +96,6 @@ agent_radius = 0.8
agent_max_climb = 0.0

[sub_resource type="NavigationMesh" id="NavigationMesh_exfwj"]
vertices = PackedVector3Array(1, 0.5, 1, 1, 0.5, 49, 49, 0.5, 49, 49, 0.5, 1)
polygons = [PackedInt32Array(3, 2, 0), PackedInt32Array(0, 2, 1)]
geometry_parsed_geometry_type = 2
geometry_collision_mask = 4278190082
geometry_source_geometry_mode = 2
Expand All @@ -164,7 +117,6 @@ viewport_path = NodePath("HUD/MarginContainer/Minimap/MarginContainer/MinimapVie

[node name="Match" type="Node3D"]
script = ExtResource("1_1555u")
settings = SubResource("Resource_frabv")

[node name="IsometricCamera3D" type="Camera3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 0.866025, 0.5, 0, -0.5, 0.866025, 49.5996, 12.4465, 65.9216)
Expand All @@ -190,17 +142,11 @@ environment = SubResource("Environment_qxcnu")

[node name="RectangularSelection3D" parent="." instance=ExtResource("5_yi0pu")]

[node name="Map" parent="." instance=ExtResource("6_au6gf")]

[node name="Terrain" parent="Map/Geometry" index="1"]
mesh = SubResource("PlaneMesh_fmyt8")

[node name="Terrain" type="StaticBody3D" parent="."]
collision_mask = 0
script = ExtResource("7_ccpu4")

[node name="CollisionShape3D" type="CollisionShape3D" parent="Terrain"]
shape = SubResource("ConcavePolygonShape3D_3sb7f")

[node name="Fog" type="MeshInstance3D" parent="."]
material_override = SubResource("ShaderMaterial_qw0ps")
Expand Down Expand Up @@ -476,5 +422,3 @@ rectangular_selection_3d = NodePath("../../RectangularSelection3D")
visible = false

[node name="UnitVisibilityHandler" parent="Handlers" instance=ExtResource("32_fci1c")]

[editable path="Map"]
15 changes: 3 additions & 12 deletions tests/manual/TestAllUnits.tscn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[gd_scene load_steps=25 format=3 uid="uid://b65yuqx0iw62f"]
[gd_scene load_steps=24 format=3 uid="uid://b65yuqx0iw62f"]

[ext_resource type="PackedScene" uid="uid://camns8fqod8d4" path="res://source/match/Match.tscn" id="1_oiu0k"]
[ext_resource type="Script" path="res://tests/manual/Match.gd" id="2_ghr3h"]
Expand All @@ -11,7 +11,7 @@
[ext_resource type="PackedScene" uid="uid://h5lqor1xl2sf" path="res://source/match/units/VehicleFactory.tscn" id="4_m1xri"]
[ext_resource type="Shader" path="res://source/shaders/3d/simple_fog_of_war.gdshader" id="5_f2ny6"]
[ext_resource type="PackedScene" uid="uid://b8pckq1xn44ss" path="res://source/match/units/AntiGroundTurret.tscn" id="5_g67iu"]
[ext_resource type="Material" uid="uid://co8vfcoqqs5i8" path="res://source/match/resources/materials/terrain.material.tres" id="5_ki5yw"]
[ext_resource type="PackedScene" uid="uid://cbe63rdjw7y4p" path="res://source/match/maps/PlainAndSimple.tscn" id="5_t3ibh"]
[ext_resource type="PackedScene" uid="uid://cfa8cpnpk5pcb" path="res://source/match/units/AntiAirTurret.tscn" id="6_lglnp"]
[ext_resource type="PackedScene" uid="uid://i58ffvwxbbwm" path="res://source/match/units/Tank.tscn" id="9_csgr3"]
[ext_resource type="PackedScene" uid="uid://bf0r3fovbvf1m" path="res://source/match/units/Worker.tscn" id="10_c3eov"]
Expand All @@ -29,12 +29,6 @@ players = Array[Resource]([SubResource("Resource_e1xtl")])
visibility = 1
visible_player = 0

[sub_resource type="PlaneMesh" id="PlaneMesh_yprsb"]
resource_local_to_scene = true
material = ExtResource("5_ki5yw")
size = Vector2(50, 50)
center_offset = Vector3(25, 0, 25)

[sub_resource type="ViewportTexture" id="ViewportTexture_v46ss"]
viewport_path = NodePath("FogOfWar/CombinedViewport")

Expand Down Expand Up @@ -63,8 +57,7 @@ script = ExtResource("2_ghr3h")
allow_resources_deficit_spending = true
settings = SubResource("Resource_rpdec")

[node name="Terrain" parent="Map/Geometry" index="1"]
mesh = SubResource("PlaneMesh_yprsb")
[node name="Map" parent="." index="0" instance=ExtResource("5_t3ibh")]

[node name="ScreenOverlay" parent="FogOfWar" index="1"]
material_override = SubResource("ShaderMaterial_67o07")
Expand Down Expand Up @@ -101,5 +94,3 @@ material = SubResource("ShaderMaterial_i0ai6")

[node name="MinimapTextureRect" parent="HUD/MarginContainer/Minimap/MarginContainer" index="1"]
texture = SubResource("ViewportTexture_ltqxy")

[editable path="Map"]
17 changes: 3 additions & 14 deletions tests/manual/TestNonQuadraticMap.tscn
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
[gd_scene load_steps=17 format=3 uid="uid://c54pjqg0defrj"]
[gd_scene load_steps=15 format=3 uid="uid://c54pjqg0defrj"]

[ext_resource type="PackedScene" uid="uid://camns8fqod8d4" path="res://source/match/Match.tscn" id="1_e8lxh"]
[ext_resource type="Script" path="res://tests/manual/Match.gd" id="2_2ib5j"]
[ext_resource type="Script" path="res://source/data-model/MatchSettings.gd" id="3_52248"]
[ext_resource type="PackedScene" uid="uid://d8wcem3ievht" path="res://tests/manual/maps/NonQuadratic.tscn" id="3_dldkj"]
[ext_resource type="Script" path="res://source/data-model/PlayerSettings.gd" id="3_eliam"]
[ext_resource type="Material" uid="uid://co8vfcoqqs5i8" path="res://source/match/resources/materials/terrain.material.tres" id="4_d4g7r"]
[ext_resource type="Shader" path="res://source/shaders/3d/simple_fog_of_war.gdshader" id="5_arsbx"]
[ext_resource type="PackedScene" uid="uid://d8wcem3ievht" path="res://tests/manual/maps/NonQuadratic.tscn" id="5_jtm1l"]
[ext_resource type="Shader" path="res://source/shaders/2d/white_transparent.gdshader" id="6_2nbfa"]

[sub_resource type="Resource" id="Resource_vkdak"]
Expand All @@ -21,12 +20,6 @@ players = Array[Resource]([SubResource("Resource_vkdak")])
visibility = 0
visible_player = 0

[sub_resource type="PlaneMesh" id="PlaneMesh_7oss6"]
resource_local_to_scene = true
material = ExtResource("4_d4g7r")
size = Vector2(50, 50)
center_offset = Vector3(25, 0, 25)

[sub_resource type="ViewportTexture" id="ViewportTexture_x0ak8"]
viewport_path = NodePath("FogOfWar/CombinedViewport")

Expand Down Expand Up @@ -54,10 +47,8 @@ viewport_path = NodePath("HUD/MarginContainer/Minimap/MarginContainer/MinimapVie
script = ExtResource("2_2ib5j")
allow_resources_deficit_spending = true
settings = SubResource("Resource_qgn77")
map_to_load_and_plug = ExtResource("3_dldkj")

[node name="Terrain" parent="Map/Geometry" index="1"]
mesh = SubResource("PlaneMesh_7oss6")
[node name="Map" parent="." index="0" instance=ExtResource("5_jtm1l")]

[node name="ScreenOverlay" parent="FogOfWar" index="1"]
material_override = SubResource("ShaderMaterial_g62le")
Expand All @@ -67,5 +58,3 @@ material = SubResource("ShaderMaterial_s3a4s")

[node name="MinimapTextureRect" parent="HUD/MarginContainer/Minimap/MarginContainer" index="1"]
texture = SubResource("ViewportTexture_un6ry")

[editable path="Map"]
15 changes: 3 additions & 12 deletions tests/manual/TestOneUnit.tscn
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
[gd_scene load_steps=17 format=3 uid="uid://qhgcfjxa2ykg"]
[gd_scene load_steps=16 format=3 uid="uid://qhgcfjxa2ykg"]

[ext_resource type="PackedScene" uid="uid://camns8fqod8d4" path="res://source/match/Match.tscn" id="1_fe2sx"]
[ext_resource type="Script" path="res://tests/manual/Match.gd" id="2_sflin"]
[ext_resource type="Script" path="res://source/data-model/PlayerSettings.gd" id="3_3drrn"]
[ext_resource type="Script" path="res://source/data-model/MatchSettings.gd" id="4_go41p"]
[ext_resource type="Material" uid="uid://co8vfcoqqs5i8" path="res://source/match/resources/materials/terrain.material.tres" id="5_x8bni"]
[ext_resource type="PackedScene" uid="uid://cbe63rdjw7y4p" path="res://source/match/maps/PlainAndSimple.tscn" id="5_pl4hu"]
[ext_resource type="Shader" path="res://source/shaders/2d/white_transparent.gdshader" id="8_fifyq"]
[ext_resource type="PackedScene" uid="uid://i58ffvwxbbwm" path="res://source/match/units/Tank.tscn" id="10_tqe5i"]
[ext_resource type="Shader" path="res://source/shaders/3d/simple_fog_of_war.gdshader" id="12_ke5ti"]
Expand All @@ -21,12 +21,6 @@ players = Array[Resource]([SubResource("Resource_aehri")])
visibility = 0
visible_player = 0

[sub_resource type="PlaneMesh" id="PlaneMesh_vk1ka"]
resource_local_to_scene = true
material = ExtResource("5_x8bni")
size = Vector2(50, 50)
center_offset = Vector3(25, 0, 25)

[sub_resource type="ViewportTexture" id="ViewportTexture_v46ss"]
viewport_path = NodePath("FogOfWar/CombinedViewport")

Expand Down Expand Up @@ -55,8 +49,7 @@ script = ExtResource("2_sflin")
allow_resources_deficit_spending = true
settings = SubResource("Resource_qqc8i")

[node name="Terrain" parent="Map/Geometry" index="1"]
mesh = SubResource("PlaneMesh_vk1ka")
[node name="Map" parent="." index="0" instance=ExtResource("5_pl4hu")]

[node name="ScreenOverlay" parent="FogOfWar" index="1"]
material_override = SubResource("ShaderMaterial_67o07")
Expand All @@ -69,5 +62,3 @@ material = SubResource("ShaderMaterial_kdlxq")

[node name="MinimapTextureRect" parent="HUD/MarginContainer/Minimap/MarginContainer" index="1"]
texture = SubResource("ViewportTexture_n2lq6")

[editable path="Map"]
Loading

0 comments on commit 2525a13

Please sign in to comment.