connections

This commit is contained in:
2026-05-20 16:34:39 +02:00
parent 70bba45b8a
commit 661e62e8b8
35 changed files with 1039 additions and 258 deletions

6
Autoloads.cs Normal file
View File

@@ -0,0 +1,6 @@
using Godot;
namespace NodeWar;
[Autoload]
public partial class Autoloads { }

1
Autoloads.cs.uid Normal file
View File

@@ -0,0 +1 @@
uid://djrh33q80nek

66
BuildManager.cs Normal file
View File

@@ -0,0 +1,66 @@
using System.Collections.Generic;
using Godot;
namespace NodeWar;
public partial class BuildManager : Node
{
public bool Building { get; set; } = false;
public Nodule BuildingNodule { get; set; }
public override void _Ready() { }
[Export]
private PackedScene _noduleScene;
[Export]
private PackedScene _rootScene;
private Dictionary<NoduleConnection, Root> NoduleConnections { get; set; } = new();
public override void _Process(double delta)
{
if (Input.IsActionJustPressed("build") && !Building)
{
Building = true;
BuildingNodule = _noduleScene.Instantiate<Nodule>();
BuildingNodule.BuildMode = true;
BuildingNodule.NoduleBuilt += () =>
{
Building = false;
// try connecting built nodule to connected ones
foreach (var connectedNodule in BuildingNodule.ConnectedNodules)
{
RegisterConnection(BuildingNodule, connectedNodule);
}
BuildingNodule = null;
};
BuildingNodule.BuildingCanceled += () =>
{
Building = false;
BuildingNodule = null;
};
GetParent().AddChild(BuildingNodule);
}
}
public void RegisterConnection(Nodule a, Nodule b)
{
if (!NoduleConnections.ContainsKey(new NoduleConnection { A = a, B = b }))
{
var root = _rootScene.Instantiate<Root>();
GetParent().AddChild(root);
root.ConnectNodules(a, b);
root.GlobalPosition = a.GlobalPosition;
NoduleConnections.Add(new NoduleConnection { A = a, B = b }, root);
}
}
}

1
BuildManager.cs.uid Normal file
View File

@@ -0,0 +1 @@
uid://c2ufhsf60fl83

6
Gui.cs
View File

@@ -1,13 +1,13 @@
using Godot; using Godot;
using NodeWar.scripts; using NodeWar;
public partial class Gui : Control public partial class Gui : Control
{ {
private Label _infoLabel; private Label _infoLabel;
public override void _Ready() public override void _Ready()
{ {
_infoLabel = GetNode<Label>("%InfoLabel"); _infoLabel = GetNode<Label>("%InfoLabel");
EventBus.Instance.SelectionChanged += text => _infoLabel.Text = text; Autoloads.EventBus.SelectionChanged += text => _infoLabel.Text = text;
} }
} }

View File

@@ -1,8 +1,18 @@
<Project Sdk="Godot.NET.Sdk/4.6.2"> <Project Sdk="Godot.NET.Sdk/4.6.2">
<PropertyGroup> <PropertyGroup>
<TargetFramework>net8.0</TargetFramework> <TargetFramework>net10.0</TargetFramework>
<TargetFramework Condition=" '$(GodotTargetPlatform)' == 'android' ">net9.0</TargetFramework> <TargetFramework Condition=" '$(GodotTargetPlatform)' == 'android' "
<EnableDynamicLoading>true</EnableDynamicLoading> >net9.0</TargetFramework
<RootNamespace>NodeWar</RootNamespace> >
</PropertyGroup> <EnableDynamicLoading>true</EnableDynamicLoading>
</Project> <RootNamespace>NodeWar</RootNamespace>
<LangVersion>14</LangVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Firebelley.GodotUtilities" Version="6.2.0" />
<PackageReference
Include="GodotSharp.SourceGenerators"
Version="2.7.0-260519-1042.Release"
/>
</ItemGroup>
</Project>

139
Nodule.cs Normal file
View File

@@ -0,0 +1,139 @@
using System;
using System.Collections.Generic;
using Godot;
using NodeWar.scripts;
namespace NodeWar;
public partial class Nodule : Area2D
{
private const float GrowthFactor = 0.01f;
[Export]
public float Radius { get; set; } = 120;
[Export]
public float MaxRadius { get; set; } = 360;
[Export]
public CollisionShape2D Collision { get; set; }
[Export]
public bool BuildMode { get; set; } = false;
[Export]
public float Age { get; set; } = 0;
[Export]
public PackedScene RootScene { get; set; }
public List<Nodule> ConnectedNodules { get; set; } = [];
[Signal]
public delegate void NoduleBuiltEventHandler();
[Signal]
public delegate void BuildingCanceledEventHandler();
public override void _Ready()
{
Radius = Age * MaxRadius;
AreaEntered += OnAreaEntered;
AreaExited += OnAreaExited;
QueueRedraw();
}
private void OnAreaEntered(Area2D area)
{
if (area is Nodule nodule)
{
if (nodule.BuildMode)
{
return;
}
ConnectedNodules.Add(nodule);
}
}
private void OnAreaExited(Area2D area)
{
if (area is Nodule nodule)
{
if (nodule.BuildMode)
{
return;
}
ConnectedNodules.Remove(nodule);
}
}
public override void _Process(double delta)
{
if (BuildMode)
{
GlobalPosition = GetGlobalMousePosition();
if (Input.IsMouseButtonPressed(MouseButton.Left))
{
EmitSignalNoduleBuilt();
BuildMode = false;
MouseEntered += OnMouseEntered;
}
if (Input.IsMouseButtonPressed(MouseButton.Right))
{
EmitSignalBuildingCanceled();
BuildMode = false;
QueueFree();
}
}
else
{
Age += GrowthFactor * delta.ToFloat();
Age = MathF.Min(Age, 1);
Radius = Age * MaxRadius;
QueueRedraw();
}
// TODO: replace with line2d?
QueueRedraw();
}
private void OnMouseEntered()
{
GD.Print("Mouse entered");
}
public override void _Draw()
{
foreach (var nodule in ConnectedNodules)
{
if (BuildMode)
{
DrawDashedLine(
Vector2.Zero,
nodule.GlobalPosition - GlobalPosition,
Colors.White,
2f,
dash: 4f,
antialiased: true
);
}
}
if (BuildMode)
{
DrawCircle(Vector2.Zero, Radius, new Color(Colors.DarkOliveGreen, 0.2f));
}
else
{
DrawCircle(Vector2.Zero, Radius, new Color(Colors.WhiteSmoke, 0.4f));
}
}
}

1
Nodule.cs.uid Normal file
View File

@@ -0,0 +1 @@
uid://7em4o0ud8sgj

19
NoduleConnection.cs Normal file
View File

@@ -0,0 +1,19 @@
using System;
namespace NodeWar;
public class NoduleConnection
{
public Nodule A { get; set; }
public Nodule B { get; set; }
protected bool Equals(NoduleConnection other)
{
return Equals(A, other.A) && Equals(B, other.B);
}
public override int GetHashCode()
{
return HashCode.Combine(A, B);
}
}

1
NoduleConnection.cs.uid Normal file
View File

@@ -0,0 +1 @@
uid://c04vh06mc1yms

30
Root.cs Normal file
View File

@@ -0,0 +1,30 @@
using Godot;
using GodotUtilities;
namespace NodeWar;
[Scene]
public partial class Root : Node2D
{
[Node]
private Line2D line2D;
public override void _Ready()
{
GD.Print(line2D);
}
public void ConnectNodules(Nodule a, Nodule b)
{
GlobalPosition = a.GlobalPosition;
line2D.Points = [Vector2.Zero, b.GlobalPosition - a.GlobalPosition];
}
public override void _Notification(int what)
{
if (what == NotificationSceneInstantiated)
{
WireNodes();
}
}
}

1
Root.cs.uid Normal file
View File

@@ -0,0 +1 @@
uid://but18j8vnbom4

View File

@@ -1344,5 +1344,3 @@ static func set_ellipse_points(curve : Curve2D, size: Vector2, offset := Vector2
) )
curve.set_block_signals(false) curve.set_block_signals(false)
curve.changed.emit() curve.changed.emit()

View File

@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Made by Claudio Z. 2024 (cloudofoz) -->
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
viewBox="0 0 16 16" style="enable-background:new 0 0 16 16;" xml:space="preserve">
<style type="text/css">
.st0{fill:#8DA5F3;}
</style>
<g>
<g>
<path class="st0" d="M2.9,1.2c1.9,0,3.8,0,5.7,0.3c1,0.1,1.9,0.3,3,0.7c0.5,0.2,1,0.4,1.7,1c0.3,0.3,0.7,0.8,0.6,1.6
c-0.1,0.8-0.6,1.1-0.9,1.4l0,0c-0.1,0.1-0.2,0.1-0.3,0.2C11,6.8,9.4,7.4,8,8.1c-1.5,0.7-2.9,1.6-3.8,2.7c-0.2,0.3-0.4,0.6-0.5,0.9
c0,0.1-0.1,0.3-0.1,0.4l0,0c0,0,0-0.1,0-0.1c0-0.1,0-0.1-0.1-0.2c0-0.1-0.1-0.1-0.1-0.1c0,0,0,0,0.1,0.1C4,12,4.9,12.1,5.7,12.1
c1.6,0.1,3.3-0.1,5-0.4c0.3-0.1,0.6,0.1,0.6,0.4c0.1,0.3-0.1,0.5-0.4,0.6c-1.7,0.5-3.4,0.8-5.2,0.8c-0.9,0-1.8,0-2.8-0.3
c-0.1,0-0.3-0.1-0.5-0.2c-0.1-0.1-0.2-0.1-0.3-0.3C2,12.6,2,12.5,2,12.4c0-0.1,0-0.1,0-0.2l0-0.1c0-0.4,0.1-0.6,0.1-0.9
c0.2-0.5,0.4-1,0.7-1.4C3.9,8.2,5.5,7.2,7,6.3c1.6-0.9,3.2-1.6,4.8-2.3l-0.3,0.2c0,0-0.1,0-0.1,0.3c0,0.3,0.1,0.4,0.1,0.4
c-0.1-0.1-0.4-0.2-0.8-0.3C10,4.4,9.1,4.2,8.3,4.2C6.5,4.1,4.8,4.1,3,4.2l0,0C2.1,4.3,1.4,3.7,1.4,2.9C1.3,2,1.9,1.3,2.9,1.2
C2.8,1.3,2.8,1.2,2.9,1.2z"/>
<g>
<polygon class="st0" points="11,15.4 15,10.5 8.8,9.5 "/>
</g>
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 1.3 KiB

View File

@@ -0,0 +1,43 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://c0qiq6063dp2k"
path="res://.godot/imported/icon.svg-b9b36016f8243188eed518770c277664.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://addons/linepath2d/icon.svg"
dest_files=["res://.godot/imported/icon.svg-b9b36016f8243188eed518770c277664.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/uastc_level=0
compress/rdo_quality_loss=0.0
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/channel_remap/red=0
process/channel_remap/green=1
process/channel_remap/blue=2
process/channel_remap/alpha=3
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
svg/scale=1.0
editor/scale_with_editor_scale=false
editor/convert_colors_with_editor_theme=false

View File

@@ -0,0 +1,248 @@
# Copyright (C) 2024 Claudio Z. (cloudofoz)
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
@tool
extends Path2D
#---------------------------------------------------------------------------------------------------
# CONSTANTS
#---------------------------------------------------------------------------------------------------
# Enable the creation of a default curve when this class is instantiated
const LP_CREATE_DEFAULT_CURVE = true
# Enable the creation of a default curve width profile when this class is instatiated
const LP_CREATE_DEFAULT_PROFILE = true
# Size in pixels of the default curve
const LP_DEFAULT_CURVE_SIZE = 400
# Size in pixels of the default curve width
const LP_DEFAULT_CURVE_WIDTH = 25
#---------------------------------------------------------------------------------------------------
# PRIVATE VARIABLES
#---------------------------------------------------------------------------------------------------
var lp_line: Line2D = null
#---------------------------------------------------------------------------------------------------
# PUBLIC VARIABLES
#---------------------------------------------------------------------------------------------------
@export_category("LinePath2D")
## Sets the Path2D 'Curve2D' resource
##
## Note: Please, use this variable to change the curve and not the original Path2D property
## Reason: It's not currently possible to override the parent setter:
## 'Path2D.set_curve(value)'.
## Reference: https://github.com/godotengine/godot-proposals/issues/8045
@export var _curve: Curve2D = null:
set(value):
if(curve && curve.changed.is_connected(lp_build_line)):
curve.changed.disconnect(lp_build_line)
curve = value
if(curve):
curve.changed.connect(lp_build_line)
lp_build_line()
get:
return curve
## Sets the width of the curve
@export var width: float = LP_DEFAULT_CURVE_WIDTH:
set(value):
if(!lp_line): return
lp_line.width = value
#lp_line.draw.emit()
get:
return lp_line.width if lp_line else LP_DEFAULT_CURVE_WIDTH
## Use this [Curve] to modify the line width profile
@export var width_profile: Curve:
set(value):
if(!lp_line): return
lp_line.width_curve = value
#lp_line.draw.emit()
get:
return lp_line.width_curve if lp_line else null
@export_group("Fill", "fill_")
## Default path color
@export var fill_default_color: Color = Color.WHITE:
set(value):
if(lp_line): lp_line.default_color = value
get:
return lp_line.default_color if lp_line else Color.WHITE
## Fill the path with a gradient
@export var fill_gradient: Gradient = null:
set(value):
if(lp_line): lp_line.gradient = value
get:
return lp_line.gradient if lp_line else null
## Fill the path with a texture
@export var fill_texture: Texture2D = null:
set(value):
if(lp_line): lp_line.texture = value
get:
return lp_line.texture if lp_line else null
## Change the texture fill mode
@export_enum("None: 0", "Tile: 1", "Stretch: 2")
var fill_texture_mode: int = Line2D.LINE_TEXTURE_NONE:
set(value):
if(lp_line): lp_line.texture_mode = value
get:
return lp_line.texture_mode if lp_line else Line2D.LINE_TEXTURE_NONE
## Sets the material (CanvasMaterial2D or ShaderMaterial)
#@export var fill_material: Material = null:
#set(value):
#if(!lp_line): return
#if(!(value is CanvasItemMaterial) && !(value is ShaderMaterial)):
#lp_line.material = null
#return
#lp_line.material = value
#get:
#return lp_line.material if lp_line else null
@export_group("Capping", "cap_")
## The style of connection between segments of the polyline
@export_enum("Sharp: 0", "Bevel: 1", "Round: 2")
var cap_joint_mode: int = Line2D.LINE_JOINT_SHARP:
set(value):
if(lp_line): lp_line.joint_mode = value
get:
return lp_line.joint_mode if lp_line else 0
## The style of the beginning of the polyline
@export_enum("None: 0", "Box: 1", "Round: 1")
var cap_begin_cap: int = Line2D.LINE_CAP_NONE:
set(value):
if(lp_line): lp_line.begin_cap_mode = value
get:
return lp_line.begin_cap_mode if lp_line else Line2D.LINE_CAP_NONE
## The style of the ending of the polyline
@export_enum("None: 0", "Box: 1", "Round: 1")
var cap_end_cap: int = Line2D.LINE_CAP_NONE:
set(value):
if(lp_line): lp_line.end_cap_mode = value
get:
return lp_line.end_cap_mode if lp_line else Line2D.LINE_CAP_NONE
## If true and the polyline has more than two segments,
## the first and the last point will be connected by a segment
@export var cap_close_curve: bool = false:
set(value):
if(lp_line): lp_line.closed = value
get:
return lp_line.closed if lp_line else false
@export_group("Border", "border_")
## Determines the miter limit of the polyline
@export var border_sharp_limit: float = 2.0:
set(value):
if(lp_line): lp_line.sharp_limit = value
get:
return lp_line.sharp_limit if lp_line else 2.0
## The smoothness of the rounded joints and caps
@export var border_round_precision: int = 8:
set(value):
if(lp_line): lp_line.round_precision = value
get:
return lp_line.round_precision if lp_line else 8
## If true the polyline border will be antialiased
## Note: Antialiased polylines are not accelerated by batching
@export var border_antialiased: bool = false:
set(value):
if(lp_line): lp_line.antialiased = value
get:
return lp_line.antialiased if lp_line else false
#---------------------------------------------------------------------------------------------------
# VIRTUAL METHODS
#---------------------------------------------------------------------------------------------------
func _init() -> void:
if(!lp_line):
lp_line = Line2D.new()
func _ready() -> void:
lp_clear_duplicated_internal_children()
lp_line.set_meta("__lp2d_internal__", true)
add_child(lp_line)
if(!curve || curve.point_count < 2):
curve = lp_create_default_curve(LP_DEFAULT_CURVE_SIZE)
if(!lp_line.width_curve):
lp_line.width_curve = lp_create_default_profile(LP_DEFAULT_CURVE_WIDTH)
lp_build_line()
if(curve && !curve.changed.is_connected(lp_build_line)):
curve.changed.connect(lp_build_line)
#---------------------------------------------------------------------------------------------------
# PRIVATE METHODS
#---------------------------------------------------------------------------------------------------
func lp_create_default_curve(size:int) -> Curve2D:
if(!LP_CREATE_DEFAULT_CURVE): return null
var c = Curve2D.new()
c.add_point(Vector2.ZERO, Vector2.ZERO, Vector2(size,0))
c.add_point(Vector2(size,size), Vector2(-size,0), Vector2.ZERO)
return c
func lp_create_default_profile(size:float) -> Curve:
if(!LP_CREATE_DEFAULT_PROFILE): return null
var c = Curve.new()
c.add_point(Vector2.ZERO)
c.add_point(Vector2(0.5,1))
c.add_point(Vector2(1.0, 0))
return c
func lp_build_line() -> void:
if(!lp_line):
return
if(!curve || curve.point_count < 2):
lp_line.clear_points()
return
lp_line.points = curve.get_baked_points()
func lp_clear_duplicated_internal_children():
for c in get_children():
if(c.get_meta("__lp2d_internal__", false)):
c.queue_free()
#---------------------------------------------------------------------------------------------------
# KNOWN BUGS/LIMITATIONS:
#
# *) Changing the 'Path2D.curve' in the editor will result in an unexpected behaviour
# TO-FIX: Overriding the default setter 'Path2D.set_curve(value)', it's not currently possible.
# PROPOSAL: https://github.com/godotengine/godot-proposals/issues/8045

View File

@@ -0,0 +1 @@
uid://b7ni0w4diekq4

View File

@@ -0,0 +1,7 @@
[plugin]
name="LinePath2D"
description="This simple Godot addon brings the 'Line2D' drawing capabilities to 'Path2D' curves."
author="cloudofoz"
version="0.10"
script="plugin.gd"

View File

@@ -0,0 +1,31 @@
# Copyright (C) 2024 Claudio Z. (cloudofoz)
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
@tool
extends EditorPlugin
func _enter_tree() -> void:
## This simple addon brings the 'Line2D' drawing capabilities to 'Path2D' curves.
add_custom_type("LinePath2D", "Path2D", preload("linepath2d.gd"), preload("icon.svg"))
func _exit_tree() -> void:
remove_custom_type("LinePath2D")

View File

@@ -0,0 +1 @@
uid://or7xl32s36qq

View File

@@ -1,98 +0,0 @@
[gd_scene format=3 uid="uid://dxfhhf4qu42bb"]
[ext_resource type="Script" uid="uid://demgvopfvjmql" path="res://scripts/Base.cs" id="1_21bcp"]
[ext_resource type="Texture2D" uid="uid://du7ejwu1yo0j1" path="res://assets/icon.svg" id="1_rpg24"]
[ext_resource type="PackedScene" uid="uid://c2blpf56yvidh" path="res://scripts/components/SpawnerComponent.tscn" id="2_42dj3"]
[ext_resource type="Script" uid="uid://de3jpss66xjfh" path="res://addons/curved_lines_2d/scalable_vector_shape_2d.gd" id="3_21bcp"]
[ext_resource type="Script" uid="uid://dlbv4pit17dnu" path="res://addons/curved_lines_2d/scalable_arc.gd" id="4_tpea4"]
[ext_resource type="Script" uid="uid://dl1t88tthmwts" path="res://addons/curved_lines_2d/scalable_arc_list.gd" id="5_42dj3"]
[ext_resource type="PackedScene" uid="uid://dn6jqa3wj40ir" path="res://scripts/components/health_component.tscn" id="6_tpea4"]
[ext_resource type="PackedScene" uid="uid://c24a65g4ixikh" path="res://scheppes_x.tscn" id="8_56f15"]
[sub_resource type="Curve2D" id="Curve2D_56f15"]
resource_local_to_scene = true
_data = {
"points": PackedVector2Array(0, 0, 0, 56.282383, 101.90546, 0, 56.282383, 0, -56.282383, 0, 0, 101.90546, 0, 56.282383, 0, -56.282383, -101.90546, 0, -56.282383, 0, 56.282383, 0, 0, -101.90546, 0, -56.282383, 0, 0, 101.90546, 0)
}
point_count = 5
[sub_resource type="Resource" id="Resource_cho24"]
resource_local_to_scene = true
script = ExtResource("5_42dj3")
[sub_resource type="Curve2D" id="Curve2D_cho24"]
resource_local_to_scene = true
_data = {
"points": PackedVector2Array(0, 0, 0, 0, 39.776398, -42.15619, 0, 0, 0, 0, -45.14743, 49.220245, 0, 0, 0, 0, -2.6800537, 3.5144196, 0, 0, 0, 0, -45.14743, -41.986115, 0, 0, 0, 0, 40.02704, 49.35132)
}
point_count = 5
[sub_resource type="Resource" id="Resource_dlkme"]
resource_local_to_scene = true
script = ExtResource("5_42dj3")
[sub_resource type="LabelSettings" id="LabelSettings_rpg24"]
font_size = 33
outline_size = 8
outline_color = Color(0, 0, 0, 1)
[node name="Base" type="Area2D" unique_id=1354578205 node_paths=PackedStringArray("Target", "HealthComponent", "SpawnerComponent")]
script = ExtResource("1_21bcp")
Target = NodePath("Selection/Target")
HealthComponent = NodePath("HealthComponent")
SpawnerComponent = NodePath("SpawnerComponent")
[node name="SpawnerComponent" parent="." unique_id=1304757964 instance=ExtResource("2_42dj3")]
[node name="HealthComponent" parent="." unique_id=1360050278 instance=ExtResource("6_tpea4")]
offset_left = -99.0
offset_right = -72.0
[node name="CollisionPolygon2D" type="CollisionPolygon2D" parent="." unique_id=1632145743]
polygon = PackedVector2Array(59.1, -64, -59, -64, -63.8, -59, -64, 61, -60.3, 64, 59.6, 64, 63.9, 59, 64, -61.1)
[node name="Selection" type="Node2D" parent="." unique_id=544477539 node_paths=PackedStringArray("line")]
visible = false
script = ExtResource("3_21bcp")
stroke_color = Color(0.36841604, 0.683675, 0.26152232, 1)
stroke_width = 4.0
line = NodePath("Stroke")
curve = SubResource("Curve2D_56f15")
update_curve_at_runtime = true
arc_list = SubResource("Resource_cho24")
shape_type = 2
size = Vector2(203.81091, 203.81091)
rx = 101.90546
ry = 101.90546
[node name="Stroke" type="Line2D" parent="Selection" unique_id=1625752545]
points = PackedVector2Array(101.90546, 0, 101.37935, 10.4194975, 99.83516, 20.537949, 97.32412, 30.304142, 93.89744, 39.66686, 89.60633, 48.574883, 84.50201, 56.976994, 78.635704, 64.821976, 72.058624, 72.058624, 64.821976, 78.63571, 56.97699, 84.502014, 48.574883, 89.60633, 39.666855, 93.89744, 30.304142, 97.32412, 20.537949, 99.83516, 10.419497, 101.37935, 0, 101.90546, -10.4194975, 101.37935, -20.537949, 99.83516, -30.304142, 97.32412, -39.66686, 93.89744, -48.574883, 89.60633, -56.976994, 84.50201, -64.821976, 78.635704, -72.058624, 72.058624, -78.63571, 64.821976, -84.502014, 56.97699, -89.60633, 48.574883, -93.89744, 39.666855, -97.32412, 30.304142, -99.83516, 20.537949, -101.37935, 10.419497, -101.90546, 0, -101.37935, -10.4194975, -99.83516, -20.537949, -97.32412, -30.304142, -93.89744, -39.66686, -89.60633, -48.574883, -84.50201, -56.976994, -78.635704, -64.821976, -72.058624, -72.058624, -64.821976, -78.63571, -56.97699, -84.502014, -48.574883, -89.60633, -39.666855, -93.89744, -30.304142, -97.32412, -20.537949, -99.83516, -10.419497, -101.37935, 0, -101.90546, 10.4194975, -101.37935, 20.537949, -99.83516, 30.304142, -97.32412, 39.66686, -93.89744, 48.574883, -89.60633, 56.976994, -84.50201, 64.821976, -78.635704, 72.058624, -72.058624, 78.63571, -64.821976, 84.502014, -56.97699, 89.60633, -48.574883, 93.89744, -39.666855, 97.32412, -30.304142, 99.83516, -20.537949, 101.37935, -10.419497)
closed = true
width = 4.0
default_color = Color(0.36841604, 0.683675, 0.26152232, 1)
sharp_limit = 90.0
antialiased = true
metadata/_edit_lock_ = true
[node name="Target" parent="Selection" unique_id=868654776 instance=ExtResource("8_56f15")]
curve = SubResource("Curve2D_cho24")
arc_list = SubResource("Resource_dlkme")
[node name="Gfx" type="Sprite2D" parent="." unique_id=1646140640]
texture = ExtResource("1_rpg24")
[node name="Label" type="Label" parent="." unique_id=1802037971]
visible = false
anchors_preset = 5
anchor_left = 0.5
anchor_right = 0.5
offset_left = -38.0
offset_top = 65.885
offset_right = 38.0
offset_bottom = 111.88508
grow_horizontal = 2
text = "Base"
label_settings = SubResource("LabelSettings_rpg24")
[connection signal="mouse_entered" from="." to="." method="_on_mouse_entered"]
[connection signal="mouse_exited" from="." to="." method="_on_mouse_exited"]

View File

@@ -1,13 +1,13 @@
[gd_scene format=3 uid="uid://bf7croj2rk4q6"] [gd_scene format=3 uid="uid://bf7croj2rk4q6"]
[ext_resource type="Script" uid="uid://rirna2vebukw" path="res://addons/strategy_cam/strategy_camera.gd" id="2_0xm2m"] [ext_resource type="Script" uid="uid://rirna2vebukw" path="res://addons/strategy_cam/strategy_camera.gd" id="2_0xm2m"]
[ext_resource type="PackedScene" uid="uid://dxfhhf4qu42bb" path="res://base.tscn" id="2_h2yge"] [ext_resource type="Script" uid="uid://c2ufhsf60fl83" path="res://BuildManager.cs" id="2_5vw27"]
[ext_resource type="Script" uid="uid://de3jpss66xjfh" path="res://addons/curved_lines_2d/scalable_vector_shape_2d.gd" id="3_lquwl"] [ext_resource type="Script" uid="uid://de3jpss66xjfh" path="res://addons/curved_lines_2d/scalable_vector_shape_2d.gd" id="3_lquwl"]
[ext_resource type="Script" uid="uid://bibq3e4nkwiwv" path="res://scripts/EventBus.cs" id="4_5vw27"]
[ext_resource type="Script" uid="uid://dlbv4pit17dnu" path="res://addons/curved_lines_2d/scalable_arc.gd" id="4_7mycd"] [ext_resource type="Script" uid="uid://dlbv4pit17dnu" path="res://addons/curved_lines_2d/scalable_arc.gd" id="4_7mycd"]
[ext_resource type="PackedScene" uid="uid://b1a13w4ckxnub" path="res://gui.tscn" id="4_272bh"] [ext_resource type="PackedScene" uid="uid://b1a13w4ckxnub" path="res://gui.tscn" id="4_272bh"]
[ext_resource type="PackedScene" uid="uid://cd47em5shcnid" path="res://root.tscn" id="4_kek77"]
[ext_resource type="Script" uid="uid://dl1t88tthmwts" path="res://addons/curved_lines_2d/scalable_arc_list.gd" id="5_272bh"] [ext_resource type="Script" uid="uid://dl1t88tthmwts" path="res://addons/curved_lines_2d/scalable_arc_list.gd" id="5_272bh"]
[ext_resource type="PackedScene" uid="uid://4b8osd3h3xbm" path="res://pip.tscn" id="6_7mycd"] [ext_resource type="PackedScene" uid="uid://cb07jvtr8x7i1" path="res://nodule.tscn" id="8_5vw27"]
[sub_resource type="Curve2D" id="Curve2D_5vw27"] [sub_resource type="Curve2D" id="Curve2D_5vw27"]
resource_local_to_scene = true resource_local_to_scene = true
@@ -22,8 +22,10 @@ script = ExtResource("5_272bh")
[node name="Main" type="Node2D" unique_id=866253780] [node name="Main" type="Node2D" unique_id=866253780]
[node name="EventBus" type="Node" parent="." unique_id=239508674] [node name="BuildManager" type="Node" parent="." unique_id=288291270]
script = ExtResource("4_5vw27") script = ExtResource("2_5vw27")
_noduleScene = ExtResource("8_5vw27")
_rootScene = ExtResource("4_kek77")
[node name="CanvasLayer" type="CanvasLayer" parent="." unique_id=1010925224] [node name="CanvasLayer" type="CanvasLayer" parent="." unique_id=1010925224]
@@ -60,20 +62,4 @@ script = ExtResource("2_0xm2m")
translation_speed = 300.0 translation_speed = 300.0
metadata/_custom_type_script = "uid://rirna2vebukw" metadata/_custom_type_script = "uid://rirna2vebukw"
[node name="PlayerBase" parent="." unique_id=1646140640 instance=ExtResource("2_h2yge")] [node name="Nodule" parent="." unique_id=698496795 instance=ExtResource("8_5vw27")]
position = Vector2(-680, -353)
Faction = 1
[node name="NeutralBase" parent="." unique_id=1354578205 instance=ExtResource("2_h2yge")]
position = Vector2(365, -382)
[node name="NeutralBase2" parent="." unique_id=98685585 instance=ExtResource("2_h2yge")]
position = Vector2(-189, 396)
[node name="EnemyBase" parent="." unique_id=2059599822 groups=["enemyBase"] instance=ExtResource("2_h2yge")]
position = Vector2(707, 439)
Faction = 2
[node name="Pip" parent="." unique_id=1889156888 node_paths=PackedStringArray("Target") instance=ExtResource("6_7mycd")]
position = Vector2(-7, -14)
Target = NodePath("../EnemyBase")

58
nodule.tscn Normal file
View File

@@ -0,0 +1,58 @@
[gd_scene format=3 uid="uid://cb07jvtr8x7i1"]
[ext_resource type="Script" uid="uid://7em4o0ud8sgj" path="res://Nodule.cs" id="1_beybw"]
[ext_resource type="Script" uid="uid://de3jpss66xjfh" path="res://addons/curved_lines_2d/scalable_vector_shape_2d.gd" id="2_cahmm"]
[ext_resource type="Script" uid="uid://dlbv4pit17dnu" path="res://addons/curved_lines_2d/scalable_arc.gd" id="3_fnyqb"]
[ext_resource type="Script" uid="uid://dl1t88tthmwts" path="res://addons/curved_lines_2d/scalable_arc_list.gd" id="4_qiyup"]
[sub_resource type="CircleShape2D" id="CircleShape2D_7mycd"]
resource_local_to_scene = true
radius = 200.0
[sub_resource type="Curve2D" id="Curve2D_272bh"]
resource_local_to_scene = true
_data = {
"points": PackedVector2Array(0, 0, 0, 5.523, 10, 0, 5.523, 0, -5.523, 0, 0, 10, 0, 5.523, 0, -5.523, -10, 0, -5.523, 0, 5.523, 0, 0, -10, 0, -5.523, 0, 0, 10, 0)
}
point_count = 5
[sub_resource type="Resource" id="Resource_5vw27"]
resource_local_to_scene = true
script = ExtResource("4_qiyup")
[node name="Nodule" type="Area2D" unique_id=698496795 node_paths=PackedStringArray("Collision")]
script = ExtResource("1_beybw")
Radius = 10.0
Collision = NodePath("Collision")
Age = 0.5
[node name="Collision" type="CollisionShape2D" parent="." unique_id=402084582]
shape = SubResource("CircleShape2D_7mycd")
[node name="Ellipse2" type="Node2D" parent="." unique_id=1962026750 node_paths=PackedStringArray("polygon", "line")]
z_index = 10
script = ExtResource("2_cahmm")
polygon = NodePath("Fill")
stroke_color = Color(0, 0, 0, 1)
stroke_width = 4.0
line = NodePath("Stroke")
curve = SubResource("Curve2D_272bh")
update_curve_at_runtime = true
arc_list = SubResource("Resource_5vw27")
shape_type = 2
size = Vector2(20, 20)
rx = 10.0
ry = 10.0
[node name="Fill" type="Polygon2D" parent="Ellipse2" unique_id=1355608579]
color = Color(0.21759033, 0.88248014, 0.8984375, 1)
polygon = PackedVector2Array(10, 0, 9.948373, 1.022467, 9.796842, 2.0153925, 9.550433, 2.9737506, 9.214172, 3.8925154, 8.793085, 4.766661, 8.292197, 5.5911617, 7.7165356, 6.3609915, 7.071125, 7.071125, 6.360992, 7.7165356, 5.591162, 8.292197, 4.766661, 8.793085, 3.8925154, 9.214172, 2.9737508, 9.550432, 2.0153925, 9.796842, 1.022467, 9.948373, 0, 10, -1.022467, 9.948373, -2.0153925, 9.796842, -2.9737506, 9.550433, -3.8925154, 9.214172, -4.766661, 8.793085, -5.5911617, 8.292197, -6.3609915, 7.7165356, -7.071125, 7.071125, -7.7165356, 6.360992, -8.292197, 5.591162, -8.793085, 4.766661, -9.214172, 3.8925154, -9.550432, 2.9737508, -9.796842, 2.0153925, -9.948373, 1.022467, -10, 0, -9.948373, -1.022467, -9.796842, -2.0153925, -9.550433, -2.9737506, -9.214172, -3.8925154, -8.793085, -4.766661, -8.292197, -5.5911617, -7.7165356, -6.3609915, -7.071125, -7.071125, -6.360992, -7.7165356, -5.591162, -8.292197, -4.766661, -8.793085, -3.8925154, -9.214172, -2.9737508, -9.550432, -2.0153925, -9.796842, -1.022467, -9.948373, 0, -10, 1.022467, -9.948373, 2.0153925, -9.796842, 2.9737506, -9.550433, 3.8925154, -9.214172, 4.766661, -8.793085, 5.5911617, -8.292197, 6.3609915, -7.7165356, 7.071125, -7.071125, 7.7165356, -6.360992, 8.292197, -5.591162, 8.793085, -4.766661, 9.214172, -3.8925154, 9.550432, -2.9737508, 9.796842, -2.0153925, 9.948373, -1.022467)
metadata/_edit_lock_ = true
[node name="Stroke" type="Line2D" parent="Ellipse2" unique_id=1428670823]
points = PackedVector2Array(10, 0, 9.948373, 1.022467, 9.796842, 2.0153925, 9.550433, 2.9737506, 9.214172, 3.8925154, 8.793085, 4.766661, 8.292197, 5.5911617, 7.7165356, 6.3609915, 7.071125, 7.071125, 6.360992, 7.7165356, 5.591162, 8.292197, 4.766661, 8.793085, 3.8925154, 9.214172, 2.9737508, 9.550432, 2.0153925, 9.796842, 1.022467, 9.948373, 0, 10, -1.022467, 9.948373, -2.0153925, 9.796842, -2.9737506, 9.550433, -3.8925154, 9.214172, -4.766661, 8.793085, -5.5911617, 8.292197, -6.3609915, 7.7165356, -7.071125, 7.071125, -7.7165356, 6.360992, -8.292197, 5.591162, -8.793085, 4.766661, -9.214172, 3.8925154, -9.550432, 2.9737508, -9.796842, 2.0153925, -9.948373, 1.022467, -10, 0, -9.948373, -1.022467, -9.796842, -2.0153925, -9.550433, -2.9737506, -9.214172, -3.8925154, -8.793085, -4.766661, -8.292197, -5.5911617, -7.7165356, -6.3609915, -7.071125, -7.071125, -6.360992, -7.7165356, -5.591162, -8.292197, -4.766661, -8.793085, -3.8925154, -9.214172, -2.9737508, -9.550432, -2.0153925, -9.796842, -1.022467, -9.948373, 0, -10, 1.022467, -9.948373, 2.0153925, -9.796842, 2.9737506, -9.550433, 3.8925154, -9.214172, 4.766661, -8.793085, 5.5911617, -8.292197, 6.3609915, -7.7165356, 7.071125, -7.071125, 7.7165356, -6.360992, 8.292197, -5.591162, 8.793085, -4.766661, 9.214172, -3.8925154, 9.550432, -2.9737508, 9.796842, -2.0153925, 9.948373, -1.022467)
closed = true
width = 4.0
default_color = Color(0, 0, 0, 1)
sharp_limit = 90.0
metadata/_edit_lock_ = true

View File

@@ -11,7 +11,11 @@ config_version=5
[addons] [addons]
curved_lines_2d/use_line_2d_for_stroke=true curved_lines_2d/use_line_2d_for_stroke=true
curved_lines_2d/add_fill_enabled=false curved_lines_2d/add_fill_enabled=true
curved_lines_2d/add_stroke_enabled=true
curved_lines_2d/fill_color=Color(0.21759033, 0.88248014, 0.8984375, 1)
curved_lines_2d/stroke_width=4.0
curved_lines_2d/stroke_color=Color(0, 0, 0, 1)
[application] [application]
@@ -22,7 +26,7 @@ config/icon="res://assets/icon.svg"
[autoload] [autoload]
EventBus="*res://scripts/EventBus.cs" EventBus="*uid://bibq3e4nkwiwv"
[dotnet] [dotnet]
@@ -79,6 +83,11 @@ cam_drag={
"events": [Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"button_mask":0,"position":Vector2(0, 0),"global_position":Vector2(0, 0),"factor":1.0,"button_index":3,"canceled":false,"pressed":false,"double_click":false,"script":null) "events": [Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"button_mask":0,"position":Vector2(0, 0),"global_position":Vector2(0, 0),"factor":1.0,"button_index":3,"canceled":false,"pressed":false,"double_click":false,"script":null)
] ]
} }
build={
"deadzone": 0.2,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":66,"key_label":0,"unicode":98,"location":0,"echo":false,"script":null)
]
}
[physics] [physics]

14
root.tscn Normal file
View File

@@ -0,0 +1,14 @@
[gd_scene format=3 uid="uid://cd47em5shcnid"]
[ext_resource type="Script" uid="uid://but18j8vnbom4" path="res://Root.cs" id="1_pyidc"]
[sub_resource type="Curve" id="Curve_pq8q7"]
_data = [Vector2(0.051515155, 0.8803681), 0.0, 0.0, 0, 0, Vector2(0.054545455, 0.47361964), 0.0, 0.0, 0, 0, Vector2(0.087878786, 0.8165644), 0.0, 0.0, 0, 0, Vector2(0.12727273, 0.32208586), 0.0, 0.0, 0, 0, Vector2(0.19090909, 0.67386234), 0.0, 0.0, 0, 0, Vector2(0.34242424, 0.7876313), 0.0, 0.0, 0, 0, Vector2(0.38181818, 0.34601223), 0.0, 0.0, 0, 0, Vector2(0.530303, 0.4815951), 0.0, 0.0, 0, 0, Vector2(0.7151515, 0.66503066), 0.0, 0.0, 0, 0, Vector2(0.75454545, 0.3141104), 0.0, 0.0, 0, 0, Vector2(0.8575757, 0.38588953), 0.0, 0.0, 0, 0, Vector2(0.8636364, 0.7766871), 0.0, 0.0, 0, 0, Vector2(0.9, 0.8165644), 0.0, 0.0, 0, 0, Vector2(0.94545454, 0.37791407), 0.0, 0.0, 0, 0]
point_count = 14
[node name="Root" type="Node2D" unique_id=1632219197]
script = ExtResource("1_pyidc")
[node name="Line2D" type="Line2D" parent="." unique_id=388168093]
points = PackedVector2Array(0, 0, -25, -59, -53, -88, -94, -96, -130, -114, -151, -125, -167, -148, -188, -168, -207, -199, -242, -220)
width_curve = SubResource("Curve_pq8q7")

View File

@@ -1,102 +0,0 @@
using System;
using Godot;
using NodeWar.scripts.components;
namespace NodeWar.scripts;
public partial class Base : Area2D
{
private Node2D _selection;
private Node2D _gfx;
public Vector2 TargetPosition { get; set; }
[Export]
public Node2D Target;
[Export]
public HealthComponent HealthComponent;
[Export]
public SpawnerComponent SpawnerComponent;
[Export]
public bool Selected = false;
[Export]
public Faction Faction = Faction.Neutral;
private bool _mouseInside = false;
private bool _selected = false;
private PackedScene _pipScene = GD.Load<PackedScene>("res://pip.tscn");
public override void _Ready()
{
MouseEntered += OnMouseEntered;
MouseExited += OnMouseExited;
_selection = GetNode<Node2D>("Selection");
_gfx = GetNode<Node2D>("Gfx");
_selection.Visible = false;
SpawnerComponent.Faction = Faction;
UpdateColor();
}
public override void _UnhandledInput(InputEvent @event)
{
if (@event is InputEventMouseButton { Pressed: true, ButtonIndex: MouseButton.Left })
{
_selected = _mouseInside;
if (_selected)
{
_selection.Visible = true;
// TODO: super ugly
EventBus.Instance.EmitSignal(
EventBus.SignalName.SelectionChanged,
"This is a Base"
);
}
else
{
_selection.Visible = false;
}
}
if (
@event is InputEventMouseButton { Pressed: true, ButtonIndex: MouseButton.Right }
&& _selected
)
{
// TODO: 3 Stellen eine Sache zu speichern?
TargetPosition = GetGlobalMousePosition();
Target.GlobalPosition = TargetPosition;
SpawnerComponent.Target = TargetPosition;
}
}
private void UpdateColor()
{
_gfx.Modulate = Faction switch
{
Faction.Neutral => Colors.Gray,
Faction.Player => Colors.ForestGreen,
Faction.Computer => Colors.Red,
_ => throw new ArgumentOutOfRangeException(),
};
}
private void OnMouseExited()
{
_mouseInside = false;
}
private void OnMouseEntered()
{
_mouseInside = true;
}
}

View File

@@ -1 +0,0 @@
uid://demgvopfvjmql

View File

@@ -6,18 +6,10 @@ public partial class EventBus : Node
{ {
[Signal] [Signal]
public delegate void GameStartedEventHandler(); public delegate void GameStartedEventHandler();
[Signal] [Signal]
public delegate void GameEndedEventHandler(bool win); public delegate void GameEndedEventHandler(bool win);
[Signal] [Signal]
public delegate void SelectionChangedEventHandler(string infoText); public delegate void SelectionChangedEventHandler(string infoText);
}
public static EventBus Instance { get; private set; }
public override void _EnterTree()
{
Instance ??= this;
}
}

View File

@@ -1,9 +1,9 @@
namespace NodeWar; namespace NodeWar.scripts;
public static class Extensions public static class Extensions
{ {
public static float ToFloat(this double value) public static float ToFloat(this double value)
{ {
return (float)value; return (float)value;
} }
} }

299
scripts/LinePath2D.cs Normal file
View File

@@ -0,0 +1,299 @@
namespace NodeWar.scripts;
using Godot;
[Tool]
[GlobalClass]
public partial class LinePath2D : Path2D
{
private const bool ShouldCreateDefaultCurve = true;
private const bool ShouldCreateDefaultProfile = true;
// Size in pixels of the default curve
private const int DefaultCurveSize = 400;
// Size in pixels of the default curve width
private const float DefaultCurveWidth = 25.0f;
private Line2D _line = new();
[ExportCategory("LinePath2D")]
[Export]
public Curve2D LinePathCurve
{
get => Curve;
set
{
if (Curve != null)
Curve.Changed -= BuildLine;
Curve = value;
if (Curve != null)
Curve.Changed += BuildLine;
BuildLine();
}
}
/// <summary>
/// Sets the width of the curve.
/// </summary>
[Export]
public float Width
{
get => _line?.Width ?? DefaultCurveWidth;
set
{
if (_line == null)
return;
_line.Width = value;
}
}
/// <summary>
/// Use this Curve to modify the line width profile.
/// </summary>
[Export]
public Curve WidthProfile
{
get => _line?.WidthCurve;
set
{
if (_line == null)
return;
_line.WidthCurve = value;
}
}
[ExportGroup("Fill", "Fill")]
[Export]
public Color FillDefaultColor
{
get => _line?.DefaultColor ?? Colors.White;
set
{
if (_line != null)
_line.DefaultColor = value;
}
}
/// <summary>
/// Fill the path with a gradient.
/// </summary>
[Export]
public Gradient FillGradient
{
get => _line?.Gradient;
set
{
if (_line != null)
_line.Gradient = value;
}
}
/// <summary>
/// Fill the path with a texture.
/// </summary>
[Export]
public Texture2D FillTexture
{
get => _line?.Texture;
set
{
if (_line != null)
_line.Texture = value;
}
}
/// <summary>
/// Change the texture fill mode.
/// </summary>
[Export]
public Line2D.LineTextureMode FillTextureMode
{
get => _line?.TextureMode ?? Line2D.LineTextureMode.None;
set
{
if (_line != null)
_line.TextureMode = value;
}
}
[ExportGroup("Capping", "Cap")]
[Export]
public Line2D.LineJointMode CapJointMode
{
get => _line?.JointMode ?? Line2D.LineJointMode.Sharp;
set
{
if (_line != null)
_line.JointMode = value;
}
}
/// <summary>
/// The style of the beginning of the polyline.
/// </summary>
[Export]
public Line2D.LineCapMode CapBeginCap
{
get => _line?.BeginCapMode ?? Line2D.LineCapMode.None;
set
{
if (_line != null)
_line.BeginCapMode = value;
}
}
/// <summary>
/// The style of the ending of the polyline.
/// </summary>
[Export]
public Line2D.LineCapMode CapEndCap
{
get => _line?.EndCapMode ?? Line2D.LineCapMode.None;
set
{
if (_line != null)
_line.EndCapMode = value;
}
}
/// <summary>
/// If true and the polyline has more than two segments,
/// the first and the last point will be connected by a segment.
/// </summary>
[Export]
public bool CapCloseCurve
{
get => _line?.Closed ?? false;
set
{
if (_line != null)
_line.Closed = value;
}
}
[ExportGroup("Border", "Border")]
[Export]
public float BorderSharpLimit
{
get => _line?.SharpLimit ?? 2.0f;
set
{
if (_line != null)
_line.SharpLimit = value;
}
}
/// <summary>
/// The smoothness of the rounded joints and caps.
/// </summary>
[Export]
public int BorderRoundPrecision
{
get => _line?.RoundPrecision ?? 8;
set
{
if (_line != null)
_line.RoundPrecision = value;
}
}
/// <summary>
/// If true the polyline border will be antialiased.
/// Note: Antialiased polylines are not accelerated by batching.
/// </summary>
[Export]
public bool BorderAntialiased
{
get => _line?.Antialiased ?? false;
set
{
if (_line != null)
_line.Antialiased = value;
}
}
public override void _Ready()
{
ClearDuplicatedInternalChildren();
_line.SetMeta("__lp2d_internal__", true);
AddChild(_line);
if (Curve == null || Curve.PointCount < 2)
Curve = CreateDefaultCurve(DefaultCurveSize);
_line.WidthCurve ??= CreateDefaultProfile(DefaultCurveWidth);
BuildLine();
if (Curve != null)
{
Curve.Changed -= BuildLine;
Curve.Changed += BuildLine;
}
}
public override void _ExitTree()
{
if (Curve != null)
Curve.Changed -= BuildLine;
}
private Curve2D CreateDefaultCurve(int size)
{
if (!ShouldCreateDefaultCurve)
return null;
var curve = new Curve2D();
curve.AddPoint(Vector2.Zero, Vector2.Zero, new Vector2(size, 0));
curve.AddPoint(new Vector2(size, size), new Vector2(-size, 0), Vector2.Zero);
return curve;
}
private static Curve CreateDefaultProfile(float size)
{
if (!ShouldCreateDefaultProfile)
return null;
var curve = new Curve();
curve.AddPoint(Vector2.Zero);
curve.AddPoint(new Vector2(0.5f, 1.0f));
curve.AddPoint(new Vector2(1.0f, 0.0f));
return curve;
}
private void BuildLine()
{
if (_line == null)
return;
if (Curve == null || Curve.PointCount < 2)
{
_line.ClearPoints();
return;
}
_line.Points = Curve.GetBakedPoints();
}
private void ClearDuplicatedInternalChildren()
{
foreach (var child in GetChildren())
{
if (child.GetMeta("__lp2d_internal__", false).AsBool())
child.QueueFree();
}
}
}

View File

@@ -0,0 +1 @@
uid://dyydou5vpcmmx

View File

@@ -40,10 +40,6 @@ public partial class Pip : Area2D
private void OnAreaEntered(Node2D body) private void OnAreaEntered(Node2D body)
{ {
if (body is Base enteredBase && enteredBase.Faction != Faction)
{
enteredBase.HealthComponent.TakeDamage(1);
QueueFree();
}
} }
} }