private TES5ScriptHeader CreateHeader(TES4Script script) { string edid = script.ScriptHeader.ScriptName; ITES5Type type = this.esmAnalyzer.GetScriptTypeByScriptNameFromCache(edid); return(TES5ScriptHeaderFactory.GetFromCacheOrConstructByBasicType(edid, type, TES5TypeFactory.TES4Prefix, false)); }
public TES5GlobalScope Build(string scriptPath, TES5GlobalVariables globalVariables) { TES4Script parsedScript = this.standaloneParsingService.ParseOrGetFromCache(scriptPath); TES5ScriptHeader scriptHeader = this.CreateHeader(parsedScript); TES4VariableDeclarationList?variableList = parsedScript.VariableDeclarationList; TES5GlobalScope globalScope = new TES5GlobalScope(scriptHeader); if (variableList != null) { propertyFactory.CreateAndAddProperties(variableList, globalScope, globalVariables); } return(globalScope); }
/* * The script to be converted * The script"s global scope * The scope under which we"re converting * * @throws ConversionException */ public TES5Target Convert(TES4Target target, bool isStandalone, TES5GlobalScope globalScope, TES5MultipleScriptsScope multipleScriptsScope) { TES4Script script = target.Script; TES4BlockList?parsedBlockList = script.BlockList; Dictionary <string, List <ITES5CodeBlock> > createdBlocks = new Dictionary <string, List <ITES5CodeBlock> >(); if (parsedBlockList != null) { TES5EventCodeBlock?onUpdateBlockOfNonQuestOrAME = null; foreach (TES4CodeBlock block in parsedBlockList.Blocks) { TES5BlockList newBlockList = this.blockFactory.CreateBlock(block, globalScope, multipleScriptsScope, ref onUpdateBlockOfNonQuestOrAME); foreach (ITES5CodeBlock newBlock in newBlockList.Blocks) { createdBlocks.AddNewListIfNotContainsKeyAndAddValueToList(newBlock.BlockName, newBlock); } } } TES5BlockList blockList = new TES5BlockList(); foreach (var createdBlock in createdBlocks) { var blockType = createdBlock.Key; var blocks = createdBlock.Value; if (blocks.Count > 1) { foreach (TES5CodeBlock block in CombineRepeatedEventCodeBlockNames(blocks, blockType, isStandalone, globalScope)) { blockList.Add(block); } } else { ITES5CodeBlock block = blocks[0]; blockList.Add(block); } } TES5Target result = new TES5Target(new TES5Script(globalScope, blockList, false), target.OutputPath); return(result); }
/* * The script to be converted * The script"s global scope * The scope under which we"re converting * * @throws ConversionException */ public TES5Target Convert(TES4Target target, TES5GlobalScope globalScope, TES5MultipleScriptsScope multipleScriptsScope) { TES4Script script = target.Script; TES5BlockList blockList = new TES5BlockList(); TES4BlockList parsedBlockList = script.BlockList; Dictionary <string, List <ITES5CodeBlock> > createdBlocks = new Dictionary <string, List <ITES5CodeBlock> >(); if (parsedBlockList != null) { foreach (TES4CodeBlock block in parsedBlockList.Blocks) { TES5BlockList newBlockList = this.blockFactory.CreateBlock(block, globalScope, multipleScriptsScope); foreach (ITES5CodeBlock newBlock in newBlockList.Blocks) { createdBlocks.AddNewListIfNotContainsKeyAndAddValueToList(newBlock.BlockName, newBlock); } } } //todo encapsulate it to a different class. bool isStandalone = target.OutputPath.Contains(Path.DirectorySeparatorChar + "Standalone" + Path.DirectorySeparatorChar); foreach (var createdBlock in createdBlocks) { var blockType = createdBlock.Key; var blocks = createdBlock.Value; if (blocks.Count > 1) { List <TES5FunctionCodeBlock> functions = new List <TES5FunctionCodeBlock>(); int i = 1; TES5ObjectCallArguments localScopeArguments = null; foreach (TES5CodeBlock block in blocks) { TES5FunctionScope newFunctionScope = new TES5FunctionScope(blockType + "_" + i.ToString()); foreach (var variable in block.FunctionScope.Variables.Values) { newFunctionScope.AddVariable(variable); } TES5FunctionCodeBlock function = new TES5FunctionCodeBlock(newFunctionScope, block.CodeScope, new TES5VoidType(), isStandalone); functions.Add(function); if (localScopeArguments == null) { localScopeArguments = new TES5ObjectCallArguments(); foreach (var variable in block.FunctionScope.Variables.Values) { localScopeArguments.Add(TES5ReferenceFactory.CreateReferenceToVariable(variable)); } } ++i; } //Create the proxy block. ITES5CodeBlock lastBlock = blocks.Last(); TES5EventCodeBlock proxyBlock = TES5BlockFactory.CreateEventCodeBlock(blockType, /* * //WTM: Change: block was used below, but block is out of scope. The PHP must have been using the last defined block from above. * //WTM: Change: PHP called "clone" below, but I'm not sure if this is necessary or would even operate the same in C#. */ lastBlock.FunctionScope); foreach (var function in functions) { blockList.Add(function); TES5ObjectCall functionCall = this.objectCallFactory.CreateObjectCall(TES5ReferenceFactory.CreateReferenceToSelf(globalScope), function.BlockName, multipleScriptsScope, localScopeArguments, false // hacky. ); proxyBlock.AddChunk(functionCall); } blockList.Add(proxyBlock); } else { ITES5CodeBlock block = blocks[0]; blockList.Add(block); } } TES5Target result = new TES5Target(new TES5Script(globalScope, blockList), target.OutputPath); return(result); }
public TES4Target(TES4Script script, string outputPath) { this.Script = script; this.OutputPath = outputPath; }
private TES5ScriptHeader CreateHeader(TES4Script script) { string edid = script.ScriptHeader.ScriptName; return(new TES5ScriptHeader(edid, this.esmAnalyzer.GetScriptType(edid), TES5TypeFactory.TES4Prefix)); }