예제 #1
0
 public BuildScopeCommandQFOrTIF(TES5PropertyFactory propertyFactory, FragmentsReferencesBuilder fragmentsReferencesBuilder, TES5BasicType scriptType, string scriptNamePrefix, TES5FragmentType fragmentType)
 {
     this.propertyFactory            = propertyFactory;
     this.fragmentsReferencesBuilder = fragmentsReferencesBuilder;
     this.scriptType       = scriptType;
     this.scriptNamePrefix = scriptNamePrefix;
     this.fragmentType     = fragmentType;
 }
        public TES5Target Convert(TES5FragmentType fragmentType, TES4FragmentTarget fragmentTarget, TES5GlobalScope globalScope, TES5MultipleScriptsScope multipleScriptsScope)
        {
            TES5FunctionCodeBlock fragment  = CreateFragment(fragmentType, 0, globalScope, multipleScriptsScope, fragmentTarget.CodeChunks);
            TES5BlockList         blockList = new TES5BlockList()
            {
                fragment
            };
            TES5Script script = new TES5Script(globalScope, blockList, true);
            TES5Target target = new TES5Target(script, fragmentTarget.OutputPath);

            return(target);
        }
        public static TES5FunctionScope CreateFromFragmentType(string fragmentName, TES5FragmentType fragmentType)
        {
            TES5FunctionScope localScope = new TES5FunctionScope(fragmentName);

            if (fragmentType == TES5FragmentType.T_TIF)
            {
                localScope.AddVariable(new TES5LocalVariable("akSpeakerRef", TES5BasicType.T_OBJECTREFERENCE, new TES5LocalVariableParameterMeaning[] { TES5LocalVariableParameterMeaning.ACTIVATOR }));
            }
            else if (fragmentType == TES5FragmentType.T_PF)
            {
                localScope.AddVariable(new TES5LocalVariable("akActor", TES5BasicType.T_ACTOR, new TES5LocalVariableParameterMeaning[] { TES5LocalVariableParameterMeaning.ACTIVATOR }));
            }
            return(localScope);
        }
        public TES5FunctionCodeBlock CreateFragment(TES5FragmentType fragmentType, string fragmentName, TES5GlobalScope globalScope, TES5MultipleScriptsScope multipleScriptsScope, TES4CodeChunks chunks)
        {
            TES5FunctionScope     fragmentLocalScope = TES5FragmentFunctionScopeFactory.CreateFromFragmentType(fragmentName, fragmentType);
            TES5FunctionCodeBlock function           = new TES5FunctionCodeBlock(fragmentLocalScope, TES5CodeScopeFactory.CreateCodeScopeRoot(fragmentLocalScope), TES5VoidType.Instance, false, fragmentType == TES5FragmentType.T_QF || fragmentType == TES5FragmentType.T_TIF);

            foreach (var codeChunk in chunks)
            {
                TES5CodeChunkCollection codeChunks = this.codeChunkFactory.CreateCodeChunk(codeChunk, function.CodeScope, globalScope, multipleScriptsScope);
                foreach (var newCodeChunk in codeChunks)
                {
                    function.AddChunk(newCodeChunk);
                }
            }
            return(function);
        }
        private TES5FunctionCodeBlock CreateFragment(TES5FragmentType fragmentType, int stageID, TES5GlobalScope globalScope, TES5MultipleScriptsScope multipleScriptsScope, TES4CodeChunks chunks)
        {
            string fragmentName = GetFragmentName(stageID);

            return(CreateFragment(fragmentType, fragmentName, globalScope, multipleScriptsScope, chunks));
        }
        public static Dictionary <string, KeyValuePair <int, TES5BasicType> > GetTypesFromSCRO(ESMAnalyzer esmAnalyzer, string fileNameNoExt, TES5FragmentType fragmentType)
        {
            Tuple <int, StageIndexAndLogIndex?> formIDStageIndexAndLogIndex = GetTES4FormIDStageIndexAndLogIndex(fileNameNoExt, fragmentType);

            return(esmAnalyzer.GetTypesFromSCRO(formIDStageIndexAndLogIndex.Item1, formIDStageIndexAndLogIndex.Item2));
        }
        private static Tuple <int, StageIndexAndLogIndex?> GetTES4FormIDStageIndexAndLogIndex(string fileNameNoExt, TES5FragmentType fragmentType)
        {
            Match fileNameMatch = fileNameRE.Match(fileNameNoExt);

            if (!fileNameMatch.Success)
            {
                throw new ConversionException(fileNameNoExt + " did not match pattern.");
            }
            string scriptTES5FormIDHex = fileNameMatch.Groups[2].Value;
            StageIndexAndLogIndex?stageIndexAndLogIndex = null;

            if (fragmentType == TES5FragmentType.T_QF)
            {
                stageIndexAndLogIndex = new StageIndexAndLogIndex(int.Parse(fileNameMatch.Groups[4].Value), int.Parse(fileNameMatch.Groups[5].Value));
            }
            int scriptTES4FormID = Convert.ToInt32(scriptTES5FormIDHex, 16) - 0x01000000;

            return(new Tuple <int, StageIndexAndLogIndex?>(scriptTES4FormID, stageIndexAndLogIndex));
        }
        public TES4VariableDeclarationList BuildVariableDeclarationList(string sourcePath, string scriptName, TES5FragmentType fragmentType)
        {
            TES4VariableDeclarationList list = new TES4VariableDeclarationList();
            var scroRecords = TES5ReferenceFactory.GetTypesFromSCRO(esmAnalyzer, scriptName, fragmentType);

            string[] references =
#if USEFILESINSTEADOFESM
                GetReferences(sourcePath, scriptName)
#else
                scroRecords
#if !NEWBT
                .Where(r => r.Value.Key != TES5PlayerReference.FormID)
#endif
                .Select(r => r.Key)
#endif
                .ToArray();
            foreach (var reference in references)
            {
                var scroReference = scroRecords[reference];
                list.Add(new TES4VariableDeclaration(reference, TES4Type.T_REF, formID: scroReference.Key, tes5Type: scroReference.Value));
            }
            return(list);
        }