public string NameOf(Animation.Frame frame, Animation.Element element) { int precedingOccurences = occurenceCache.GetPrecedingOccurencesCount(frame, element); string name = $"{HashToName[element.Image]}_{element.Index}_{precedingOccurences}"; return(name); }
private XmlElement MakeBoneNode(XmlDocument scml, Animation.Element element) { XmlElement obj = scml.CreateElement(string.Empty, "bone", string.Empty); obj.SetAttribute("x", (element.M5 * 0.5f).ToString()); obj.SetAttribute("y", (element.M6 * -0.5f).ToString()); float scaleX = (float)Math.Sqrt(element.M1 * element.M1 + element.M2 * element.M2); float scaleY = (float)Math.Sqrt(element.M3 * element.M3 + element.M4 * element.M4); float det = element.M1 * element.M4 - element.M3 * element.M2; if (det < 0) { scaleY = -scaleY; } float sinApprox = 0.5f * (element.M3 / scaleY - element.M2 / scaleX); float cosApprox = 0.5f * (element.M1 / scaleX + element.M4 / scaleY); float angle = (float)Math.Atan2(sinApprox, cosApprox); if (angle < 0) { angle += (float)(2 * Math.PI); } angle *= (float)(180.0f / Math.PI); obj.SetAttribute("angle", angle.ToString()); obj.SetAttribute("scale_x", scaleX.ToString()); obj.SetAttribute("scale_y", scaleY.ToString()); return(obj); }
private XmlElement MakeObjectNode(XmlDocument scml, Animation.Element element, FileIdProvider fileIdProvider) { XmlElement obj = scml.CreateElement(string.Empty, "object", string.Empty); obj.SetAttribute("folder", "0"); obj.SetAttribute("file", GetThisOrPrecedingFile(element, fileIdProvider)); return(obj); }
/** * Gets the number of times the sprite used by this element was used by elements * in the given frame that came before this element in the frame's element list. * * Uses a simple caching scheme based on the frame for performance improvements. */ public int GetPrecedingOccurencesCount(Animation.Frame frame, Animation.Element element) { if (frame != associatedFrame) { RebuildCache(frame); } return(occurenceMap[element]); }
private XmlElement MakeBoneRefNode(XmlDocument scml, Animation.Frame frame, Animation.Element element, int frameId, SymbolIdProvider symbolIdProvider) { XmlElement boneRef = scml.CreateElement(string.Empty, "bone_ref", string.Empty); int id = symbolIdProvider.GetId(frame, element); boneRef.SetAttribute("id", id.ToString()); boneRef.SetAttribute("timeline", id.ToString()); boneRef.SetAttribute("key", frameId.ToString()); return(boneRef); }
private XmlElement MakeTimelineKeyNode(XmlDocument scml, Animation.Element element, int frameId, int rate, FileIdProvider fileIdProvider, ChildType childType) { XmlElement key = scml.CreateElement(string.Empty, "key", string.Empty); key.SetAttribute("id", frameId.ToString()); key.SetAttribute("time", (frameId * rate).ToString()); switch (childType) { case ChildType.Sprite: key.AppendChild(MakeObjectNode(scml, element, fileIdProvider)); break; case ChildType.Bone: key.AppendChild(MakeBoneNode(scml, element)); break; } return(key); }
private string GetThisOrPrecedingFile(Animation.Element element, FileIdProvider fileIdProvider) { int index = element.Index; while (index >= 0) { string name = $"{AnimationFile.HashToName[element.Image]}_{index}"; try { return(fileIdProvider.NameToFileId[name].ToString()); } catch { index--; } } // If a file doesn't exist for the sprite then assume that this is intentional and return no corresponding file // Note that this is done because there are some sprites defined in Klei's animation files that do not have // any corresponding actual texture/file to go with. return(""); }
public int GetId(Animation.Frame frame, Animation.Element element) { string name = NameOf(frame, element); return(IdMap[name]); }
private XmlElement MakeObjectRefNode(XmlDocument scml, Animation.Frame frame, Animation.Element element, int frameId, int elementId, SpriteIdProvider spriteIdProvider, SymbolIdProvider symbolIdProvider) { XmlElement objectRef = scml.CreateElement(string.Empty, "object_ref", string.Empty); string id = spriteIdProvider.GetId(frame, element).ToString(); objectRef.SetAttribute("id", id); objectRef.SetAttribute("parent", symbolIdProvider.GetId(frame, element).ToString()); objectRef.SetAttribute("timeline", id); objectRef.SetAttribute("key", frameId.ToString()); objectRef.SetAttribute("z_index", (frame.Elements - elementId).ToString()); return(objectRef); }