private List <TreeNode> NodesForAssetRegistry(AssetRegistry registry) { var registry_tNodes = new List <TreeNode>(); var nodesByScene = registry.Nodes.GroupBy(x => x.Scene); foreach (var scene in nodesByScene) { var sceneName = scene.FirstOrDefault().Scene; var scene_tNodes = new List <TreeNode>(); var nodesByZones = scene.GroupBy(x => x.Zone); foreach (var zone in nodesByZones) { var zoneName = zone.FirstOrDefault().Zone; var zone_tNodes = new List <TreeNode>(); var orderedNodes = zone.OrderBy(x => x.Number); foreach (var node in orderedNodes) { var nodeName = node.Number; var treeNode = new TreeNode(nodeName); treeNode.Tag = node; zone_tNodes.Add(treeNode); } scene_tNodes.Add(new TreeNode(zoneName, zone_tNodes.ToArray())); } registry_tNodes.Add(new TreeNode(sceneName, scene_tNodes.ToArray())); } return(registry_tNodes); }
private static LocalContextToken PrepareLocalContext(Type type) { var token = new LocalContextToken { Type = type, OldContext = LocalContext.Value, ClearLocalContext = false }; if (typeof(AssetComposite).IsAssignableFrom(token.Type)) { // Entering the asset root node, create the local context. LocalContext.Value = new AssetCompositeVisitorContext(token.Type); token.ClearLocalContext = true; } else if (LocalContext.Value == null && AssetRegistry.IsAssetPartType(token.Type)) { var attributes = AssetRegistry.GetPartReferenceAttributes(token.Type); LocalContext.Value = new AssetCompositeVisitorContext(attributes); token.ClearLocalContext = true; } token.RemoveLastEnteredNode = LocalContext.Value?.EnterNode(token.Type) ?? false; return(token); }
public override async Task <DialogResult> ShowModal() { if (AcceptedTypes.Count > 0) { // Gather all registered asset types that are assignable to the given accepted types var assetTypes = AssetRegistry.GetPublicTypes().Where(x => AcceptedTypes.Any(y => y.IsAssignableFrom(x))).ToList(); // Retrieve the filters that then match the collected asset types var activeFilters = AssetView.TypeFilters.Where(f => assetTypes.Any(t => string.Equals(t.FullName, f.Filter))); foreach (var filter in activeFilters) { filter.IsReadOnly = true; // prevent the user from removing or deactivating the filter AssetView.AddAssetFilter(filter); } } selectedAssets.Clear(); await base.ShowModal(); if (Result == Presentation.Services.DialogResult.Ok) { selectedAssets.AddRange(AssetView.SelectedAssets); } return(Result); }
/// <inheritdoc/> public override void WriteYaml(ref ObjectContext objectContext) { var type = objectContext.Descriptor.Type; bool clearLocalContext = false; // Entering the asset root node, create the local context. if (typeof(AssetComposite).IsAssignableFrom(type)) { localContext.Value = new AssetCompositeVisitorContext(type); clearLocalContext = true; } else if (localContext.Value == null && AssetRegistry.IsAssetPartType(type)) { var attributes = AssetRegistry.GetPartReferenceAttributes(type); localContext.Value = new AssetCompositeVisitorContext(attributes); clearLocalContext = true; } var removeLastEnteredType = localContext.Value?.EnterNode(type) ?? false; try { base.WriteYaml(ref objectContext); } finally { localContext.Value?.LeaveNode(type, removeLastEnteredType); if (clearLocalContext) { localContext.Value = null; } } }
/// <inheritdoc/> public override bool UpgradeAfterAssetsLoaded(PackageLoadParameters loadParameters, PackageSession session, ILogger log, Package dependentPackage, PackageDependency dependency, Package dependencyPackage, PackageVersionRange dependencyVersionBeforeUpdate) { if (dependencyVersionBeforeUpdate.MinVersion < new PackageVersion("1.3.0-alpha02")) { // Add everything as root assets (since we don't know what the project was doing in the code before) foreach (var assetItem in dependentPackage.Assets) { if (!AssetRegistry.IsAssetTypeAlwaysMarkAsRoot(assetItem.Asset.GetType())) { dependentPackage.RootAssets.Add(new AssetReference(assetItem.Id, assetItem.Location)); } } } if (dependencyVersionBeforeUpdate.MinVersion < new PackageVersion("1.6.0-beta")) { // Mark all assets dirty to force a resave foreach (var assetItem in dependentPackage.Assets) { if (!(assetItem.Asset is SourceCodeAsset)) { assetItem.IsDirty = true; } } } return(true); }
protected override IEnumerable <AssetItem> CreateAssets(AssetTemplateGeneratorParameters parameters) { var files = parameters.Tags.Get(SourceFilesPathKey); if (files == null) { return(base.CreateAssets(parameters)); } var importParameters = new AssetImporterParameters { Logger = parameters.Logger }; importParameters.SelectedOutputTypes.Add(typeof(SkeletonAsset), true); var importedAssets = new List <AssetItem>(); foreach (var file in files) { // TODO: should we allow to select the importer? var importer = AssetRegistry.FindImporterForFile(file).OfType <ModelAssetImporter>().FirstOrDefault(); if (importer == null) { parameters.Logger.Warning($"No importer found for file \"{file}\""); continue; } var assets = importer.Import(file, importParameters).Select(x => new AssetItem(UPath.Combine(parameters.TargetLocation, x.Location), x.Asset)).ToList(); // Create unique names amongst the list of assets importedAssets.AddRange(MakeUniqueNames(assets)); } return(importedAssets); }
public AssetNodeContainer() { NodeBuilder.RegisterPrimitiveType(typeof(IReference)); NodeBuilder.RegisterPrimitiveType(typeof(PropertyKey)); NodeBuilder.RegisterPrimitiveType(typeof(TimeSpan)); NodeBuilder.RegisterPrimitiveType(typeof(DateTime)); NodeBuilder.RegisterPrimitiveType(typeof(Guid)); NodeBuilder.RegisterPrimitiveType(typeof(AssetId)); NodeBuilder.RegisterPrimitiveType(typeof(Color)); NodeBuilder.RegisterPrimitiveType(typeof(Color3)); NodeBuilder.RegisterPrimitiveType(typeof(Color4)); NodeBuilder.RegisterPrimitiveType(typeof(Vector2)); NodeBuilder.RegisterPrimitiveType(typeof(Vector3)); NodeBuilder.RegisterPrimitiveType(typeof(Vector4)); NodeBuilder.RegisterPrimitiveType(typeof(Int2)); NodeBuilder.RegisterPrimitiveType(typeof(Int3)); NodeBuilder.RegisterPrimitiveType(typeof(Int4)); NodeBuilder.RegisterPrimitiveType(typeof(Quaternion)); NodeBuilder.RegisterPrimitiveType(typeof(RectangleF)); NodeBuilder.RegisterPrimitiveType(typeof(Rectangle)); NodeBuilder.RegisterPrimitiveType(typeof(Matrix)); NodeBuilder.RegisterPrimitiveType(typeof(UPath)); NodeBuilder.RegisterPrimitiveType(typeof(AngleSingle)); // Register content types as primitive so they are not processed by Quantum foreach (var contentType in AssetRegistry.GetContentTypes()) { NodeBuilder.RegisterPrimitiveType(contentType); } }
private async Task UpdateGameSideReference([NotNull] AssetCompositeEditorViewModel editor, [NotNull] IGraphNode gameSideNode, ContentChangeType changeType, object oldValue, object newValue, NodeIndex index) { if (editor == null) { throw new ArgumentNullException(nameof(editor)); } if (!AssetRegistry.IsContentType(gameSideNode.Descriptor.GetInnerCollectionType())) { return; } // Grab the old referenced object if it's not null AttachedReference reference = null; if (!ReferenceEquals(oldValue, null)) { reference = AttachedReferenceManager.GetAttachedReference(oldValue); } // Switch to game thread to actually update objects await editor.Controller.InvokeTask(() => { // For references, push null instead of the real value, the editor asset loader will set the actual value later switch (changeType) { case ContentChangeType.ValueChange: ((IMemberNode)gameSideNode).Update(null); break; case ContentChangeType.CollectionUpdate: ((IObjectNode)gameSideNode).Update(null, index); break; case ContentChangeType.CollectionAdd: ((IObjectNode)gameSideNode).Add(null, index); break; case ContentChangeType.CollectionRemove: var oldValueGameSide = gameSideNode.Retrieve(index); ((IObjectNode)gameSideNode).Remove(oldValueGameSide, index); break; default: throw new ArgumentOutOfRangeException(nameof(changeType), changeType, null); } if (oldValue == newValue) { return(Task.CompletedTask); } // Unregister the previous value if (reference != null) { return(editor.Controller.Loader.Manager.ClearContentReference(Owner.Id, reference.Id, gameSideNode, index)); } return(Task.CompletedTask); }); }
public override async Task <AssetViewModel> PickupObject(AssetViewModel objectToFix, object referencedMember) { var assetPicker = ServiceProvider.Get <IEditorDialogService>().CreateAssetPickerDialog(objectToFix.Session); assetPicker.Message = "Select an asset to replace the deleted asset"; assetPicker.Filter = x => !IsInObjectsToFixList(x); assetPicker.InitialLocation = objectToFix.Directory; assetPicker.AllowMultiSelection = false; Type assetType = objectToFix.AssetType; var contentType = AssetRegistry.GetContentType(objectToFix.AssetType); if (contentType != null) { var assetTypes = AssetRegistry.GetAssetTypes(contentType); assetPicker.AcceptedTypes.AddRange(assetTypes); } else { assetPicker.AcceptedTypes.Add(assetType); } var result = await assetPicker.ShowModal(); return(result == DialogResult.Ok ? assetPicker.SelectedAssets.First() : null); }
public object Load(Stream stream, UFile filePath, ILogger log, bool clearBrokenObjectReferences, out bool aliasOccurred, out AttachedYamlAssetMetadata yamlMetadata) { aliasOccurred = false; var assetFileExtension = filePath.GetFileExtension().ToLowerInvariant(); var type = AssetRegistry.GetAssetTypeFromFileExtension(assetFileExtension); var asset = (SourceCodeAsset)Activator.CreateInstance(type); var textAccessor = asset.TextAccessor as DefaultTextAccessor; if (textAccessor != null) { // Don't load the file if we have the file path textAccessor.FilePath = filePath; // Set the assets text if it loaded from an in-memory version // TODO: Propagate dirtiness? if (stream is MemoryStream) { var reader = new StreamReader(stream, Encoding.UTF8); textAccessor.Set(reader.ReadToEnd()); } } // No override in source code assets yamlMetadata = new AttachedYamlAssetMetadata(); return(asset); }
public void Initialize() { AssetRegistry.RegisterAssembly(typeof(ModelAsset).Assembly); AssetRegistry.RegisterAssembly(typeof(MaterialDescription).Assembly); AssetRegistry.RegisterAssembly(typeof(Color4).Assembly); AssetRegistry.RegisterAssembly(typeof(MaterialParameters).Assembly); }
public override void Update(GameEngine engine, GameTime gameTime) { if (_firstRun) { List <Asset.Asset> assetsToLoad = AssetRegistry.GetAssetsToLoad(); AssetLoader.LoadQueue.AddAll(assetsToLoad); _totalAssetsToLoad = AssetLoader.LoadQueue.GetSize(); _currentlyLoaded = 0; _loadedEverything = _currentlyLoaded == _totalAssetsToLoad; _firstRun = false; } if (!_loadedEverything) { AssetLoader.LoadQueue.LoadNext(); _currentlyLoaded++; _loadedEverything |= _currentlyLoaded == _totalAssetsToLoad; } if (!IsAssetLoaded()) { return; } MapTileTextures.Initialise(); PlayerUnitAssets.Initialise(); engine.EnterState(StateId.Gameplay); }
public object Load(Stream stream, string filePath, ILogger log, out bool aliasOccurred) { aliasOccurred = false; var assetFileExtension = Path.GetExtension(filePath).ToLowerInvariant(); var type = AssetRegistry.GetAssetTypeFromFileExtension(assetFileExtension); var asset = (SourceCodeAsset)Activator.CreateInstance(type); var textAccessor = asset.TextAccessor as SourceCodeAsset.DefaultTextAccessor; if (textAccessor != null) { // Don't load the file if we have the file path textAccessor.FilePath = filePath; // Set the assets text if it loaded from an in-memory version // TODO: Propagate dirtiness? if (stream is MemoryStream) { var reader = new StreamReader(stream, Encoding.UTF8); textAccessor.Set(reader.ReadToEnd()); } } return(asset); }
protected override void VisitNode(IGraphNode node) { var assetNode = (IAssetNode)node; // TODO: share the proper const var gameContent = assetNode.GetContent("Game"); if (gameContent != null) { var memberContent = node as IMemberNode; if (memberContent != null) { if (AssetRegistry.IsContentType(memberContent.Type)) { var id = AttachedReferenceManager.GetAttachedReference(memberContent.Retrieve())?.Id ?? AssetId.Empty; CollectContentReference(id, gameContent, NodeIndex.Empty); } } var objectNode = node as IObjectNode; if (objectNode != null && objectNode.Indices != null) { if (AssetRegistry.IsContentType(objectNode.Descriptor.GetInnerCollectionType())) { foreach (var index in objectNode.Indices) { var id = AttachedReferenceManager.GetAttachedReference(objectNode.Retrieve(index))?.Id ?? AssetId.Empty; CollectContentReference(id, gameContent, index); } } } } base.VisitNode(node); }
public AssetNodeContainer() { NodeBuilder.AvailableCommands.Add(new AddNewItemCommand()); NodeBuilder.AvailableCommands.Add(new AddPrimitiveKeyCommand()); NodeBuilder.AvailableCommands.Add(new CreateNewInstanceCommand()); NodeBuilder.AvailableCommands.Add(new RemoveItemCommand()); NodeBuilder.AvailableCommands.Add(new MoveItemCommand()); NodeBuilder.AvailableCommands.Add(new RenameStringKeyCommand()); NodeBuilder.RegisterPrimitiveType(typeof(IReference)); NodeBuilder.RegisterPrimitiveType(typeof(PropertyKey)); NodeBuilder.RegisterPrimitiveType(typeof(TimeSpan)); NodeBuilder.RegisterPrimitiveType(typeof(Guid)); NodeBuilder.RegisterPrimitiveType(typeof(AssetId)); NodeBuilder.RegisterPrimitiveType(typeof(Color)); NodeBuilder.RegisterPrimitiveType(typeof(Color3)); NodeBuilder.RegisterPrimitiveType(typeof(Color4)); NodeBuilder.RegisterPrimitiveType(typeof(Vector2)); NodeBuilder.RegisterPrimitiveType(typeof(Vector3)); NodeBuilder.RegisterPrimitiveType(typeof(Vector4)); NodeBuilder.RegisterPrimitiveType(typeof(Int2)); NodeBuilder.RegisterPrimitiveType(typeof(Int3)); NodeBuilder.RegisterPrimitiveType(typeof(Int4)); NodeBuilder.RegisterPrimitiveType(typeof(Quaternion)); NodeBuilder.RegisterPrimitiveType(typeof(RectangleF)); NodeBuilder.RegisterPrimitiveType(typeof(Rectangle)); NodeBuilder.RegisterPrimitiveType(typeof(Matrix)); NodeBuilder.RegisterPrimitiveType(typeof(UPath)); NodeBuilder.RegisterPrimitiveType(typeof(AngleSingle)); // Register content types as primitive so they are not processed by Quantum foreach (var contentType in AssetRegistry.GetContentTypes()) { NodeBuilder.RegisterPrimitiveType(contentType); } OverrideNodeFactory((name, content, guid) => new AssetNode(name, content, guid)); }
public object Load(Stream stream, string assetFileExtension, ILogger log, out bool aliasOccurred) { aliasOccurred = false; var type = AssetRegistry.GetAssetTypeFromFileExtension(assetFileExtension); var asset = (SourceCodeAsset)Activator.CreateInstance(type); return(asset); }
public override IEnumerable <Type> GetInputTypesToExclude(AssetItem assetItem) { foreach (var type in AssetRegistry.GetAssetTypes(typeof(Material))) { yield return(type); } yield return(typeof(TextureAsset)); }
private void SaveRegistryFile(string filePath, AssetRegistry registry) { EnsureRegistryFolderExists(); var serializer = new AssetRegistrySerializationService(); var registryText = serializer.SerializeRegistry(registry); File.WriteAllText(filePath, registryText); }
private bool CanVisit(Type type) { // Also handles Entity, EntityComponent and Script return(AssetRegistry.IsContentType(type) || type == typeof(Entity) || typeof(Entity).IsAssignableFrom(type) || typeof(EntityComponent).IsAssignableFrom(type)); }
public void Initialize() { AssetRegistry.RegisterAssembly(typeof(ModelAsset).Assembly); AssetRegistry.RegisterAssembly(typeof(MaterialDescription).Assembly); AssetRegistry.RegisterAssembly(typeof(Color4).Assembly); TestCommon.InitializeAssetDatabase(); }
public override bool CanAddChildren(IReadOnlyCollection <object> children, AddChildModifiers modifiers, out string message) { AssetViewModel asset = null; var singleChild = true; foreach (var child in children) { if (!singleChild) { message = "Multiple assets selected"; return(false); } asset = child as AssetViewModel; if (asset == null) { message = "The selection is not an asset"; return(false); } if (AssetRegistry.IsContentType(TargetNode.Type) || typeof(AssetReference).IsAssignableFrom(TargetNode.Type)) { var isCompatible = false; var resolvedAssetTypes = AssetRegistry.GetAssetTypes(TargetNode.Type); foreach (var resolvedAssetType in resolvedAssetTypes) { if (resolvedAssetType.IsAssignableFrom(asset.AssetType)) { isCompatible = true; break; } } if (!isCompatible) { message = "Incompatible asset"; return(false); } } var command = TargetNode.GetCommand("SetContentReference"); var param = new SetContentReferenceCommand.Parameter { Asset = asset, Type = TargetNode.Type }; if (!command.CanExecute(param)) { message = "The selection is not valid in this context"; return(false); } singleChild = false; } if (asset == null) { message = "The selection is not an asset"; return(false); } message = $"Reference {asset.Url}"; return(true); }
protected override IEnumerable <ReferenceReplacementViewModel <AssetViewModel> > GetReplacementsForReferencer(AssetViewModel referencer, object referencedMember) { var rootNode = SessionViewModel.Instance.AssetNodeContainer.GetNode(referencer.Asset); var visitor = new GraphVisitorBase { SkipRootNode = true }; var result = new List <ReferenceReplacementViewModel <AssetViewModel> >(); visitor.Visiting += (node, path) => { var memberNode = node as IAssetMemberNode; if (memberNode != null) { if (AssetRegistry.IsContentType(memberNode.Descriptor.GetInnerCollectionType())) { if (memberNode.Target?.IsEnumerable ?? false) { foreach (var index in memberNode.Target.Indices) { // If this property is inherited it will be updated by the standard propagation if (memberNode.Target.IsItemInherited(index)) { continue; } var target = ContentReferenceHelper.GetReferenceTarget(referencer.Session, memberNode.Target.Retrieve(index)); if (target == CurrentObjectToReplace) { // If so, prepare a replacement for it. var viewModel = new AssetReferenceReplacementViewModel(this, CurrentObjectToReplace, referencer, referencedMember, memberNode.Target, index); result.Add(viewModel); } } } else { // If this property is inherited it will be updated by the standard propagation if (memberNode.IsContentInherited()) { return; } var target = ContentReferenceHelper.GetReferenceTarget(referencer.Session, memberNode.Retrieve()); if (target == CurrentObjectToReplace) { // If so, prepare a replacement for it. var viewModel = new AssetReferenceReplacementViewModel(this, CurrentObjectToReplace, referencer, referencedMember, memberNode, NodeIndex.Empty); result.Add(viewModel); } } } } }; visitor.Visit(rootNode); return(result); }
public void Upgrade(AssetMigrationContext context, int currentVersion, int targetVersion, YamlMappingNode yamlAssetNode, PackageLoadingAssetFile assetFile) { dynamic asset = new DynamicYamlMapping(yamlAssetNode); asset.SerializedVersion = AssetRegistry.GetCurrentFormatVersion(typeof(MyUpgradedAsset)); // Move Test1 to Test2 asset.Test2 = asset.Test1; asset.Test1 = DynamicYamlEmpty.Default; }
public string SerializeRegistry(AssetRegistry registry) { registry.OrderNodes(); using (var stringwriter = new StringWriterUtf8()) { var serializer = new XmlSerializer(typeof(AssetRegistry), new Type[] { }); serializer.Serialize(stringwriter, registry); return(stringwriter.ToString()); } }
public IAssetSerializer TryCreate(string assetFileExtension) { var assetType = AssetRegistry.GetAssetTypeFromFileExtension(assetFileExtension); if (assetType != null && typeof(SourceCodeAsset).IsAssignableFrom(assetType)) { return(this); } return(null); }
public void Upgrade(int currentVersion, int targetVersion, ILogger log, YamlMappingNode yamlAssetNode) { dynamic asset = new DynamicYamlMapping(yamlAssetNode); asset.SerializedVersion = AssetRegistry.GetCurrentFormatVersion(typeof(MyUpgradedAsset)); // Move Test1 to Test2 asset.Test2 = asset.Test1; asset.Test1 = DynamicYamlEmpty.Default; }
public override IEnumerable <BuildDependencyInfo> GetInputTypes(AssetItem assetItem) { // We need to read the prefab asset to collect models yield return(new BuildDependencyInfo(typeof(PrefabAsset), typeof(AssetCompilationContext), BuildDependencyType.CompileAsset)); foreach (var type in AssetRegistry.GetAssetTypes(typeof(Model))) { yield return(new BuildDependencyInfo(type, typeof(AssetCompilationContext), BuildDependencyType.CompileContent)); } }
public override IEnumerable <BuildDependencyInfo> GetInputTypes(AssetItem assetItem) { foreach (var type in AssetRegistry.GetAssetTypes(typeof(Model))) { yield return(new BuildDependencyInfo(type, typeof(AssetCompilationContext), BuildDependencyType.CompileContent)); } foreach (var type in AssetRegistry.GetAssetTypes(typeof(Skeleton))) { yield return(new BuildDependencyInfo(type, typeof(AssetCompilationContext), BuildDependencyType.CompileContent)); } }
public object Load(Stream stream, string assetFileExtension, ILogger log, out bool aliasOccurred) { aliasOccurred = false; var type = AssetRegistry.GetAssetTypeFromFileExtension(assetFileExtension); var asset = (SourceCodeAsset)Activator.CreateInstance(type); var reader = new StreamReader(stream, Encoding.UTF8); asset.Text = reader.ReadToEnd(); return(asset); }
public void Upgrade(AssetMigrationContext context, string dependencyName, PackageVersion currentVersion, PackageVersion targetVersion, YamlMappingNode yamlAssetNode, PackageLoadingAssetFile assetFile) { dynamic asset = new DynamicYamlMapping(yamlAssetNode); // Note: seems little bit strange, but original test was not using targetVersion... var serializedVersion = AssetRegistry.GetCurrentFormatVersions(typeof(MyUpgradedAsset))[dependencyName]; AssetUpgraderBase.SetSerializableVersion(asset, dependencyName, serializedVersion); // Move Test1 to Test2 asset.Test2 = asset.Test1; asset.Test1 = DynamicYamlEmpty.Default; }