private void GenerateInterpolateBetween(ElementSave elementSave, ICodeBlock currentBlock, string enumType, IEnumerable<StateSave> states) { // We used to only generate these if there was were any states in this category, but // since Gum generated code supports dynamic states, there could be states in a category // even if they're not defined in Gum. //if (states.Count() > 0) { currentBlock = currentBlock.Function("public void", "InterpolateBetween", enumType + " firstState, " + enumType + " secondState, float interpolationValue"); GenerateDebugCheckForInterpolationValueNaN(currentBlock); Dictionary<VariableSave, InterpolationCharacteristic> interpolationCharacteristics = new Dictionary<VariableSave, InterpolationCharacteristic>(); CreateStartingValueVariables(elementSave, states, currentBlock, interpolationCharacteristics); currentBlock = currentBlock.Switch("firstState"); currentBlock = SetInterpolateBetweenValuesForStates(elementSave, enumType, states, currentBlock, interpolationCharacteristics, FirstValue); currentBlock = currentBlock.End(); currentBlock = currentBlock.Switch("secondState"); currentBlock = SetInterpolateBetweenValuesForStates(elementSave, enumType, states, currentBlock, interpolationCharacteristics, SecondValue); currentBlock = currentBlock.End(); currentBlock = AssignValuesUsingStartingValues(elementSave, currentBlock, interpolationCharacteristics); currentBlock = currentBlock.If("interpolationValue < 1"); string fieldToAssign; if (enumType == "VariableState") { fieldToAssign = "mCurrentVariableState"; } else { fieldToAssign = "mCurrent" + enumType + "State"; } currentBlock.Line(fieldToAssign + " = firstState;"); currentBlock = currentBlock.End().Else(); currentBlock.Line(fieldToAssign + " = secondState;"); currentBlock = currentBlock.End(); } }
private void GenerateInterpolateBetween(ElementSave elementSave, ICodeBlock currentBlock, string enumType, IEnumerable <StateSave> states) { // We used to only generate these if there was were any states in this category, but // since Gum generated code supports dynamic states, there could be states in a category // even if they're not defined in Gum. //if (states.Count() > 0) { currentBlock = currentBlock.Function("public void", "InterpolateBetween", enumType + " firstState, " + enumType + " secondState, float interpolationValue"); GenerateDebugCheckForInterpolationValueNaN(currentBlock); Dictionary <VariableSave, InterpolationCharacteristic> interpolationCharacteristics = new Dictionary <VariableSave, InterpolationCharacteristic>(); CreateStartingValueVariables(elementSave, states, currentBlock, interpolationCharacteristics); currentBlock = currentBlock.Switch("firstState"); currentBlock = SetInterpolateBetweenValuesForStates(elementSave, enumType, states, currentBlock, interpolationCharacteristics, FirstValue); currentBlock = currentBlock.End(); currentBlock = currentBlock.Switch("secondState"); currentBlock = SetInterpolateBetweenValuesForStates(elementSave, enumType, states, currentBlock, interpolationCharacteristics, SecondValue); currentBlock = currentBlock.End(); currentBlock = AssignValuesUsingStartingValues(elementSave, currentBlock, interpolationCharacteristics); currentBlock = currentBlock.If("interpolationValue < 1"); string fieldToAssign; if (enumType == "VariableState") { fieldToAssign = "mCurrentVariableState"; } else { fieldToAssign = "mCurrent" + enumType + "State"; } currentBlock.Line(fieldToAssign + " = firstState;"); currentBlock = currentBlock.End().Else(); currentBlock.Line(fieldToAssign + " = secondState;"); currentBlock = currentBlock.End(); } }
private static ICodeBlock GeneratePreloadStateContentForStateType(ICodeBlock codeBlock, IElement element, List <StateSave> list, string variableType) { if (list.Count != 0) { codeBlock = codeBlock.Function("public static void", "PreloadStateContent", variableType + " state, string contentManagerName"); codeBlock.Line("ContentManagerName = contentManagerName;"); codeBlock = codeBlock.Switch("state"); // Loop through states here and access properties that need the values foreach (StateSave state in list) { codeBlock = codeBlock.Case(variableType + "." + state.Name); foreach (InstructionSave instruction in state.InstructionSaves) { if (instruction.Value != null && instruction.Value is string) { // We insert a block so that object throwaway is not redefined in the switch scope. // We do this instead of making an object throwaway above the switch so that we don't // get warnings if is nothing to load codeBlock.Block().Line("object throwaway = " + GetRightSideAssignmentValueAsString(element, instruction) + ";"); } } codeBlock = codeBlock.End(); } codeBlock = codeBlock.End(); codeBlock = codeBlock.End(); } return(codeBlock); }
private void GenerateGetCurrentValuesOnStateForCategory(ICodeBlock currentBlock, ElementSave container, string categoryName, List <Gum.DataTypes.Variables.StateSave> states, bool addValues = false) { string methodName = "GetCurrentValuesOnState"; if (addValues) { methodName = "AddToCurrentValuesWithState"; } currentBlock = currentBlock.Function("private Gum.DataTypes.Variables.StateSave", methodName, categoryName + " state"); currentBlock.Line("Gum.DataTypes.Variables.StateSave newState = new Gum.DataTypes.Variables.StateSave();"); var switchBlock = currentBlock.Switch("state"); { foreach (var state in states) { var caseBlock = switchBlock.Case(categoryName + "." + state.MemberNameInCode()); { var instanceNames = container.Instances.Select(item => item.Name).ToList(); var orderedVariables = state.Variables .Where(item => GetIfShouldGenerateStateVariable(item, container)) .OrderBy(variable => instanceNames.IndexOf(variable.SourceObject)); foreach (var variable in orderedVariables) { string memberNameInCode = variable.MemberNameInCode(container, VariableNamesToReplaceForStates); caseBlock.Line("newState.Variables.Add(new Gum.DataTypes.Variables.VariableSave()"); var instantiatorBlock = caseBlock.Block(); { instantiatorBlock.Line("SetsValue = true,"); // Don't use memberNameInCode - states from the XML files will not, and we want this // to behave the same so merging (used in interpolation) works properly //instantiatorBlock.Line("Name = \"" + memberNameInCode + "\","); instantiatorBlock.Line("Name = \"" + variable.Name + "\","); instantiatorBlock.Line($"Type = \"{variable.Type}\","); string valueString = "Value = " + memberNameInCode + ""; if (addValues && IsVariableNumeric(variable)) { string variableValue = variable.Value.ToString(); bool isEntireAssignment; GueDerivingClassCodeGenerator.Self.AdjustVariableValueIfNecessary(variable, container, ref variableValue, out isEntireAssignment); if (isEntireAssignment) { valueString = variableValue; } else { valueString += " + " + variableValue; } } instantiatorBlock.Line(valueString); } caseBlock.Line(");"); } } } } currentBlock.Line("return newState;"); }
private static ICodeBlock GeneratePreloadStateContentForStateType(ICodeBlock codeBlock, IElement element, List<StateSave> list, string variableType) { if (list.Count != 0) { codeBlock = codeBlock.Function("public static void", "PreloadStateContent", variableType + " state, string contentManagerName"); codeBlock.Line("ContentManagerName = contentManagerName;"); codeBlock = codeBlock.Switch("state"); // Loop through states here and access properties that need the values foreach (StateSave state in list) { codeBlock = codeBlock.Case(variableType + "." + state.Name); foreach (InstructionSave instruction in state.InstructionSaves) { if (instruction.Value != null && instruction.Value is string) { // We insert a block so that object throwaway is not redefined in the switch scope. // We do this instead of making an object throwaway above the switch so that we don't // get warnings if is nothing to load codeBlock.Block().Line("object throwaway = " + GetRightSideAssignmentValueAsString(element, instruction) + ";"); } } codeBlock = codeBlock.End(); } codeBlock = codeBlock.End(); codeBlock = codeBlock.End(); } return codeBlock; }
private static void InstantiateObjectInSwitchStatement(NamedObjectSave namedObject, ICodeBlock codeBlock, List<string[]> referencedFilesAlreadyUsingFullFile, AssetTypeInfo ati, string objectName, ReferencedFileSave rfs, List<StateSave> stateSaves, IElement saveObject, string defaultContainer, string overridingName) { var switchBlock = codeBlock.Switch("LoadingState"); for (int i = 0; i < stateSaves.Count; i++) { StateSave stateSave = stateSaves[i]; string name = ""; // I don't think we're going to use these anymore //NamedObjectPropertyOverride objectOverride = stateSave.GetNamedObjectOverride(objectName); //name = FileManager.RemovePath(FileManager.RemoveExtension(objectOverride.SourceFile)); InstantiateObjectUsingFile(namedObject, switchBlock.Case("VariableState." + stateSave.Name), referencedFilesAlreadyUsingFullFile, ati, objectName, rfs, saveObject, name, overridingName); } InstantiateObjectUsingFile(namedObject, switchBlock.Case("VariableState.Uninitialized:"), referencedFilesAlreadyUsingFullFile, ati, objectName, rfs, saveObject, defaultContainer, overridingName); }