예제 #1
0
    /// <summary>
    /// Loads a creature from the contents of a save file.
    /// </summary>
    public static void LoadCreatureFromContents(string contents, CreatureBuilder builder)
    {
        BodyComponent.ResetID();
        var components = contents.Split(SPLIT_ARRAY, System.StringSplitOptions.None);

        var jointStrings  = components[0].Split('\n');       //.Split(NEWLINE_SPLIT, StringSplitOptions.None);
        var boneStrings   = components[1].Split('\n');       //Split(NEWLINE_SPLIT, StringSplitOptions.None);
        var muscleStrings = components[2].Split('\n');       //Split(NEWLINE_SPLIT, StringSplitOptions.None);

        var joints  = new List <Joint>();
        var bones   = new List <Bone>();
        var muscles = new List <Muscle>();

        // create all the joints
        foreach (var data in jointStrings)
        {
            if (data.Length > 0)
            {
                joints.Add(Joint.CreateFromString(data));
            }
        }
        // create all the bones
        foreach (var data in boneStrings)
        {
            if (data.Length > 0)
            {
                bones.Add(Bone.CreateFromString(data, joints));
            }
        }
        // create all the muscles
        foreach (var data in muscleStrings)
        {
            if (data.Length > 1)
            {
                muscles.Add(Muscle.CreateFromString(data, bones));
            }
        }

        builder.SetBodyComponents(joints, bones, muscles);
    }