public static void Put(object oVal) { //TODO: how to "automatically" call the unboxed value's ToString() function?? I don't want "Int32", I want "9"! //I can't specify each and every type that might be used here... string s = ""; if (oVal.GetType() == typeof(int)) { s = ((int)oVal).ToString(); } else if (oVal.GetType() == typeof(float)) { s = ((float)oVal).ToString(); } else if (oVal.GetType() == typeof(double)) { s = ((double)oVal).ToString(); } else if (oVal.GetType() == typeof(string)) { s = ((string)oVal).ToString(); } EH.Put(s); }
public bool Step() //returns false when finished { bool bDebug = false; BaseNode owningNode = (BaseNode)this.m_callStack.Peek(); BaseNode nextNode = owningNode.GetNextNode(this, this.m_currentNode, null); if (nextNode == null) { if (bDebug) { EH.Put("No more nodes on that depth"); } //that node is finished. Go up one level or quit! if (this.m_callStack.Count <= 1) //there has to be two nodes above the current! { //fire event! Quit! return(false); } //step up one level, and find next node there: this.m_currentNode = (BaseNode)this.m_callStack.Pop(); this.Step(); } else { if (nextNode.ParentNode != owningNode) //when going down one level (always just one) { this.m_callStack.Push(nextNode.ParentNode); this.m_currentNode = nextNode; if (bDebug) { EH.Put("Entering childnode: " + nextNode.Name); } } else //new node is at same level { this.m_currentNode = nextNode; if (bDebug) { EH.Put("Nextsibling : " + nextNode.Name); //nextNode.GetType().ToString() } } } // if (this.m_currentNode.GetType() == typeof(IfNode)) // this.m_currentNode = this.m_currentNode; //only ExpressionNodes can be executed, the others are only asked for next node. if (this.m_currentNode.GetType() != typeof(ExpressionNode)) { this.m_callStack.Push(this.m_currentNode); this.m_currentNode = null; return(this.Step()); } else { this.m_currentNode.Execute(this); //object oVal = return(true); } }
private void pivotSprite_MouseEvent(Sprite sender, System.Windows.Forms.MouseEventArgs e, Endogine.Sprite.MouseEventType t) { if (t == Endogine.Sprite.MouseEventType.StillDown) { EH.Put(e.X.ToString() + " " + e.Y.ToString() + this.m_sp.Loc.ToString()); sender.Loc += new EPointF(e.X, e.Y) - sender.MouseLastLoc.ToEPointF(); //TODO: setting the regpoint is not working when scaled. if (false) { EPoint pntLastRegPoint = this.m_sp.RegPoint.Copy(); this.m_sp.RegPoint = (sender.Loc / this.m_sp.Scaling).ToEPoint(); this.m_sp.Loc += (this.m_sp.RegPoint - pntLastRegPoint).ToEPointF(); this.Update(); } } }
public void Render() { if (this._executedRecordIndex >= this.AllReadObjects.Count - 1) { return; //For looping: //foreach (DictionaryEntry de in this._objectByDepth) // ((Sprite)de.Value).Dispose(); //this._objectByDepth.Clear(); //this._executedRecordIndex = 0; //loop from start } //EH.Put("New frame!" + this._executedRecordIndex.ToString() + "/"+this.AllReadObjects.Count.ToString()); ArrayList newSprites = new ArrayList(); ArrayList removedSprites = new ArrayList(); //loop through the parsed flash file: while (this._executedRecordIndex < this.AllReadObjects.Count - 1) { this._executedRecordIndex++; Record record = (Record)this.AllReadObjects[this._executedRecordIndex]; //EH.Put("Tag: "+record.Tag.ToString()); if (record is Placement.Placement) { // like "put member in sprite on stage" Placement.Placement placement = (Placement.Placement)record; Sprite spExisting = (Sprite)this._objectByDepth[placement.Depth]; Sprite sp = placement.Execute(this, spExisting); if (spExisting == null) { this._objectByDepth.Add(placement.Depth, sp); newSprites.Add(spExisting); } } else if (record is Placement.Remove) { Placement.Remove remove = (Placement.Remove)record; if (!this._objectByDepth.Contains(remove.Depth)) { EH.Put("Removing nonexistent sprite?"); } else { Sprite sp = (Sprite)this._objectByDepth[remove.Depth]; this._objectByDepth.Remove(remove.Depth); removedSprites.Add(sp); } } else if (record.Tag == Tags.SetBackgroundColor) { } else if (record.Tag == Tags.ShowFrame) { break; } } // foreach (Sprite sp in newSprites) // sp.Visible = true; foreach (Sprite sp in removedSprites) { sp.Dispose(); } float msecsPerFrame = 1000f / this.FrameRate; //float msecsPerFrame = 300; //; this._nextUpdateTime = DateTime.Now.Ticks + (int)(msecsPerFrame * 1000 * 10); }
/// <summary> /// Generates a Hashtable with Hashtables with Hashtables: PassNumber:[TextureName:[AnimationName:[ArrayList FileNames]]] /// </summary> /// <param name="definition"></param> /// <param name="pathWithPrefix"></param> /// <returns></returns> public static Hashtable GenerateFileLists(string definition, string overridePath) //TODO: Node overrides - can override anything { //Looks first at the Texture node to see what the textures should be called and which FrameSets they contain //For each texture, it loops through the FrameSets. //If the FrameSet should be included in the current pass, add it to the texure, else ignore it. Node rootNode = Endogine.Node.FromTabbed(definition); string path = null; string[] allFilesnames = null; if (rootNode["Input.Files"] != null) { allFilesnames = new string[rootNode["Input.Files"].ChildNodes.Count]; Node nodeX = rootNode["Input.Files"].FirstChild; for (int i = 0; i < rootNode["Input.Files"].ChildNodes.Count; i++) { allFilesnames[i] = nodeX.Name; nodeX = nodeX.NextSibling; } } else { path = rootNode["Input.Path"].Text; if (overridePath != null) { path = overridePath; } if (rootNode["Input.Search"] != null) { path += rootNode["Input.Search"].Text; } } //string path = GetFullSearchPathFromDefinition(definition, overridePath); //this will contain all passes (passNumber:textureHashList) Hashtable passNumberToTexture = new Hashtable(); bool usingPasses = false; #region Find all IDs and numbers used in Passes section int highestPassNum = 1; Hashtable predefRanges = null; //contains rangeId:range definition. //TODO: predefRanges is essentially useless! remove and replace with predefRangeIdToPassNumbers! Hashtable predefRangeIdToPassNumbers = null; //contains rangeId:[pass numbers] ArrayList allPassNumbers = new ArrayList(); //contains all numbers that occur in all the pass specifications Node passesNode = rootNode["Passes"]; if (passesNode != null) { usingPasses = true; predefRanges = new Hashtable(); predefRangeIdToPassNumbers = new Hashtable(); for (int i = 0; i < passesNode.ChildNodes.Count; i++) { Node n = passesNode[i]; ArrayList nums = Endogine.Text.IntervalString.CreateArrayFromIntervalString(n.Text); predefRanges.Add(n.Name, n.Text); predefRangeIdToPassNumbers.Add(n.Name, nums); foreach (int num in nums) { if (!allPassNumbers.Contains(num)) { highestPassNum = num > highestPassNum ? num : highestPassNum; allPassNumbers.Add(num); } } } } #endregion if (allPassNumbers.Count == 0) { allPassNumbers.Add(1); } Node texturesNode = rootNode["Textures"]; Node framesNode = rootNode["FrameSets"]; //Are the number specified for each frameset the actual numbers in the regex "variables" (eg [10-45]) //or just the order index (alphabetical sorting) bool bNumbersMeanOrder = false; if (allFilesnames != null) { bNumbersMeanOrder = true; } else if (rootNode["NumbersMeanOrder"] != null && rootNode["NumbersMeanOrder"].Text.ToLower() == "true") { bNumbersMeanOrder = true; allFilesnames = Endogine.Files.FileFinder.GetNamesFromFiles( Endogine.Files.FileFinder.GetFiles(path)); } MatchCollection msVariableMatched = null; if (allFilesnames == null) { msVariableMatched = GetVariableMatchesInSearchPattern(path); } foreach (int passNum in allPassNumbers) { Hashtable textureNameToAnimations = new Hashtable(); passNumberToTexture.Add(passNum, textureNameToAnimations); for (int texNum = 0; texNum < texturesNode.ChildNodes.Count; texNum++) { //find which framesets to use for this texture: Node node = texturesNode[texNum]; string[] frameSetNames = node.Text.Split(','); if (frameSetNames[0] == "All") { frameSetNames = new string[framesNode.ChildNodes.Count]; for (int i = 0; i < framesNode.ChildNodes.Count; i++) { frameSetNames[i] = framesNode[i].Name; } } Hashtable animationNameToFileLists = new Hashtable(); foreach (string frameSetName in frameSetNames) { string trimmedFrameSetName = frameSetName.Trim(); //TODO: rename range to pass! string[] ranges = framesNode[trimmedFrameSetName].Text.Split('\t'); if (bNumbersMeanOrder) { string range = ranges[1]; if (range.EndsWith("-")) { range += allFilesnames.Length - 1; } ArrayList indices = Endogine.Text.IntervalString.CreateArrayFromIntervalString(range); string[] filenames = new string[indices.Count]; for (int i = 0; i < indices.Count; i++) { filenames[i] = allFilesnames[(int)indices[i]]; } animationNameToFileLists.Add(trimmedFrameSetName, filenames); //animationNameToFileLists.Add(animationPrefix + trimmedFrameSetName, filenames); } else { //replace []'s in path with the ranges defined in the frameset: //first is the pass, second is string newPath = path; bool includeThisFrameSet = true; for (int i = 0; i < msVariableMatched.Count; i++) { //TODO: rename range to pass! string find = msVariableMatched[i].Value; string range = ranges[i]; string rangeID = range; if (char.IsLetter(range, 0)) { range = (string)predefRanges[range]; } //When doing passes, the first column is the one checked for pass numbers: if (usingPasses && i == 0) { //if pass is not included in the list, don't use in this pass if (char.IsLetter(range, 0)) { if (!((ArrayList)predefRangeIdToPassNumbers[rangeID]).Contains(passNum)) { includeThisFrameSet = false; } } else if (!Endogine.Text.IntervalString.CreateArrayFromIntervalString(range).Contains(passNum)) { includeThisFrameSet = false; } if (!includeThisFrameSet) { break; } range = passNum.ToString(); } //doesn't work with just one number, so make it number-number (13-13 instead of 13) if (range.IndexOf("-") < 0 && range.IndexOf(",") < 0) { range = range + "-" + range; } string replace = find.Insert(1, range); newPath = Endogine.Text.StringHelpers.Replace(newPath, find, replace, 1); } if (!includeThisFrameSet) { continue; } //EH.Put("FS "+trimmedFrameSetName+" "+newPath); string[] filenames = Endogine.Files.FileFinder.GetNamesFromFiles( Endogine.Files.FileFinder.GetFiles(newPath)); if (filenames.Length == 0) { EH.Put("No files found for frameset " + trimmedFrameSetName); } else { string animationPrefix = ""; if (rootNode["AnimationPrefix"] != null) { animationPrefix = rootNode["AnimationPrefix"].Text; } else { //TODO: should be able to extract AnimationPrefix from newPath somehow... //First [] or [pad:X] is simply replaced with passNum, and at the next occurrence, remove the rest //NOPE: exacly what we DON'T want: then add .+ to find anything that starts with this //@@actor0[1-1]_portrait[1-10pad:4] -> actor01_portrait //@@actor0\w_isoview0[1-1]_[1-20pad:4] -> actor0\w_isoview01_ //then look at the first found file that matches this: int indexStartFile = newPath.IndexOf("@@"); animationPrefix = newPath.Remove(0, indexStartFile + 2); string regexPattern = Endogine.Files.FileFinder.GetRegexPatternForRanges(); MatchCollection msRangeMatches = Regex.Matches(animationPrefix, regexPattern); if (msRangeMatches.Count > 0) { if (msRangeMatches.Count > 1) { animationPrefix = animationPrefix.Substring(0, msRangeMatches[1].Index); } //TODO: use my regex-like replacement. Now it doesn't care about padding. animationPrefix = Endogine.Text.StringHelpers.Replace(animationPrefix, msRangeMatches[0].Index, msRangeMatches[0].Length, passNum.ToString()); } //now we have actor01_portrait.+ Match m = Regex.Match(filenames[0], animationPrefix); if (m.Success) { animationPrefix = m.Value; } } //if (usingPasses) //the animation names should not be the same for the different passes - name after pass number // animationPrefix+=passNum.ToString().PadLeft(highestPassNum.ToString().Length, '0'); animationNameToFileLists.Add(animationPrefix + trimmedFrameSetName, filenames); } } } if (animationNameToFileLists.Count > 0) { textureNameToAnimations.Add(node.Name, animationNameToFileLists); } else { EH.Put("No files found for texture node " + node.Name); } } } return(passNumberToTexture); }