Skip to content

Commit ed1a1ee

Browse files
committed
Batch cleanup
1 parent 657b3a2 commit ed1a1ee

File tree

16 files changed

+90
-54
lines changed

16 files changed

+90
-54
lines changed

Editor/Core/JsonUtility.cs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,7 @@ public class JsonUtility : JsonUtilityShared<FigmaGeneration>
1717
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)]
1818
public static void Initialize()
1919
{
20-
JsonSerializerSettings settings = new()
21-
{
22-
NullValueHandling = NullValueHandling.Ignore
23-
};
20+
JsonSerializerSettings settings = new() { NullValueHandling = NullValueHandling.Ignore };
2421
settings.Converters.Add(new EffectArrayConverter());
2522
settings.Converters.Add(new PaintArrayConverter());
2623
settings.Converters.Add(new LayoutGridArrayConverter());
@@ -192,8 +189,6 @@ protected override SceneNode ToObject(JObject obj, JsonSerializer serializer)
192189
#endregion
193190
}
194191

195-
public class FigmaGeneration
196-
{
197-
}
192+
public class FigmaGeneration { }
198193
}
199194
}

Editor/Core/NodeMetadata.cs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@ class NodeMetadata
1616
{
1717
#region Containers
1818
record RootMetadata(bool filter, UxmlAttribute uxml, UxmlDownloadImages downloadImages);
19+
1920
// ReSharper disable once NotAccessedPositionalProperty.Global
2021
record QueryMetadata(Type fieldType, QueryAttribute query);
22+
2123
record BaseNodeMetadata(RootMetadata root, QueryMetadata query);
2224
#endregion
2325

@@ -39,16 +41,15 @@ void InitializeRootElement(Type elementType)
3941
void InitializeElement(Type type, BaseNode rootNode)
4042
{
4143
BaseNode FindNodeByQuery(QueryAttribute queryRoot, QueryAttribute query, bool throwException) =>
42-
queryRoot is not null && !ReferenceEquals(queryRoot, query) && Find(rootNode, queryRoot.Path, throwException, silent) is { } queryRootNode ?
43-
Find(queryRootNode, query.Path, throwException, silent) :
44-
Find(rootNode, query.Path, throwException, silent);
44+
queryRoot is not null && !ReferenceEquals(queryRoot, query) && Find(rootNode, queryRoot.Path, throwException, silent) is { } queryRootNode ? Find(queryRootNode, query.Path, throwException, silent) : Find(rootNode, query.Path, throwException, silent);
4545

4646
QueryAttribute queryRoot = default;
4747
foreach (FieldInfo field in type.GetFields(FieldsFlags))
4848
{
4949
Type fieldType = field.FieldType;
5050
QueryAttribute query = field.GetCustomAttribute<QueryAttribute>();
5151
if (query is null) continue;
52+
5253
if (query.StartRoot) queryRoot = query;
5354

5455
BaseNode node = FindNodeByQuery(queryRoot, query, throwExceptions && !query.Nullable && query.ReplaceElementPath.NullOrEmpty() && query.RebuildElementEvent.NullOrEmpty());
@@ -88,6 +89,7 @@ internal bool ShouldDownload(BaseNode node, UxmlDownloadImages flag)
8889
if (metadata.query is null) return shouldDownload;
8990
if (metadata.query.query.ImageFiltering == ElementDownloadImage.Download) return true;
9091
if (metadata.query.query.ImageFiltering == ElementDownloadImage.Ignore) return false;
92+
9193
return shouldDownload;
9294
}
9395
internal (bool hash, string value) GetTemplate(BaseNode node)
@@ -174,9 +176,9 @@ ElementType FieldTypeToElementType(Type type)
174176

175177
BaseNodeMetadata metadata = GetMetadata(node);
176178
return metadata.root is not null && metadata.root.filter &&
177-
metadata.root.uxml.TypeIdentification == UxmlElementTypeIdentification.ByElementType && metadata.query is not null ?
178-
(FieldTypeToElementType(metadata.query.fieldType), metadata.query.fieldType!.FullName!.Replace("+", ".")) :
179-
(ElementType.None, default);
179+
metadata.root.uxml.TypeIdentification == UxmlElementTypeIdentification.ByElementType && metadata.query is not null
180+
? (FieldTypeToElementType(metadata.query.fieldType), metadata.query.fieldType!.FullName!.Replace("+", "."))
181+
: (ElementType.None, default);
180182
}
181183
#endregion
182184

@@ -207,6 +209,7 @@ void SearchIn(BaseNode value, string path, int startIndex = 0)
207209
static bool IsVisible(BaseNodeMixin mixin)
208210
{
209211
if (mixin is SceneNodeMixin scene && scene.visible.HasValueAndFalse()) return false;
212+
210213
return mixin.parent is null || IsVisible(mixin.parent);
211214
}
212215
static IReadOnlyCollection<BaseNode> GetChildren(BaseNode value)
@@ -222,6 +225,7 @@ static IReadOnlyCollection<BaseNode> GetChildren(BaseNode value)
222225
children.AddRange(childrenMixin.children);
223226
break;
224227
}
228+
225229
return children;
226230
}
227231
IReadOnlyCollection<BaseNode> children = GetChildren(value);
@@ -241,6 +245,7 @@ void SearchByFullPath(BaseNode value, string path, int startIndex = 0)
241245
static bool IsVisible(BaseNodeMixin mixin)
242246
{
243247
if (mixin is SceneNodeMixin scene && scene.visible.HasValueAndFalse()) return false;
248+
244249
return mixin.parent is null || IsVisible(mixin.parent);
245250
}
246251
static IReadOnlyCollection<BaseNode> GetChildren(BaseNode value)
@@ -249,6 +254,7 @@ static IReadOnlyCollection<BaseNode> GetChildren(BaseNode value)
249254
if (value is DocumentNode documentNode) children.AddRange(documentNode.children);
250255
else if (value is ChildrenMixin childrenMixin) children.AddRange(childrenMixin.children);
251256
else return children;
257+
252258
return children;
253259
}
254260
IReadOnlyCollection<BaseNode> children = GetChildren(value);
@@ -323,6 +329,7 @@ BaseNode FindRootInChildren(BaseNode value)
323329
BaseNode node = FindRootInChildren(child);
324330
if (node is not null) return node;
325331
}
332+
326333
break;
327334

328335
case ChildrenMixin children:
@@ -331,6 +338,7 @@ BaseNode FindRootInChildren(BaseNode value)
331338
BaseNode node = FindRootInChildren(child);
332339
if (node is not null) return node;
333340
}
341+
334342
break;
335343
}
336344

Editor/Extensions/NodeExtensions.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public static void SetParentRecursively(this BaseNode node)
1919
canvas.parent = node;
2020
SetParentRecursively(canvas);
2121
}
22+
2223
break;
2324

2425
case ChildrenMixin { children: not null } children:
@@ -27,6 +28,7 @@ public static void SetParentRecursively(this BaseNode node)
2728
child.parent = node;
2829
SetParentRecursively(child);
2930
}
31+
3032
break;
3133
}
3234
}
@@ -63,4 +65,4 @@ public static string GetHash(this GradientPaint gradient)
6365
}
6466
#endregion
6567
}
66-
}
68+
}

Editor/FigmaParser.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ public static implicit operator LengthProperty(string value)
184184
if (value.Contains("px")) return new LengthProperty(number.Parse(value.ToLower().Replace("px", ""), culture), Unit.Pixel);
185185
if (value.Contains("deg")) return new LengthProperty(number.Parse(value.ToLower().Replace("deg", ""), culture), Unit.Degrees);
186186
if (value.Contains('%')) return new LengthProperty(number.Parse(value.Replace("%", ""), culture), Unit.Percent);
187+
187188
return default;
188189
}
189190
public static implicit operator string(LengthProperty value)
@@ -311,6 +312,7 @@ public static implicit operator string(ColorProperty value)
311312
if (value.rgb.NotNullOrEmpty()) return value.rgb;
312313
if (value.hex.NotNullOrEmpty()) return value.hex;
313314
if (value.name.NotNullOrEmpty()) return value.name;
315+
314316
return "initial";
315317
}
316318
public override string ToString() => this;
@@ -354,6 +356,7 @@ public static implicit operator string(AssetProperty value)
354356
{
355357
if (value.url.NotNullOrEmpty()) return value.url;
356358
if (value.resource.NotNullOrEmpty()) return value.resource;
359+
357360
return value.unit switch
358361
{
359362
Unit.None => "none",
@@ -1023,6 +1026,7 @@ void AddRotation()
10231026
if ((layout.relativeTransform[0][0] == 1 && layout.relativeTransform[0][0] == 0 &&
10241027
layout.relativeTransform[0][0] == 0 && layout.relativeTransform[1][1] == 1) || !layout.relativeTransform[0][0].HasValue ||
10251028
!layout.relativeTransform[0][1].HasValue || !layout.relativeTransform[1][0].HasValue || !layout.relativeTransform[1][1].HasValue) return;
1029+
10261030
float m00 = (float)layout.relativeTransform[0][0].Value;
10271031
float m01 = (float)layout.relativeTransform[0][1].Value;
10281032
int rotation = Mathf.RoundToInt(Mathf.Rad2Deg * Mathf.Acos(m00 / Mathf.Sqrt(m00 * m00 + m01 * m01)));
@@ -1046,6 +1050,7 @@ void AddRotation()
10461050
AddFillStyle(mixin.fills);
10471051

10481052
if (mixin.strokes.Length == 0) return;
1053+
10491054
AddStrokeFillStyle(mixin.strokes);
10501055

10511056
if (!mixin.strokeWeight.HasValue) return;
@@ -1069,9 +1074,11 @@ void AdjustSvgSize()
10691074
layout.absoluteBoundingBox = new Rect(layout.absoluteBoundingBox.x, layout.absoluteBoundingBox.y, width, height);
10701075

10711076
if (geometry.strokes.Length == 0 || geometry.strokeWeight is not > 0) return;
1077+
10721078
layout.absoluteBoundingBox = new Rect(layout.absoluteBoundingBox.x - geometry.strokeWeight.Value / 2, layout.absoluteBoundingBox.y, layout.absoluteBoundingBox.width, layout.absoluteBoundingBox.height);
10731079

10741080
if (geometry.strokeCap is null or StrokeCap.NONE) return;
1081+
10751082
layout.absoluteBoundingBox = new Rect(layout.absoluteBoundingBox.x, layout.absoluteBoundingBox.y - geometry.strokeWeight.Value / 2, layout.absoluteBoundingBox.width, layout.absoluteBoundingBox.height);
10761083
}
10771084
void AddSizeByParentAutoLayoutFromAutoLayout(DefaultFrameMixin frame)
@@ -1531,11 +1538,13 @@ string Get1(string name, string group, int index)
15311538
}
15321539

15331540
if (Has(name)) return attributes[name];
1541+
15341542
throw new NotSupportedException();
15351543
}
15361544
string Get4(string name, params string[] names)
15371545
{
15381546
if (Has(name)) return attributes[name];
1547+
15391548
LengthProperty[] properties = new LengthProperty[4];
15401549
for (int i = 0; i < 4; ++i)
15411550
{
@@ -1632,6 +1641,7 @@ public UssWriter(IEnumerable<UssStyle> styles, IEnumerable<UssStyle> components,
16321641
void Write(UssStyle style)
16331642
{
16341643
if (!style.HasAttributes) return;
1644+
16351645
if (count > 0)
16361646
{
16371647
uss.WriteLine();
@@ -2046,6 +2056,7 @@ void AddImageFillsRecursively(BaseNode node, Func<BaseNode, bool> enabledInHiera
20462056
if (!enabledInHierarchy(node)) return;
20472057

20482058
if (node is BooleanOperationNode) return;
2059+
20492060
if (!IsSvgNode(node) && HasImageFill(node)) ImageFillNodes.Add(node);
20502061

20512062
if (node is ChildrenMixin children)
@@ -2103,6 +2114,7 @@ void AddGradientsRecursively(BaseNode node, Func<BaseNode, bool> enabledInHierar
21032114
}
21042115

21052116
if (node is not ChildrenMixin children) return;
2117+
21062118
foreach (SceneNode child in children.children)
21072119
AddGradientsRecursively(child, enabledInHierarchy);
21082120
}
@@ -2194,6 +2206,7 @@ BaseNode Find(BaseNode root)
21942206
UssStyle GetStyle(BaseNode node)
21952207
{
21962208
if (componentStyleMap.TryGetValue(node, out UssStyle style)) return style;
2209+
21972210
return nodeStyleMap.TryGetValue(node, out style) ? style : default;
21982211
}
21992212
void InheritStylesRecursively(BaseNode node)
@@ -2328,6 +2341,7 @@ string GetClassList(BaseNode node)
23282341
static bool IsVisible(BaseNodeMixin mixin)
23292342
{
23302343
if (mixin is SceneNodeMixin scene && scene.visible.HasValueAndFalse()) return false;
2344+
23312345
return mixin.parent is null || IsVisible(mixin.parent);
23322346
}
23332347
static bool HasImageFill(BaseNodeMixin mixin) => mixin is GeometryMixin geometry && geometry.fills.Any(x => x is ImagePaint);

Editor/Inspector/FigmaInspector.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public class FigmaInspector : Editor
2727
const string documentsOnlyIcon = "d_Refresh@2x";
2828
const string documentWithImagesIcon = "d_RawImage Icon";
2929
const string folderIcon = "d_Project";
30-
static Regex regex = new (@"[^/\\]+$");
30+
static Regex regex = new(@"[^/\\]+$");
3131

3232
#region Fields
3333
SerializedProperty title;
@@ -229,6 +229,7 @@ string GetAssetPath()
229229
Progress.Finish(progress, Progress.Status.Failed);
230230

231231
if (!exception.Message.Contains("404") || exception is not OperationCanceledException) throw;
232+
232233
Debug.LogException(exception);
233234
}
234235
finally

Editor/Inspector/FigmaUpdater.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ void OnPreprocessAsset()
4343

4444
textureImporter.npotScale = TextureImporterNPOTScale.None;
4545
textureImporter.mipmapEnabled = false;
46-
46+
4747
TextureImporterPlatformSettings androidOverrides = textureImporter.GetPlatformTextureSettings("Android");
4848
androidOverrides.overridden = true;
4949
androidOverrides.format = TextureImporterFormat.ETC2_RGBA8Crunched;
@@ -168,6 +168,7 @@ internal void Cleanup(string name)
168168
Debug.LogWarning($"Removing obsolete image {relativePath}");
169169
FileUtil.DeleteFileOrDirectory(path);
170170
}
171+
171172
foreach (string path in Directory.GetFiles(Path.Combine(folder, elements), "*.svg"))
172173
{
173174
string filename = Path.GetFileName(path);
@@ -268,6 +269,7 @@ async Task GetImageAsync(string nodeID, string url, string extension)
268269
await WriteInvalidPngAsync(assetPath);
269270
break;
270271
}
272+
271273
break;
272274

273275
default:
@@ -443,6 +445,7 @@ string GetFontPath(string name, string extension)
443445
{
444446
case "png":
445447
if (!valid) return (false, -1, -1);
448+
446449
TextureImporter importer = (TextureImporter)AssetImporter.GetAtPath(Path.Combine(relativeFolder, path));
447450
importer.GetSourceTextureWidthAndHeight(out int width, out int height);
448451
return (true, width, height);

Editor/Interface/Enums.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
namespace Figma
32
{
43
public enum ElementType

Editor/Interface/Figma.Enums.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-

2-
// ReSharper disable InconsistentNaming
1+
// ReSharper disable InconsistentNaming
32

43
namespace Figma
54
{

0 commit comments

Comments
 (0)