chore: import upstream snapshot with attribution
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
using T3.Core.Utils;
|
||||
|
||||
namespace Lib.@string.buffers.transform;
|
||||
|
||||
[Guid("7dff2da3-30e3-4ad9-bfc6-d6800f90fca8")]
|
||||
internal sealed class StringInsert : Instance<StringInsert>
|
||||
{
|
||||
[Output(Guid = "3f9aa46b-e9d5-43fd-b463-fcdd48ded406")]
|
||||
public readonly Slot<string> Result = new();
|
||||
|
||||
public StringInsert()
|
||||
{
|
||||
Result.UpdateAction += Update;
|
||||
}
|
||||
|
||||
private void Update(EvaluationContext context)
|
||||
{
|
||||
var original = Original.GetValue(context);
|
||||
var insert = Insertion.GetValue(context);
|
||||
if (string.IsNullOrEmpty(original) || string.IsNullOrEmpty(insert))
|
||||
return;
|
||||
|
||||
var maxPosition = original.Length - insert.Length;
|
||||
|
||||
if (maxPosition <= 0)
|
||||
return;
|
||||
|
||||
var position = Position.GetValue(context);
|
||||
|
||||
if (UseModuloPosition.GetValue(context))
|
||||
{
|
||||
position = Math.Abs(position) % maxPosition;
|
||||
}
|
||||
else
|
||||
{
|
||||
position.Clamp(0, maxPosition);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
Result.Value = original.Remove(position, insert.Length).Insert(position, insert);
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
Log.Warning("Failed to insert string:" + e);
|
||||
}
|
||||
}
|
||||
|
||||
[Input(Guid = "11d0a66a-e2e9-4267-9458-f9844a482235")]
|
||||
public readonly InputSlot<string> Original = new();
|
||||
|
||||
[Input(Guid = "b00a60d3-c525-4e65-8b84-2084521d0d2d")]
|
||||
public readonly InputSlot<string> Insertion = new();
|
||||
|
||||
[Input(Guid = "B5709B52-E755-4046-8E71-EEAD5A01303A")]
|
||||
public readonly InputSlot<int> Position = new();
|
||||
|
||||
[Input(Guid = "C103C06D-BF68-4C5C-967E-DDD939221292")]
|
||||
public readonly InputSlot<bool> UseModuloPosition = new();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
{
|
||||
"FormatVersion": 3,
|
||||
"Id": "7dff2da3-30e3-4ad9-bfc6-d6800f90fca8"/*StringInsert*/,
|
||||
"Inputs": [
|
||||
{
|
||||
"Id": "11d0a66a-e2e9-4267-9458-f9844a482235"/*Original*/,
|
||||
"DefaultValue": ""
|
||||
},
|
||||
{
|
||||
"Id": "b00a60d3-c525-4e65-8b84-2084521d0d2d"/*Insertion*/,
|
||||
"DefaultValue": ""
|
||||
},
|
||||
{
|
||||
"Id": "b5709b52-e755-4046-8e71-eead5a01303a"/*Position*/,
|
||||
"DefaultValue": 0
|
||||
},
|
||||
{
|
||||
"Id": "c103c06d-bf68-4c5c-967e-ddd939221292"/*UseModuloPosition*/,
|
||||
"DefaultValue": true
|
||||
}
|
||||
],
|
||||
"Children": [],
|
||||
"Connections": []
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
{
|
||||
"FormatVersion": 3,
|
||||
"Id": "7dff2da3-30e3-4ad9-bfc6-d6800f90fca8"/*StringInsert*/,
|
||||
"Description": "Can replace and move characters to any position within a string",
|
||||
"SymbolTags": "8",
|
||||
"InputUis": [
|
||||
{
|
||||
"InputId": "11d0a66a-e2e9-4267-9458-f9844a482235"/*Original*/,
|
||||
"Position": {
|
||||
"X": 0.0,
|
||||
"Y": 45.0
|
||||
},
|
||||
"Description": "Input for the string into which something is to be inserted",
|
||||
"Usage": "Default"
|
||||
},
|
||||
{
|
||||
"InputId": "b00a60d3-c525-4e65-8b84-2084521d0d2d"/*Insertion*/,
|
||||
"Position": {
|
||||
"X": 0.0,
|
||||
"Y": 90.0
|
||||
},
|
||||
"Description": "String to be inserted into the 'original' string",
|
||||
"Usage": "Default"
|
||||
},
|
||||
{
|
||||
"InputId": "b5709b52-e755-4046-8e71-eead5a01303a"/*Position*/,
|
||||
"Position": {
|
||||
"X": 0.0,
|
||||
"Y": 135.0
|
||||
},
|
||||
"Description": "Defines the position at which the 'Insertion' string is inserted into the 'original' string\n\nThis value can be animated"
|
||||
},
|
||||
{
|
||||
"InputId": "c103c06d-bf68-4c5c-967e-ddd939221292"/*UseModuloPosition*/,
|
||||
"Position": {
|
||||
"X": 0.0,
|
||||
"Y": 180.0
|
||||
},
|
||||
"Description": "If modulo is activated, the string position is looped if the value is too high or too low"
|
||||
}
|
||||
],
|
||||
"SymbolChildUis": [],
|
||||
"OutputUis": [
|
||||
{
|
||||
"OutputId": "3f9aa46b-e9d5-43fd-b463-fcdd48ded406"/*Result*/,
|
||||
"Position": {
|
||||
"X": 0.0,
|
||||
"Y": 0.0
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user