| | 1 | | /* |
| | 2 | | * Copyright (c) 2024 Willy Alberto Kuster |
| | 3 | | * |
| | 4 | | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| | 5 | | * of this software and associated documentation files (the "Software"), to deal |
| | 6 | | * in the Software without restriction, including without limitation the rights |
| | 7 | | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| | 8 | | * copies of the Software, and to permit persons to whom the Software is |
| | 9 | | * furnished to do so, subject to the following conditions: |
| | 10 | | * |
| | 11 | | * The above copyright notice and this permission notice shall be included in |
| | 12 | | * all copies or substantial portions of the Software. |
| | 13 | | * |
| | 14 | | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| | 15 | | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| | 16 | | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| | 17 | | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| | 18 | | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| | 19 | | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| | 20 | | * THE SOFTWARE. |
| | 21 | | */ |
| | 22 | | using Scriban; |
| | 23 | | using Scriban.Runtime; |
| | 24 | | using System; |
| | 25 | | using System.Collections.Generic; |
| | 26 | | using System.IO; |
| | 27 | | using System.Linq; |
| | 28 | |
|
| | 29 | | namespace Willykc.Templ.Editor.Entry |
| | 30 | | { |
| | 31 | | using Abstraction; |
| | 32 | | using static TemplSettings; |
| | 33 | |
|
| | 34 | | internal sealed class TemplEntryCore : ITemplEntryCore |
| | 35 | | { |
| | 36 | | private const string LiveEntriesTitle = "Templ Live Entries"; |
| | 37 | | private const string ProgressBarRenderingInfo = "Rendering..."; |
| | 38 | | private const string TemplChangedKey = "templ.changed"; |
| | 39 | | private const string TemplDeferredKey = "templ.deferred"; |
| | 40 | | private const string OkDialogText = "Remove Live Entries ({0})"; |
| | 41 | | private const string CancelDialogText = "Abort"; |
| | 42 | | private const string DialogMessage = "The '{0}' asset/directory currently referenced by " + |
| | 43 | | LiveEntriesTitle + " is about to be deleted. Press 'Remove Live Entries' to delete " + |
| | 44 | | "the corresponding " + LiveEntriesTitle + ". Press '" + CancelDialogText + "' to " + |
| | 45 | | "cancel the removal of both the asset and the " + LiveEntriesTitle; |
| | 46 | |
|
| | 47 | | private const char AssetPathSeparator = '/'; |
| | 48 | |
|
| | 49 | | private readonly IAssetDatabase assetDatabase; |
| | 50 | | private readonly IFileSystem fileSystem; |
| | 51 | | private readonly ISessionState sessionState; |
| | 52 | | private readonly ILogger log; |
| | 53 | | private readonly ISettingsProvider settingsProvider; |
| | 54 | | private readonly IEditorUtility editorUtility; |
| | 55 | | private readonly List<Type> functions; |
| | 56 | | private readonly string[] functionConflicts; |
| | 57 | | private readonly string[] functionNames; |
| | 58 | |
|
| 73 | 59 | | internal TemplEntryCore( |
| | 60 | | IAssetDatabase assetDatabase, |
| | 61 | | IFileSystem fileSystem, |
| | 62 | | ISessionState sessionState, |
| | 63 | | ILogger log, |
| | 64 | | ISettingsProvider settingsProvider, |
| | 65 | | ITemplateFunctionProvider templateFunctionProvider, |
| | 66 | | IEditorUtility editorUtility) |
| 73 | 67 | | { |
| 73 | 68 | | this.assetDatabase = assetDatabase ?? |
| | 69 | | throw new ArgumentNullException(nameof(assetDatabase)); |
| 73 | 70 | | this.fileSystem = fileSystem ?? |
| | 71 | | throw new ArgumentNullException(nameof(fileSystem)); |
| 73 | 72 | | this.sessionState = sessionState ?? |
| | 73 | | throw new ArgumentNullException(nameof(sessionState)); |
| 73 | 74 | | this.log = log ?? |
| | 75 | | throw new ArgumentNullException(nameof(log)); |
| 73 | 76 | | this.settingsProvider = settingsProvider ?? |
| | 77 | | throw new ArgumentNullException(nameof(settingsProvider)); |
| 73 | 78 | | this.editorUtility = editorUtility ?? |
| | 79 | | throw new ArgumentNullException(nameof(editorUtility)); |
| 73 | 80 | | templateFunctionProvider = templateFunctionProvider ?? |
| | 81 | | throw new ArgumentNullException(nameof(templateFunctionProvider)); |
| | 82 | |
|
| 73 | 83 | | functions = templateFunctionProvider.GetTemplateFunctionTypes().ToList(); |
| 73 | 84 | | functionConflicts = templateFunctionProvider.GetDuplicateTemplateFunctionNames(); |
| 73 | 85 | | functionNames = templateFunctionProvider.GetTemplateFunctionNames(); |
| | 86 | |
|
| 73 | 87 | | if (functionConflicts.Length > 0) |
| 12 | 88 | | { |
| 12 | 89 | | log.Error("Function name conflicts detected: " + |
| | 90 | | string.Join(", ", functionConflicts)); |
| 12 | 91 | | } |
| 73 | 92 | | } |
| | 93 | |
|
| | 94 | | void ITemplEntryCore.OnAssetsChanged(AssetsPaths changes) |
| 159 | 95 | | { |
| 159 | 96 | | if (!settingsProvider.SettingsExist() || FunctionConflictsDetected()) |
| 144 | 97 | | { |
| 144 | 98 | | return; |
| | 99 | | } |
| | 100 | |
|
| 15 | 101 | | if (IsSettingsChanged(changes)) |
| 2 | 102 | | { |
| 2 | 103 | | RenderChangedEntries(); |
| 2 | 104 | | return; |
| | 105 | | } |
| | 106 | |
|
| 13 | 107 | | var eagerDeferred = GetEagerDeferredEntries(); |
| 13 | 108 | | var entriesToRender = settingsProvider.GetSettings().ValidEntries |
| 304 | 109 | | .Where(e => DecomposeChanges(changes, e).Any(c => e.ShouldRender(c))) |
| | 110 | | .Union(eagerDeferred) |
| | 111 | | .Distinct(); |
| | 112 | |
|
| 13 | 113 | | FlagDeferredEntries(entriesToRender, changes); |
| 13 | 114 | | RenderEagerEntries(entriesToRender, changes); |
| 159 | 115 | | } |
| | 116 | |
|
| | 117 | | void ITemplEntryCore.OnAfterAssemblyReload() |
| 6 | 118 | | { |
| 6 | 119 | | if (!settingsProvider.SettingsExist() || FunctionConflictsDetected()) |
| 3 | 120 | | { |
| 3 | 121 | | return; |
| | 122 | | } |
| | 123 | |
|
| 3 | 124 | | var deferred = sessionState.GetString(TemplDeferredKey); |
| | 125 | |
|
| 3 | 126 | | if (string.IsNullOrWhiteSpace(deferred)) |
| 1 | 127 | | { |
| 1 | 128 | | return; |
| | 129 | | } |
| | 130 | |
|
| 2 | 131 | | var deferredEntries = settingsProvider.GetSettings().ValidEntries |
| 10 | 132 | | .Where(e => deferred.Contains(e.Id)); |
| 2 | 133 | | RenderEntries(deferredEntries); |
| 2 | 134 | | sessionState.EraseString(TemplDeferredKey); |
| 6 | 135 | | } |
| | 136 | |
|
| | 137 | | bool ITemplEntryCore.OnWillDeleteAsset(string path) |
| 85 | 138 | | { |
| 85 | 139 | | if (!settingsProvider.SettingsExist() || FunctionConflictsDetected()) |
| 73 | 140 | | { |
| 73 | 141 | | return true; |
| | 142 | | } |
| | 143 | |
|
| 12 | 144 | | var settings = settingsProvider.GetSettings(); |
| | 145 | |
|
| 12 | 146 | | var referencedEntries = settings.Entries |
| 24 | 147 | | .Where(e => IsPathReferencedByEntry(e, path)) |
| | 148 | | .ToList(); |
| | 149 | |
|
| 12 | 150 | | if (referencedEntries.Count > 0) |
| 8 | 151 | | { |
| 8 | 152 | | var agreedToRemoveEntries = HandleRequestToRemoveLiveEntries(path, settings, |
| | 153 | | referencedEntries); |
| 8 | 154 | | return agreedToRemoveEntries; |
| | 155 | | } |
| | 156 | |
|
| 4 | 157 | | FlagInputDeletedEntries(path); |
| 4 | 158 | | return true; |
| 85 | 159 | | } |
| | 160 | |
|
| | 161 | | void ITemplEntryCore.FlagChangedEntry(TemplEntry entry) |
| 4 | 162 | | { |
| 4 | 163 | | if (entry == null) |
| 1 | 164 | | { |
| 1 | 165 | | return; |
| | 166 | | } |
| | 167 | |
|
| 3 | 168 | | var existing = sessionState.GetString(TemplChangedKey); |
| | 169 | |
|
| 3 | 170 | | if (!existing.Contains(entry.Id)) |
| 2 | 171 | | { |
| 2 | 172 | | sessionState.SetString(TemplChangedKey, existing + entry.Id); |
| 2 | 173 | | } |
| 4 | 174 | | } |
| | 175 | |
|
| | 176 | | void ITemplEntryCore.RenderAllValidEntries() |
| 15 | 177 | | { |
| 15 | 178 | | if (!settingsProvider.SettingsExist() || FunctionConflictsDetected()) |
| 3 | 179 | | { |
| 3 | 180 | | return; |
| | 181 | | } |
| | 182 | |
|
| 12 | 183 | | RenderEntries(settingsProvider.GetSettings().ValidEntries); |
| 15 | 184 | | } |
| | 185 | |
|
| | 186 | | void ITemplEntryCore.RenderEntry(string id) |
| 12 | 187 | | { |
| 12 | 188 | | if (!settingsProvider.SettingsExist() || FunctionConflictsDetected()) |
| 3 | 189 | | { |
| 3 | 190 | | return; |
| | 191 | | } |
| | 192 | |
|
| 20 | 193 | | var entry = settingsProvider.GetSettings().ValidEntries.FirstOrDefault(e => e.Id == id); |
| | 194 | |
|
| 9 | 195 | | if (entry == null) |
| 4 | 196 | | { |
| 4 | 197 | | log.Error($"Could not find valid entry with id '{id}'"); |
| 4 | 198 | | return; |
| | 199 | | } |
| | 200 | |
|
| 5 | 201 | | RenderEntries(new[] { entry }); |
| 12 | 202 | | } |
| | 203 | |
|
| | 204 | | private bool HandleRequestToRemoveLiveEntries(string path, TemplSettings settings, |
| | 205 | | List<TemplEntry> referencedEntries) |
| 8 | 206 | | { |
| 8 | 207 | | var message = string.Format(DialogMessage, path); |
| 8 | 208 | | var okText = string.Format(OkDialogText, referencedEntries.Count); |
| 8 | 209 | | var agreedToRemoveEntries = editorUtility.DisplayDialog(LiveEntriesTitle, message, |
| | 210 | | okText, CancelDialogText); |
| | 211 | |
|
| 8 | 212 | | if (agreedToRemoveEntries) |
| 4 | 213 | | { |
| 12 | 214 | | referencedEntries.ForEach(e => settings.Entries.Remove(e)); |
| | 215 | |
|
| 4 | 216 | | editorUtility.SetDirty(settings); |
| 4 | 217 | | assetDatabase.SaveAssets(); |
| 4 | 218 | | } |
| | 219 | |
|
| 8 | 220 | | return agreedToRemoveEntries; |
| 8 | 221 | | } |
| | 222 | |
|
| | 223 | | private IList<TemplEntry> GetEagerDeferredEntries() |
| 13 | 224 | | { |
| 13 | 225 | | var deferred = sessionState.GetString(TemplDeferredKey); |
| | 226 | |
|
| 13 | 227 | | if (string.IsNullOrEmpty(deferred)) |
| 9 | 228 | | { |
| 9 | 229 | | return EmptyEntryArray; |
| | 230 | | } |
| | 231 | |
|
| 4 | 232 | | var eagerDeferred = settingsProvider.GetSettings().ValidEntries |
| 8 | 233 | | .Where(e => !e.Deferred && deferred.Contains(e.Id)) |
| | 234 | | .ToList(); |
| 4 | 235 | | deferred = eagerDeferred |
| 2 | 236 | | .Select(e => e.Id) |
| 2 | 237 | | .Aggregate(deferred, (result, next) => result.Replace(next, string.Empty)); |
| 4 | 238 | | sessionState.SetString(TemplDeferredKey, deferred); |
| 4 | 239 | | return eagerDeferred; |
| 13 | 240 | | } |
| | 241 | |
|
| 24 | 242 | | private bool IsPathReferencedByEntry(TemplEntry entry, string path) => (new[] |
| | 243 | | { |
| | 244 | | assetDatabase.GetAssetPath(entry.InputAsset), |
| | 245 | | assetDatabase.GetAssetPath(entry.Directory), |
| | 246 | | assetDatabase.GetAssetPath(entry.Template) |
| 52 | 247 | | }).Any(p => !string.IsNullOrEmpty(p) && IsMatchPath(path, p)); |
| | 248 | |
|
| | 249 | | private bool FunctionConflictsDetected() |
| 61 | 250 | | { |
| 61 | 251 | | if (functionConflicts.Length > 0 || functionNames.Contains(NameOfOutputAssetPath)) |
| 10 | 252 | | { |
| 10 | 253 | | log.Error("Templates will not render due to function name conflicts"); |
| 10 | 254 | | return true; |
| | 255 | | } |
| | 256 | |
|
| 51 | 257 | | return false; |
| 61 | 258 | | } |
| | 259 | |
|
| | 260 | | private bool IsSettingsChanged(AssetsPaths changes) |
| 15 | 261 | | { |
| 15 | 262 | | var settingsPath = assetDatabase.GetAssetPath(settingsProvider.GetSettings()); |
| 15 | 263 | | return changes.importedAssets.Contains(settingsPath); |
| 15 | 264 | | } |
| | 265 | |
|
| | 266 | | private void RenderChangedEntries() |
| 2 | 267 | | { |
| 2 | 268 | | var changed = sessionState.GetString(TemplChangedKey); |
| | 269 | |
|
| 2 | 270 | | if (string.IsNullOrWhiteSpace(changed)) |
| 1 | 271 | | { |
| 1 | 272 | | return; |
| | 273 | | } |
| | 274 | |
|
| 1 | 275 | | var entriesToRender = settingsProvider.GetSettings().ValidEntries |
| 5 | 276 | | .Where(e => changed.Contains(e.Id)); |
| 1 | 277 | | RenderEntries(entriesToRender); |
| 1 | 278 | | sessionState.EraseString(TemplChangedKey); |
| 2 | 279 | | } |
| | 280 | |
|
| | 281 | | private void FlagDeferredEntries(IEnumerable<TemplEntry> entries, AssetsPaths changes) |
| 13 | 282 | | { |
| 13 | 283 | | var deferred = entries |
| 13 | 284 | | .Where(e => e.Deferred && |
| 8 | 285 | | DecomposeChanges(changes, e).All(c => !e.IsTemplateChanged(c))) |
| 2 | 286 | | .Select(e => e.Id); |
| 13 | 287 | | var deferredFlags = string.Concat(deferred); |
| | 288 | |
|
| 13 | 289 | | if (!string.IsNullOrWhiteSpace(deferredFlags)) |
| 2 | 290 | | { |
| 2 | 291 | | sessionState.SetString(TemplDeferredKey, deferredFlags); |
| 2 | 292 | | } |
| 13 | 293 | | } |
| | 294 | |
|
| | 295 | | private void FlagInputDeletedEntries(string path) |
| 4 | 296 | | { |
| 4 | 297 | | var deferred = settingsProvider.GetSettings().ValidEntries |
| 8 | 298 | | .Where(e => e.ShouldRender(new AssetChange(ChangeType.Delete, path))) |
| 1 | 299 | | .Select(e => e.Id); |
| 4 | 300 | | var deferredFlags = string.Concat(deferred); |
| | 301 | |
|
| 4 | 302 | | if (!string.IsNullOrWhiteSpace(deferredFlags)) |
| 1 | 303 | | { |
| 1 | 304 | | sessionState.SetString(TemplDeferredKey, deferredFlags); |
| 1 | 305 | | } |
| 4 | 306 | | } |
| | 307 | |
|
| | 308 | | private void RenderEagerEntries( |
| | 309 | | IEnumerable<TemplEntry> entries, |
| | 310 | | AssetsPaths changes) |
| 13 | 311 | | { |
| 13 | 312 | | var entriesToRenderNow = entries |
| 37 | 313 | | .Where(e => !e.Deferred || |
| 24 | 314 | | DecomposeChanges(changes, e).Any(c => e.IsTemplateChanged(c))); |
| 13 | 315 | | RenderEntries(entriesToRenderNow); |
| 13 | 316 | | } |
| | 317 | |
|
| | 318 | | private void RenderEntries(IEnumerable<TemplEntry> entriesToRender) |
| 33 | 319 | | { |
| 33 | 320 | | var inputPaths = settingsProvider.GetSettings().ValidEntries |
| 66 | 321 | | .Select(e => assetDatabase.GetAssetPath(e.InputAsset)) |
| | 322 | | .ToArray(); |
| 33 | 323 | | var templatePaths = settingsProvider.GetSettings().ValidEntries |
| 66 | 324 | | .Select(e => assetDatabase.GetAssetPath(e.Template)) |
| | 325 | | .ToArray(); |
| | 326 | |
|
| | 327 | | try |
| 33 | 328 | | { |
| 33 | 329 | | RenderEntriesWithProgress(entriesToRender, inputPaths, templatePaths); |
| 33 | 330 | | } |
| | 331 | | finally |
| 33 | 332 | | { |
| 33 | 333 | | editorUtility.ClearProgressBar(); |
| 33 | 334 | | } |
| | 335 | |
|
| 33 | 336 | | if (entriesToRender.Any() && settingsProvider.GetSettings().HasInvalidEntries) |
| 2 | 337 | | { |
| 2 | 338 | | log.Warn("Invalid live entries found in settings"); |
| 2 | 339 | | } |
| 33 | 340 | | } |
| | 341 | |
|
| | 342 | | private void RenderEntriesWithProgress( |
| | 343 | | IEnumerable<TemplEntry> entriesToRender, |
| | 344 | | string[] inputPaths, |
| | 345 | | string[] templatePaths) |
| 33 | 346 | | { |
| 33 | 347 | | var entryCount = entriesToRender.Count(); |
| | 348 | |
|
| 187 | 349 | | foreach (var (entry, index) in entriesToRender.Select(GetEntryWithIndex)) |
| 44 | 350 | | { |
| 44 | 351 | | editorUtility.DisplayProgressBar( |
| | 352 | | LiveEntriesTitle, |
| | 353 | | ProgressBarRenderingInfo, |
| | 354 | | (float)index / entryCount); |
| 44 | 355 | | RenderEntry(entry, inputPaths, templatePaths); |
| 44 | 356 | | } |
| 33 | 357 | | } |
| | 358 | |
|
| | 359 | | private void RenderEntry(TemplEntry entry, string[] inputPaths, string[] templatePaths) |
| 44 | 360 | | { |
| 44 | 361 | | if (!CheckOverrides(entry, inputPaths, templatePaths)) |
| 6 | 362 | | { |
| 6 | 363 | | return; |
| | 364 | | } |
| | 365 | |
|
| 38 | 366 | | if (entry.ExposedInputName == NameOfOutputAssetPath) |
| 1 | 367 | | { |
| 1 | 368 | | log.Error("Entry input name must not be reserved " + |
| | 369 | | $"keyword: {NameOfOutputAssetPath}"); |
| 1 | 370 | | return; |
| | 371 | | } |
| | 372 | |
|
| | 373 | | try |
| 37 | 374 | | { |
| 37 | 375 | | var context = GetContext(entry); |
| 37 | 376 | | var template = Template.Parse(entry.Template.Text); |
| 37 | 377 | | var result = template.Render(context); |
| 33 | 378 | | fileSystem.WriteAllText(entry.FullPath, result); |
| 33 | 379 | | assetDatabase.ImportAsset(entry.OutputAssetPath); |
| 33 | 380 | | log.Info($"Template rendered at {entry.OutputAssetPath}"); |
| 33 | 381 | | } |
| 4 | 382 | | catch (Exception e) |
| 4 | 383 | | { |
| 4 | 384 | | log.Error($"Error while rendering template at {entry.OutputAssetPath}", e); |
| 4 | 385 | | } |
| 44 | 386 | | } |
| | 387 | |
|
| | 388 | | private bool CheckOverrides(TemplEntry entry, string[] inputPaths, string[] templatePaths) |
| 44 | 389 | | { |
| 44 | 390 | | if (inputPaths.Contains(entry.OutputAssetPath)) |
| 2 | 391 | | { |
| 2 | 392 | | log.Error("Overwriting an input in settings is not allowed. " + |
| | 393 | | $"Did not render template at {entry.OutputAssetPath}"); |
| 2 | 394 | | return false; |
| | 395 | | } |
| | 396 | |
|
| 42 | 397 | | if (templatePaths.Contains(entry.OutputAssetPath)) |
| 2 | 398 | | { |
| 2 | 399 | | log.Error("Overwriting a template in settings is not allowed. " + |
| | 400 | | $"Did not render template at {entry.OutputAssetPath}"); |
| 2 | 401 | | return false; |
| | 402 | | } |
| | 403 | |
|
| 40 | 404 | | if (entry.OutputAssetPath == assetDatabase.GetAssetPath(settingsProvider.GetSettings())) |
| 2 | 405 | | { |
| 2 | 406 | | log.Error("Overwriting settings is not allowed. " + |
| | 407 | | $"Did not render template at {entry.OutputAssetPath}"); |
| 2 | 408 | | return false; |
| | 409 | | } |
| | 410 | |
|
| 38 | 411 | | return true; |
| 44 | 412 | | } |
| | 413 | |
|
| | 414 | | private TemplateContext GetContext(TemplEntry entry) |
| 37 | 415 | | { |
| 37 | 416 | | var scriptObject = new ScriptObject(); |
| 1073 | 417 | | scriptObject.Import(typeof(TemplFunctions), renamer: member => member.Name); |
| 37 | 418 | | functions.ForEach(t => scriptObject.Import(t, renamer: member => member.Name)); |
| 37 | 419 | | scriptObject.Add(entry.ExposedInputName, entry.TheInputValue); |
| 37 | 420 | | scriptObject.Add(NameOfOutputAssetPath, entry.OutputAssetPath); |
| | 421 | |
|
| 37 | 422 | | var context = new TemplateContext() |
| | 423 | | { |
| | 424 | | TemplateLoader = AssetTemplateLoader.Instance |
| | 425 | | }; |
| | 426 | |
|
| 37 | 427 | | context.PushGlobal(scriptObject); |
| 37 | 428 | | return context; |
| 37 | 429 | | } |
| | 430 | |
|
| | 431 | | private static bool IsMatchPath(string path, string entryPath) => |
| 20 | 432 | | entryPath == path || |
| | 433 | | GetAssetDirectoryPath(entryPath).StartsWith(path); |
| | 434 | |
|
| | 435 | | private static string GetAssetDirectoryPath(string path) => |
| 8 | 436 | | Path.GetDirectoryName(path).Replace(Path.DirectorySeparatorChar, AssetPathSeparator); |
| | 437 | |
|
| | 438 | | private static (TemplEntry, int) GetEntryWithIndex(TemplEntry entry, int index) => |
| 44 | 439 | | (entry, index); |
| | 440 | |
|
| | 441 | | private static AssetChange[] DecomposeChanges(AssetsPaths changes, TemplEntry entry) |
| 113 | 442 | | { |
| 113 | 443 | | var imported = entry.DeclaresChangeType(ChangeType.Import) |
| 113 | 444 | | ? changes.importedAssets.Select(p => new AssetChange(ChangeType.Import, p)) |
| | 445 | | : EmptyAssetChangeArray; |
| 113 | 446 | | var moved = entry.DeclaresChangeType(ChangeType.Move) |
| | 447 | | ? changes.movedAssets.Select((p, i) => |
| 113 | 448 | | new AssetChange(ChangeType.Move, p, changes.movedFromAssetPaths[i])) |
| | 449 | | : EmptyAssetChangeArray; |
| 113 | 450 | | var deleted = entry.DeclaresChangeType(ChangeType.Delete) |
| 113 | 451 | | ? changes.deletedAssets.Select(p => new AssetChange(ChangeType.Delete, p)) |
| | 452 | | : EmptyAssetChangeArray; |
| 113 | 453 | | return imported |
| | 454 | | .Union(moved) |
| | 455 | | .Union(deleted) |
| | 456 | | .ToArray(); |
| 113 | 457 | | } |
| | 458 | | } |
| | 459 | | } |