Exemplo n.º 1
0
        public StyleCompileContext CreateContext(LightList <StyleASTNode> rootNodes, MaterialDatabase materialDatabase)
        {
            StyleCompileContext context = new StyleCompileContext(materialDatabase);

            // first all imports must be collected as they can be referenced in exports and consts
            for (int i = 0; i < rootNodes.size; i++)
            {
                switch (rootNodes[i])
                {
                case ImportNode importNode:

                    StyleSheet importedStyle = styleSheetImporter.ImportStyleSheetFromFile(importNode.source, materialDatabase);

                    LightList <StyleConstant> importedStyleConstants = new LightList <StyleConstant>(importedStyle.constants.Length);

                    for (int constantIndex = 0; constantIndex < importedStyle.constants.Length; constantIndex++)
                    {
                        StyleConstant importedStyleConstant = importedStyle.constants[constantIndex];
                        if (importedStyleConstant.exported)
                        {
                            importedStyleConstants.Add(importedStyleConstant);
                        }
                    }

                    context.importedStyleConstants.Add(importNode.alias, importedStyleConstants);

                    break;
                }
            }

            // collect all constants that could be referenced
            for (int index = 0; index < rootNodes.size; index++)
            {
                switch (rootNodes[index])
                {
                case ExportNode exportNode:
                    TransformConstNode(context, exportNode.constNode, true);
                    break;

                case ConstNode constNode:
                    TransformConstNode(context, constNode, false);
                    break;
                }
            }

            ResolveConstantReferences(context);
            context.constantsWithReferences.Clear();

            return(context);
        }