public void WeWillOverrideTheMethod() { ScriptTranslator trans = new ScriptTranslator(testScript); trans.Translate(); string newScript = trans.ToString(); Assert.That(newScript, Is.StringContaining("public override void LateUpdate")); }
public override SubRenderState CreateInstance(Scripting.Compiler.ScriptCompiler compiler, Scripting.Compiler.AST.PropertyAbstractNode prop, Graphics.Pass pass, ScriptTranslator stranslator) { SubRenderState subRenderState = CreateInstance(); return(subRenderState); }
public void WeWillGetTheClassDefinitionAsWritten() { ScriptTranslator trans = new ScriptTranslator(testScript); trans.CreateStub(); string newScript = trans.ToString(); Assert.That(newScript, Is.StringContaining(testScript.First(s => s.Contains(" class ")))); }
public void WeWillNotDeleteSymboldBeforeRandom() { ScriptTranslator trans = new ScriptTranslator(testScript); trans.Translate(); string newScript = trans.ToString(); Assert.That(newScript, Is.StringContaining("(PressPlay.FFWD.Random")); Assert.That(newScript, Is.Not.StringContaining("(Random.")); }
public void WeWillTranslateItToFFWDRandom() { ScriptTranslator trans = new ScriptTranslator(testScript); trans.Translate(); string newScript = trans.ToString(); Assert.That(newScript, Is.StringContaining("PressPlay.FFWD.Random")); Assert.That(newScript, Is.Not.StringContaining("PressPlay.FFWD.PressPlay.FFWD.")); }
public void WeWillOverrideTheStartMethod() { ScriptTranslator trans = new ScriptTranslator(testScript); trans.Translate(); string newScript = trans.ToString(); Assert.That(newScript, Is.StringContaining("public override void Start")); }
public void WeCanAlsoRemoveAttributesThatHasParameters() { ScriptTranslator.ReplaceAttributes = new System.Collections.Generic.Dictionary<string, string>() { { "AddComponentMenu", "" } }; ScriptTranslator trans = new ScriptTranslator(testScript); trans.Translate(); string newScript = trans.ToString(); Assert.That(newScript, Is.Not.StringContaining("[AddComponentMenu")); }
public void IfAnAttributeHasACommentedSectionItCanBeRemoved() { ScriptTranslator.ReplaceAttributes = new System.Collections.Generic.Dictionary<string, string>() { { "AttributeWithComment", "" } }; ScriptTranslator trans = new ScriptTranslator(testScript); trans.Translate(); string newScript = trans.ToString(); Assert.That(newScript, Is.Not.StringContaining("[AttributeWithComment")); }
public void WeCanAddExtraUsings() { string myNamespace = "MyNamespace"; ScriptTranslator trans = new ScriptTranslator(testScript); ScriptTranslator.DefaultUsings.Add(myNamespace); trans.Translate(); string newScript = trans.ToString(); Assert.That(newScript, Is.StringContaining("using " + myNamespace + ";")); }
public void IfAnAttributeHasACommentedSectionRemoveTheCommentMarkers() { ScriptTranslator.ReplaceAttributes = new System.Collections.Generic.Dictionary<string, string>() { { "AttributeWithComment", "ConvertedAttribute" } }; ScriptTranslator trans = new ScriptTranslator(testScript); trans.Translate(); string newScript = trans.ToString(); Assert.That(newScript, Is.StringContaining("[ConvertedAttribute(")); }
public void WeWillAddANamespaceAfterUsingStatements() { ScriptTranslator.ScriptNamespace = "TestNamespace"; ScriptTranslator trans = new ScriptTranslator(testScript); trans.CreateStub(); string newScript = trans.ToString(); Assert.That(newScript, Is.StringContaining(ScriptTranslator.ScriptNamespace)); Assert.That(newScript.IndexOf("using"), Is.LessThan(newScript.IndexOf(ScriptTranslator.ScriptNamespace))); }
public void WeWillReplaceExplicitUnityEngineWithFFWDNamespace() { ScriptTranslator trans = new ScriptTranslator(testScript); trans.Translate(); string newScript = trans.ToString(); Assert.That(newScript, Is.StringContaining("PressPlay.FFWD.Vector3")); Assert.That(newScript, Is.Not.StringContaining("UnityEngine.Vector3")); }
public void WeWillRemoveOldUsings() { ScriptTranslator trans = new ScriptTranslator(testScript); trans.CreateStub(); string newScript = trans.ToString(); Assert.That(newScript, Is.Not.StringContaining("UnityEngine;")); Assert.That(newScript, Is.Not.StringContaining("SomeSystem;")); }
public void ItWillBeReplacedWithUnityObject() { ScriptTranslator trans = new ScriptTranslator(testScript); trans.Translate(); string newScript = trans.ToString(); Assert.That(newScript, Is.StringContaining("UnityObject myObj;")); Assert.That(newScript, Is.StringContaining("(UnityObject myObject")); }
public void WeWillOverrideTheFixedUpdateMEthodEvenWithABrokenSignature() { ScriptTranslator trans = new ScriptTranslator(testScript); trans.Translate(); string newScript = trans.ToString(); Assert.That(newScript, Is.StringContaining("public override void FixedUpdate")); Assert.That(newScript, Is.Not.StringContaining("virtual protected public override void")); }
public void AllCodeInTheClassWillBeRemoved() { ScriptTranslator trans = new ScriptTranslator(testScript); trans.CreateStub(); string newScript = trans.ToString(); Assert.That(newScript, Is.Not.StringContaining(testScript.First(s => s.Contains("Start()")))); Assert.That(newScript, Is.Not.StringContaining(testScript.First(s => s.Contains("Vector3")))); Assert.That(newScript, Is.Not.StringContaining(testScript.First(s => s.Contains("Update()")))); }
public void WeWillAddTheDefinedUsings() { ScriptTranslator trans = new ScriptTranslator(testScript); trans.Translate(); string newScript = trans.ToString(); foreach (string u in ScriptTranslator.DefaultUsings) { Assert.That(newScript, Is.StringContaining("using " + u + ";")); } }
public void WeWillRemoveUsingsNotSetToBeKept() { ScriptTranslator trans = new ScriptTranslator(testScript); ScriptTranslator.UsingsThatShouldBeKept = new List<string> { "System", "System.Diagnostics" }; trans.Translate(); string newScript = trans.ToString(); Assert.That(newScript, Is.StringContaining("System;")); Assert.That(newScript, Is.StringContaining("System.Diagnostics;")); Assert.That(newScript, Is.Not.StringContaining("UnityEngine;")); Assert.That(newScript, Is.Not.StringContaining("SomeSystem;")); }
public void WeCanAddExtraUsings() { string myNamespace = "MyNamespace"; ScriptTranslator trans = new ScriptTranslator(testScript); ScriptTranslator.DefaultUsings.Add(myNamespace); trans.CreateStub(); string newScript = trans.ToString(); Assert.That(newScript, Is.StringContaining("using " + myNamespace + ";")); }
public void WeWillAddTheDefinedUsings() { ScriptTranslator trans = new ScriptTranslator(testScript); trans.CreateStub(); string newScript = trans.ToString(); foreach (string u in ScriptTranslator.DefaultUsings) { Assert.That(newScript, Is.StringContaining("using " + u + ";")); } }
public void WeCanAlsoRemoveAttributesThatHasParameters() { ScriptTranslator.ReplaceAttributes = new System.Collections.Generic.Dictionary <string, string>() { { "AddComponentMenu", "" } }; ScriptTranslator trans = new ScriptTranslator(testScript); trans.Translate(); string newScript = trans.ToString(); Assert.That(newScript, Is.Not.StringContaining("[AddComponentMenu")); }
public void IfAnAttributeHasACommentedSectionRemoveTheCommentMarkers() { ScriptTranslator.ReplaceAttributes = new System.Collections.Generic.Dictionary <string, string>() { { "AttributeWithComment", "ConvertedAttribute" } }; ScriptTranslator trans = new ScriptTranslator(testScript); trans.Translate(); string newScript = trans.ToString(); Assert.That(newScript, Is.StringContaining("[ConvertedAttribute(")); }
public void IfAnAttributeHasACommentedSectionItCanBeRemoved() { ScriptTranslator.ReplaceAttributes = new System.Collections.Generic.Dictionary <string, string>() { { "AttributeWithComment", "" } }; ScriptTranslator trans = new ScriptTranslator(testScript); trans.Translate(); string newScript = trans.ToString(); Assert.That(newScript, Is.Not.StringContaining("[AttributeWithComment")); }
public void WeCanRemoveAnAttribute() { ScriptTranslator.ReplaceAttributes = new System.Collections.Generic.Dictionary <string, string>() { { "HideInInspector", "" } }; ScriptTranslator trans = new ScriptTranslator(testScript); trans.Translate(); string newScript = trans.ToString(); Assert.That(newScript, Is.Not.StringContaining("[]")); Assert.That(newScript, Is.Not.StringContaining("[HideInInspector]")); }
public void WeWillRemoveUsingsNotSetToBeKept() { ScriptTranslator trans = new ScriptTranslator(testScript); ScriptTranslator.UsingsThatShouldBeKept = new List <string> { "System", "System.Diagnostics" }; trans.Translate(); string newScript = trans.ToString(); Assert.That(newScript, Is.StringContaining("System;")); Assert.That(newScript, Is.StringContaining("System.Diagnostics;")); Assert.That(newScript, Is.Not.StringContaining("UnityEngine;")); Assert.That(newScript, Is.Not.StringContaining("SomeSystem;")); }
public void WeCanTranslateTheTestScripts() { foreach (string filename in Directory.GetFiles("TestScripts", "*.cs")) { try { ScriptTranslator trans = new ScriptTranslator(File.ReadAllLines(filename)); trans.Translate(); } catch (Exception ex) { Assert.Fail("Exception while translating " + Path.GetFileNameWithoutExtension(filename) + ": " + ex.Message); } } Assert.Pass("We have translated all scripts"); }
private LayeredBlending CreateOrRetrieveSubRenderState(ScriptTranslator translator) { LayeredBlending layeredBlendState = null; //check if we already create a blend srs SubRenderState subState = translator.GetGeneratedSubRenderState(Type); if (subState != null) { layeredBlendState = subState as LayeredBlending; } else { SubRenderState subRenderState = CreateOrRetrieveInstance(translator); layeredBlendState = (LayeredBlending)subRenderState; } return(layeredBlendState); }
private void TranslateScriptFile(string scriptFile) { try { string scriptText = File.ReadAllText(scriptFile); string[] textLines = scriptText.Split('\n'); PressPlay.FFWD.Exporter.ScriptTranslator trans = new ScriptTranslator(textLines); trans.Translate(); string newText = trans.ToString(); string newPath = scriptFile.Replace(Path.Combine(Application.dataPath, config.unityScriptDir), Path.Combine(xnaBaseDir, config.xnaAssets.ScriptDir)); if (!Directory.Exists(Path.GetDirectoryName(newPath))) { Directory.CreateDirectory(Path.GetDirectoryName(newPath)); } File.WriteAllText(newPath, newText); } catch (Exception ex) { Debug.LogError("Error when converting script " + Path.GetFileName(scriptFile) + ": " + ex.Message); } }
public override SubRenderState CreateInstance(Scripting.Compiler.ScriptCompiler compiler, Scripting.Compiler.AST.PropertyAbstractNode prop, Graphics.Pass pass, ScriptTranslator stranslator) { if (prop.Name == "lighting_stage") { if (prop.Values.Count == 1) { string modelType; if (SGScriptTranslator.GetString(prop.Values[0], out modelType) == false) { //compiler.AddError(...) return(null); } if (modelType == "per_pixel") { return(CreateOrRetrieveInstance(stranslator)); } } } return(null); }
public void WeWillReplaceAttributes() { ScriptTranslator.ReplaceAttributes = new System.Collections.Generic.Dictionary<string, string>() { { "HideInInspector", "InspectorGadget" } }; ScriptTranslator trans = new ScriptTranslator(testScript); trans.Translate(); string newScript = trans.ToString(); Assert.That(newScript, Is.StringContaining("[InspectorGadget]")); Assert.That(newScript, Is.Not.StringContaining("[HideInInspector]")); }
public override SubRenderState CreateInstance(Scripting.Compiler.ScriptCompiler compiler, Scripting.Compiler.AST.PropertyAbstractNode prop, Graphics.TextureUnitState texState, ScriptTranslator translator) { if (prop.Name == "layered_blend") { string blendType; if (!SGScriptTranslator.GetString(prop.Values[0], out blendType)) { // compiler.AddError(...); return(null); } LayeredBlending.BlendMode blendMode = StringToBlendMode(blendType); if (blendMode == LayeredBlending.BlendMode.Invalid) { // compiler.AddError(...); return(null); } //get the layer blend sub-render state to work on var layeredBlendState = (LayeredBlending)CreateOrRetrieveInstance(translator); int texIndex = -1; //TODO: check impl. Ogre use: texIndex = texState.Parent.GetTextureUnitStateIndex(texState); for (int i = 0; i < texState.Parent.TextureUnitStatesCount; i++) { if (texState.Parent.GetTextureUnitState(i) == texState) { texIndex = i; break; } } layeredBlendState.SetBlendMode(texIndex, blendMode); return(layeredBlendState); } if (prop.Name == "source_modifier") { if (prop.Values.Count < 3) { //compiler.AddError(..); return(null); } //Read light model type bool isParseSuccess; string modifierString; string paramType; int customNum; int itValue = 0; isParseSuccess = SGScriptTranslator.GetString(prop.Values[itValue], out modifierString); LayeredBlending.SourceModifier modType = StringToSourceModifier(modifierString); isParseSuccess &= modType != LayeredBlending.SourceModifier.Invalid; if (isParseSuccess == false) { //compiler.AddError(...); return(null); } itValue++; isParseSuccess = SGScriptTranslator.GetString(prop.Values[itValue], out paramType); isParseSuccess &= (paramType == "custom"); if (isParseSuccess == false) { // compiler.AddError(...); return(null); } itValue++; isParseSuccess = SGScriptTranslator.GetString(prop.Values[itValue], out paramType); if (isParseSuccess == false) { //compiler.AddError(...); return(null); } itValue++; isParseSuccess = SGScriptTranslator.GetInt(prop.Values[itValue], out customNum); if (isParseSuccess == false) { //compiler.AddError(...); return(null); } //get the layer blend sub render state to work on var layeredBlendState = (LayeredBlending)CreateOrRetrieveInstance(translator); int texIndex = 0; //update the layer sub render state for (int i = 0; i < texState.Parent.TextureUnitStatesCount; i++) { if (texState.Parent.GetTextureUnitState(i) == texState) { texIndex = i; break; } } layeredBlendState.SetSourceModifier(texIndex, modType, customNum); return(layeredBlendState); } return(null); }
public override SubRenderState CreateInstance(Scripting.Compiler.ScriptCompiler compiler, Scripting.Compiler.AST.PropertyAbstractNode prop, Pass pass, ScriptTranslator stranslator) { if (prop.Name == "rtss_ext_reflection_map") { if (prop.Values.Count >= 2) { string strValue; int it = 0; //Read reflection map type if (!ScriptTranslator.GetString(prop.Values[it], out strValue)) { //compiler.AddError(...) return(null); } it++; SubRenderState subRenderState = CreateInstance(); var reflectionMapSubRenderState = subRenderState as ReflectionMap; //Reflection map is cubic texture. if (strValue == "cube_map") { reflectionMapSubRenderState.ReflectionMapType = TextureType.CubeMap; } else if (strValue == "2d_map") { reflectionMapSubRenderState.ReflectionMapType = TextureType.TwoD; } if (!ScriptTranslator.GetString(prop.Values[it], out strValue)) { //compiler.AddError(...) return(null); } reflectionMapSubRenderState.MaskMapTextureName = strValue; it++; //read reflection texture if (!ScriptTranslator.GetString(prop.Values[it], out strValue)) { //compiler.AddError(...); return(null); } reflectionMapSubRenderState.ReflectionMapTextureName = strValue; it++; //Read reflection power value Real reflectionPower = 0.5; if (!ScriptTranslator.GetReal(prop.Values[it], out reflectionPower)) { //compiler.AddError(...) return(null); } reflectionMapSubRenderState.ReflectionPower = reflectionPower; return(subRenderState); } } return(null); }
public Translator() { this.scriptTranslator = new ScriptTranslator(); this.localisationTranslator = new LocalisationTranslator(); }