description requests
This commit is contained in:
parent
de2e8b1e50
commit
6fbae10750
35 changed files with 359 additions and 154 deletions
|
|
@ -6,7 +6,7 @@ namespace Newlon.Components.Plants;
|
|||
// Shoot component of some plants
|
||||
public partial class Shooter : Node2D
|
||||
{
|
||||
[Export] protected PackedScene _projectile;
|
||||
[Export] public PackedScene _projectile { get; protected set;}
|
||||
[Export] protected Timer _timer;
|
||||
|
||||
protected RuntimePlantData _plantData;
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ public partial class EatBox : Area2D
|
|||
[Export]
|
||||
private AudioStream biteSound = ResourceLoader.Load<AudioStream>("uid://dyid55nhflwyn");
|
||||
private RuntimePlantData plant;
|
||||
public float Damage => _damage.GetValue();
|
||||
|
||||
public bool isEating = false;
|
||||
|
||||
|
|
@ -19,7 +20,7 @@ public partial class EatBox : Area2D
|
|||
{
|
||||
if (GetParent<RuntimeZombieData>().AbleToEat)
|
||||
{
|
||||
plant?.TakeDamage((int)_damage.GetValue(), GetParent());
|
||||
plant?.TakeDamage(Damage, GetParent());
|
||||
AudioSequencer.Play("bite", biteSound);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ public partial class ZombieMover : Node
|
|||
{
|
||||
[Export]
|
||||
private FloatModifiers _speed;
|
||||
public float Speed => _speed.GetValue();
|
||||
[Export]
|
||||
private float _speedControlMult;
|
||||
private Node2D _zombie;
|
||||
|
|
@ -21,7 +22,7 @@ public partial class ZombieMover : Node
|
|||
* (float)delta
|
||||
* FieldParams.TileWidth
|
||||
* GetParent<RuntimeZombieData>().LocalTimescale
|
||||
* _speed.GetValue()
|
||||
* Speed
|
||||
* _speedControlMult;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,9 @@
|
|||
using System.Collections.Generic;
|
||||
using Godot;
|
||||
using Newlon.Components;
|
||||
using Newlon.Components.GUI.Seedpackets;
|
||||
using Newlon.Components.Plants;
|
||||
using Newlon.Systems.Effects;
|
||||
|
||||
public partial class Previewport : SubViewport
|
||||
{
|
||||
|
|
@ -41,10 +44,98 @@ public partial class Previewport : SubViewport
|
|||
_frameField.Texture = start_Field;
|
||||
current_display = resource.Scene.Instantiate();
|
||||
title.Text = Tr(resource.NameKey);
|
||||
description.Text = Tr("rwd_"+resource.NameKey)+"\n"+ Tr(resource.DescriptionKey);
|
||||
AddChild(current_display);
|
||||
if (current_display is Entity entity)
|
||||
entity.DisableBrain();
|
||||
|
||||
|
||||
var unparsedDescription = Tr(resource.DescriptionKey);
|
||||
var keys = GetRequestedKeys(unparsedDescription);
|
||||
FillPlaceholders(keys, resource, current_display);
|
||||
var parsedDescription = ReplaceTextUsingDict(keys, unparsedDescription);
|
||||
|
||||
description.Text = Tr("rwd_" + resource.NameKey) + "\n" + parsedDescription;
|
||||
}
|
||||
|
||||
private Dictionary<string, float> GetRequestedKeys(string text)
|
||||
{
|
||||
var result = new Dictionary<string, float>();
|
||||
int start = -1;
|
||||
|
||||
for (int i = 0; i < text.Length; i++)
|
||||
{
|
||||
if (text[i] == '{')
|
||||
{
|
||||
start = i;
|
||||
}
|
||||
if (text[i] == '}')
|
||||
{
|
||||
if (start == -1) continue;
|
||||
result.Add(text.Substr(start + 1, i - start - 1), 0);
|
||||
start = -1;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
private void FillPlaceholders(Dictionary<string, float> placeholderDictionary, EntityResource resource, Node searchScene)
|
||||
{
|
||||
var searchList = new List<GodotObject>() { resource, searchScene };
|
||||
while (searchList.Count > 0)
|
||||
{
|
||||
var lookedObject = searchList[0];
|
||||
searchList.RemoveAt(0);
|
||||
|
||||
if(lookedObject is Node lookedNode)
|
||||
searchList.AddRange(lookedNode.GetChildren());
|
||||
if (lookedObject is Shooter shooter)
|
||||
{
|
||||
var projectile = shooter._projectile.Instantiate();
|
||||
searchList.Add(projectile);
|
||||
}
|
||||
foreach (var property in lookedObject.GetPropertyList())
|
||||
{
|
||||
if ((Variant.Type)property["type"].AsInt32() == Variant.Type.Object)
|
||||
{
|
||||
if (lookedObject.Get(property["name"].AsString()).AsGodotObject() is Effect effect)
|
||||
{
|
||||
searchList.Add(effect);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var key in placeholderDictionary.Keys)
|
||||
{
|
||||
var namePropertyPair = key.Split('.');
|
||||
Variant property;
|
||||
if (namePropertyPair.Length == 2)
|
||||
{
|
||||
if ((namePropertyPair[0] == "?" && lookedObject != searchScene)||(namePropertyPair[0] != "?" && lookedObject is Node node && node.Name != namePropertyPair[0]))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
property = lookedObject.Get(namePropertyPair[1]);
|
||||
}
|
||||
else
|
||||
{
|
||||
property = lookedObject.Get(namePropertyPair[0]);
|
||||
}
|
||||
if (property.VariantType == Variant.Type.Nil)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
placeholderDictionary[key] = property.As<float>();
|
||||
}
|
||||
}
|
||||
}
|
||||
private string ReplaceTextUsingDict(Dictionary<string, float> dictionary, string text)
|
||||
{
|
||||
var resStr = text;
|
||||
foreach (var key in dictionary.Keys)
|
||||
{
|
||||
resStr = resStr.Replace('{' + key + '}', dictionary[key].ToString());
|
||||
}
|
||||
return resStr;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue