Ejemplo n.º 1
0
        public void Initialize(IReadOnlyCollection <CustomScriptAssembly> assemblies,
                               IReadOnlyCollection <CustomScriptAssemblyReference> customScriptAssemblyReferences)
        {
            var assemblyByNameLookup = assemblies.ToDictionary(x => x.Name, x => x);
            var assemblyByGuidLookup = assemblies.ToDictionary(x => x.GUID, x => x);

            bool rootOverridden = assemblies.Any(x => AssetPath.ComparePaths(x.PathPrefix, _projectPath));

            if (!rootOverridden)
            {
                _npp.Insert(_globalAssemblyDefinition.PathPrefix, _globalAssemblyDefinition);
                _npp.Insert(_editorAssebmlyDefinition.PathPrefix, _editorAssebmlyDefinition);
                _npp.Insert(_globalFirstpassAssemblyDefinition.PathPrefix, _globalFirstpassAssemblyDefinition);
                _npp.Insert(_editorFirstpassAssemblyDefinition.PathPrefix, _editorFirstpassAssemblyDefinition);
            }

            foreach (var assemblyDef in assemblies)
            {
                _npp.Insert(assemblyDef.PathPrefix, assemblyDef);
            }

            if (!rootOverridden)
            {
                foreach (var globalFirstpassAssemblyReference in _globalFirstpassAssemblyReferences)
                {
                    _npp.Insert(globalFirstpassAssemblyReference.PathPrefix, _globalFirstpassAssemblyDefinition);
                }
            }

            foreach (var assemblyReference in customScriptAssemblyReferences)
            {
                CustomScriptAssembly foundAssemblyDef = null;
                var foundAssemblyDefinition           = GUIDReference.IsGUIDReference(assemblyReference.Reference)
                    ? assemblyByGuidLookup.TryGetValue(GUIDReference.GUIDReferenceToGUID(assemblyReference.Reference),
                                                       out foundAssemblyDef)
                    : assemblyByNameLookup.TryGetValue(assemblyReference.Reference, out foundAssemblyDef);

                if (foundAssemblyDefinition)
                {
                    _npp.Insert(assemblyReference.PathPrefix, foundAssemblyDef);
                }
                else
                {
                    Console.WriteLine(
                        $"Assembly reference {assemblyReference.FilePath} has no target assembly definition");
                }
            }
        }