Spawn markers in editor

This commit is contained in:
Marco 2025-09-22 16:33:10 +02:00
commit 479df3c7c4
8 changed files with 150 additions and 76 deletions

View file

@ -0,0 +1,29 @@
[gd_resource type="Resource" script_class="FuncGodotFGDPointClass" load_steps=5 format=3 uid="uid://cd8kf5wey5n8n"]
[ext_resource type="Resource" uid="uid://5bc1qysixhmh" path="res://3D/TrenchBroom/EntityDefinitions/base/actor_base.tres" id="1_yd0db"]
[ext_resource type="Resource" uid="uid://kerywjgft7vh" path="res://3D/TrenchBroom/EntityDefinitions/base/target_base.tres" id="2_n1lol"]
[ext_resource type="Script" uid="uid://cxsqwtsqd8w33" path="res://addons/func_godot/src/fgd/func_godot_fgd_point_class.gd" id="3_rwtar"]
[ext_resource type="Script" uid="uid://00rbjdb4mnb0" path="res://Scripts/Actors/EnemyMarker3D.cs" id="4_7cqxf"]
[resource]
script = ExtResource("3_rwtar")
script_class = ExtResource("4_7cqxf")
apply_rotation_on_map_build = false
apply_scale_on_map_build = false
classname = "marker_spawn_enemy"
description = "Enemy Spawn Marker"
base_classes = Array[Resource]([ExtResource("1_yd0db"), ExtResource("2_n1lol")])
class_properties = {
"autospawn": true,
"resource_path": ""
}
class_property_descriptions = {
"autospawn": "Whether to spawn automatically or not",
"resource_path": "Path to the enemy resource"
}
meta_properties = {
"color": Color(0.9229911, 0.41614023, 0.21117541, 1),
"size": AABB(-4, -4, -6, 4, 4, 6)
}
node_class = "Marker3D"
metadata/_custom_type_script = "uid://cxsqwtsqd8w33"

View file

@ -0,0 +1,29 @@
[gd_resource type="Resource" script_class="FuncGodotFGDPointClass" load_steps=5 format=3 uid="uid://cp6w7rgfgtxlk"]
[ext_resource type="Resource" uid="uid://5bc1qysixhmh" path="res://3D/TrenchBroom/EntityDefinitions/base/actor_base.tres" id="1_4w7c8"]
[ext_resource type="Resource" uid="uid://kerywjgft7vh" path="res://3D/TrenchBroom/EntityDefinitions/base/target_base.tres" id="2_4yeye"]
[ext_resource type="Script" uid="uid://cxsqwtsqd8w33" path="res://addons/func_godot/src/fgd/func_godot_fgd_point_class.gd" id="2_8rpcj"]
[ext_resource type="Script" uid="uid://00rbjdb4mnb0" path="res://Scripts/Actors/EnemyMarker3D.cs" id="3_4yeye"]
[resource]
script = ExtResource("2_8rpcj")
script_class = ExtResource("3_4yeye")
apply_rotation_on_map_build = false
apply_scale_on_map_build = false
classname = "marker_spawn_enemy_fairy_guard"
description = "Fairy Guard Spawn Marker"
base_classes = Array[Resource]([ExtResource("1_4w7c8"), ExtResource("2_4yeye")])
class_properties = {
"autospawn": true,
"resource_path": "res://Resources/Enemies/Fairy_Guard_3D.tres"
}
class_property_descriptions = {
"autospawn": "Whether to spawn automatically or not",
"resource_path": "Path to the enemy resource"
}
meta_properties = {
"color": Color(0.9229911, 0.41614023, 0.21117541, 1),
"size": AABB(-4, -4, -6, 4, 4, 6)
}
node_class = "Marker3D"
metadata/_custom_type_script = "uid://cxsqwtsqd8w33"

View file

@ -0,0 +1,29 @@
[gd_resource type="Resource" script_class="FuncGodotFGDPointClass" load_steps=5 format=3 uid="uid://n7nb0h11j0nh"]
[ext_resource type="Resource" uid="uid://5bc1qysixhmh" path="res://3D/TrenchBroom/EntityDefinitions/base/actor_base.tres" id="1_ipnjc"]
[ext_resource type="Resource" uid="uid://kerywjgft7vh" path="res://3D/TrenchBroom/EntityDefinitions/base/target_base.tres" id="2_dg4k0"]
[ext_resource type="Script" uid="uid://cxsqwtsqd8w33" path="res://addons/func_godot/src/fgd/func_godot_fgd_point_class.gd" id="2_e3k6b"]
[ext_resource type="Script" uid="uid://b88cmj87g78mx" path="res://Scripts/Actors/ItemMarker3D.cs" id="4_otker"]
[resource]
script = ExtResource("2_e3k6b")
script_class = ExtResource("4_otker")
apply_rotation_on_map_build = false
apply_scale_on_map_build = false
classname = "marker_spawn_item"
description = "Item Spawn Marker"
base_classes = Array[Resource]([ExtResource("1_ipnjc"), ExtResource("2_dg4k0")])
class_properties = {
"autospawn": true,
"resource_path": ""
}
class_property_descriptions = {
"autospawn": "Whether to spawn automatically or not",
"resource_path": "Path to the enemy resource"
}
meta_properties = {
"color": Color(0.24138406, 0.36984414, 0.9698661, 1),
"size": AABB(-4, -4, -6, 4, 4, 6)
}
node_class = "Marker3D"
metadata/_custom_type_script = "uid://cxsqwtsqd8w33"

View file

@ -1,4 +1,4 @@
[gd_resource type="Resource" script_class="FuncGodotFGDFile" load_steps=53 format=3 uid="uid://b700sa4be6dfa"]
[gd_resource type="Resource" script_class="FuncGodotFGDFile" load_steps=55 format=3 uid="uid://b700sa4be6dfa"]
[ext_resource type="Resource" uid="uid://ia1t5p4mhom3" path="res://3D/TrenchBroom/EntityDefinitions/point/lights/light_omni.tres" id="1_7vcj1"]
[ext_resource type="Script" uid="uid://drlmgulwbjwqu" path="res://addons/func_godot/src/fgd/func_godot_fgd_file.gd" id="1_lykim"]
@ -52,7 +52,9 @@
[ext_resource type="Resource" uid="uid://umbceo5tcxni" path="res://3D/TrenchBroom/EntityDefinitions/point/actors/actor_chair.tres" id="49_8hbdx"]
[ext_resource type="Resource" uid="uid://bhkn5vwemx7nk" path="res://3D/TrenchBroom/EntityDefinitions/point/actors/actor_box_blue_tall.tres" id="50_xpy40"]
[ext_resource type="Resource" uid="uid://cmdgqpq5e1duq" path="res://3D/TrenchBroom/EntityDefinitions/point/actors/marker_spawn.tres" id="51_mwau1"]
[ext_resource type="Resource" uid="uid://cd8kf5wey5n8n" path="res://3D/TrenchBroom/EntityDefinitions/point/actors/EnemySpawners/marker_spawn_enemy.tres" id="52_v4gel"]
[ext_resource type="Resource" uid="uid://n7nb0h11j0nh" path="res://3D/TrenchBroom/EntityDefinitions/point/actors/ItemSpawners/marker_spawn_item.tres" id="53_k53o0"]
[resource]
script = ExtResource("1_lykim")
entity_definitions = Array[Resource]([ExtResource("1_7vcj1"), ExtResource("2_u7uvb"), ExtResource("3_u7uvb"), ExtResource("4_1nmxk"), ExtResource("5_ljb2x"), ExtResource("6_seuvu"), ExtResource("7_fmwex"), ExtResource("8_c8m8m"), ExtResource("9_14sjf"), ExtResource("10_xik3w"), ExtResource("11_dgiqm"), ExtResource("12_1teik"), ExtResource("13_f0hti"), ExtResource("14_6ld6e"), ExtResource("15_g8j5j"), ExtResource("16_7h4of"), ExtResource("17_m3sbm"), ExtResource("18_m3sbm"), ExtResource("19_hvhb8"), ExtResource("20_3v5us"), ExtResource("21_g67cj"), ExtResource("22_iy67w"), ExtResource("23_b5lmu"), ExtResource("24_ndas4"), ExtResource("25_n7wsi"), ExtResource("26_v48k5"), ExtResource("27_ombvk"), ExtResource("28_31lma"), ExtResource("29_louv0"), ExtResource("30_wfgfu"), ExtResource("31_elv2e"), ExtResource("32_elv2e"), ExtResource("33_aawmv"), ExtResource("34_wy0ht"), ExtResource("35_3jqmy"), ExtResource("36_p5b6l"), ExtResource("37_53o7h"), ExtResource("38_mdgca"), ExtResource("39_d6b4f"), ExtResource("40_l3pck"), ExtResource("41_q8hab"), ExtResource("42_ekplg"), ExtResource("43_d7qk0"), ExtResource("44_k6g2u"), ExtResource("45_b4ckg"), ExtResource("46_dyoc0"), ExtResource("47_pa845"), ExtResource("48_lb3ub"), ExtResource("49_8hbdx"), ExtResource("50_xpy40"), ExtResource("51_mwau1")])
entity_definitions = Array[Resource]([ExtResource("1_7vcj1"), ExtResource("2_u7uvb"), ExtResource("3_u7uvb"), ExtResource("4_1nmxk"), ExtResource("5_ljb2x"), ExtResource("6_seuvu"), ExtResource("7_fmwex"), ExtResource("8_c8m8m"), ExtResource("9_14sjf"), ExtResource("10_xik3w"), ExtResource("11_dgiqm"), ExtResource("12_1teik"), ExtResource("13_f0hti"), ExtResource("14_6ld6e"), ExtResource("15_g8j5j"), ExtResource("16_7h4of"), ExtResource("17_m3sbm"), ExtResource("18_m3sbm"), ExtResource("19_hvhb8"), ExtResource("20_3v5us"), ExtResource("21_g67cj"), ExtResource("22_iy67w"), ExtResource("23_b5lmu"), ExtResource("24_ndas4"), ExtResource("25_n7wsi"), ExtResource("26_v48k5"), ExtResource("27_ombvk"), ExtResource("28_31lma"), ExtResource("29_louv0"), ExtResource("30_wfgfu"), ExtResource("31_elv2e"), ExtResource("32_elv2e"), ExtResource("33_aawmv"), ExtResource("34_wy0ht"), ExtResource("35_3jqmy"), ExtResource("36_p5b6l"), ExtResource("37_53o7h"), ExtResource("38_mdgca"), ExtResource("39_d6b4f"), ExtResource("40_l3pck"), ExtResource("41_q8hab"), ExtResource("42_ekplg"), ExtResource("43_d7qk0"), ExtResource("44_k6g2u"), ExtResource("45_b4ckg"), ExtResource("46_dyoc0"), ExtResource("47_pa845"), ExtResource("48_lb3ub"), ExtResource("49_8hbdx"), ExtResource("50_xpy40"), ExtResource("51_mwau1"), ExtResource("52_v4gel"), ExtResource("53_k53o0")])

View file

@ -2,6 +2,7 @@
using Cirno.Scripts.Resources;
using Cirno.Scripts.Utils;
using Godot;
using Godot.Collections;
namespace Cirno.Scripts.Actors;
@ -52,6 +53,26 @@ public partial class EnemyMarker3D : PreviewMarker3D, IActivable
private EnemyProxy3D _spawnedEnemy;
public void _func_godot_apply_properties(Dictionary<string, Variant> props)
{
//GroupName = (string)props["targetname"];
this.AddToGroup("EnemyMarkers");
AutoSpawn = props["autospawn"].AsBool();
var scriptPath = props["resource_path"].AsString();
if (!string.IsNullOrWhiteSpace(scriptPath))
{
Enemy = GD.Load<EnemyResource>(scriptPath);
}
else
{
GD.PushWarning($"Spawner {this.Name} has no enemy assigned");
}
Billboard = true;
//MarkerId = props["id"].AsInt32();
}
public override void _Ready()
{
base._Ready();

View file

@ -1,6 +1,7 @@
using Cirno.Scripts.Interactables;
using Cirno.Scripts.Resources;
using Godot;
using Godot.Collections;
namespace Cirno.Scripts.Actors;
@ -28,61 +29,26 @@ public partial class ItemMarker3D : PreviewMarker3D
[Export] public bool AutoSpawn { get; set; } = false;
// [ExportToolButton("Update Icon")] public Callable RedrawButton => Callable.From(Redraw);
// [ExportToolButton("Clear Children")] public Callable ClearChildrenButton => Callable.From(ClearChildren);
public void _func_godot_apply_properties(Dictionary<string, Variant> props)
{
//GroupName = (string)props["targetname"];
this.AddToGroup("ItemMarkers");
AutoSpawn = props["autospawn"].AsBool();
// public override void _Draw()
// {
// if (!Engine.IsEditorHint()) return;
// if (Item is null) return;
// if (Item.InventorySprite is null) return;
//
// DrawTexture(Item.InventorySprite, - new Vector2(Item.InventorySprite.GetWidth() / 2f, Item.InventorySprite.GetHeight() / 2f));
// }
//
// private void Redraw()
// {
// QueueRedraw();
// }
var scriptPath = props["resource_path"].AsString();
if (!string.IsNullOrWhiteSpace(scriptPath))
{
Item = GD.Load<LootItem>(scriptPath);
}
else
{
GD.PushWarning($"Spawner {this.Name} has no item assigned");
}
// private void ClearChildren()
// {
// var children = GetChildren();
// foreach (var child in children)
// {
// if (child is Sprite3D)
// {
// child.QueueFree();
// }
// }
//
// _sprite = null;
// }
Billboard = true;
//MarkerId = props["id"].AsInt32();
}
// private void QueueRedraw()
// {
// if (!Engine.IsEditorHint()) return;
// if (Item?.InventorySprite is null) return;
//
// if (_sprite is null)
// {
// GD.Print("Remaking sprite");
// _sprite = new EditorSprite3D();
// this.AddChild(_sprite);
// //_sprite.Owner = GetTree().EditedSceneRoot;
// }
//
// _sprite.Texture = Item.InventorySprite;
// //_sprite.SetRotationDegrees(new Vector3(-45, 45, 0));
// _sprite.FixedSize = true;
// _sprite.SetBillboardMode(BaseMaterial3D.BillboardModeEnum.Enabled);
// _sprite.TextureFilter = BaseMaterial3D.TextureFilterEnum.Nearest;
//
//
// }
//private Sprite3D _sprite;
public override void _Ready()
{
base._Ready();

View file

@ -21,7 +21,7 @@ public partial class PreviewMarker3D : Marker3D
private bool _fixedSize;
private bool _billboard;
private float _pixelSize = 0.1f;
private float _pixelSize = 0.05f;
[Export]
protected bool FixedSize

View file

@ -17,32 +17,31 @@ public partial class GameController : Node
private Hud _hud;
private IsoPlayerFSMProxy _player;
public IsoPlayerStateMachine Player => _player.PlayerFSM;
[Export] private Marker3D _cameraTarget;
public Vector3? PlayerPosition => _player?.GlobalPosition ?? null;
public Vector3? PlayerVelocity => _player?.Velocity ?? null;
[Export] public bool DebugDraw { get; set; }
[Signal]
public delegate void ManagerReadyEventHandler();
[Export] public MapResource MapResource { get; private set; }
[Export] public PackedScene PlayerTemplate { get; set; }
[Export] public Dictionary<int, NodePath> SpawnMarkers { get; private set; } = new();
[Export]
public int EggStartIndex = 0;
[Export] public int EggStartIndex = 0;
[Export] public Node3D PlayerParentNode { get; set; }
private InventoryManager _inventoryManager { get; set; }
private Vector3 _lastCheckPointPosition;
private GameState GameState => GameStateManager.Instance.GameState;
private GameState GameState => GameStateManager.Instance.GameState;
public Vector3 LastCheckPointPosition
{
get => _lastCheckPointPosition;
@ -57,7 +56,7 @@ public partial class GameController : Node
gsm.ProcessMode = ProcessModeEnum.Always;
this.AddChild(gsm);
gsm.Init(GameState.Playing);
RenderingServer.SetDefaultClearColor(Colors.Black);
if (GlobalState.Instance.SessionSettings.GameMode is GameMode.Roguelite)
{
@ -72,7 +71,7 @@ public partial class GameController : Node
GlobalState.Session.LevelNumber = MapResource.LevelId;
GlobalState.Session.MapId = MapResource.MapId;
}
GlobalState.Instance.ChangeCursor(false);
if (GlobalState.Instance.SessionSettings.AllowSaving)
@ -91,7 +90,7 @@ public partial class GameController : Node
_inventoryManager = GetNodeOrNull<InventoryManager>("InventoryManager");
if (_inventoryManager == null) GD.Print("No inventory manager in scene.");
//SpawnBulletsContainer();
if (_hud != null)
@ -118,7 +117,7 @@ public partial class GameController : Node
{
EmitSignalManagerReady();
}
private void DelayPlayerSpawn()
{
if (SpawnMarkers.Any())
@ -154,7 +153,7 @@ public partial class GameController : Node
// Wait before the player is fully initialized before spawning weapons on it
CallDeferred(MethodName.SpawnWeapons);
}
private void SpawnWeapons()
{
foreach (var startingItem in MapResource.StartData.StartingEquipment)
@ -167,14 +166,14 @@ public partial class GameController : Node
_inventoryManager.RemoveItem(item);
}
}
public void SpawnPlayer()
{
if (_player != null) return;
//_player = this.CreateChild<PlayerMovement>(PlayerTemplate, PlayerSpawnMarker.Position );
_player = PlayerTemplate.Instantiate<IsoPlayerFSMProxy>();
if (PlayerParentNode is not null)
{
PlayerParentNode.AddChild(_player);
@ -186,7 +185,7 @@ public partial class GameController : Node
this.AddChild(_player);
_player.Owner = this;
}
_player.GlobalPosition = GetStartPosition();
LastCheckPointPosition = _player.GlobalPosition;
@ -202,7 +201,7 @@ public partial class GameController : Node
// _cameraTarget.GlobalPosition = _player.Position;
// }
}
public void CameraTargetPlayer()
{
if (_player is null) return;
@ -219,9 +218,8 @@ public partial class GameController : Node
{
_cameraTarget.Position += offset.Value;
}
}
private Vector3 GetStartPosition()
{
var spawners = GetTree().GetNodesInGroup("SpawnMarkers").Cast<PlayerStartMarker3D>().ToList();