예제 #1
0
        public OrbitalFrame FrameFor(FreeBody body)
        {
            if (body == null)
            {
                return(null);
            }

            OrbitalFrame frame = new OrbitalFrame();
            //  Search for cyclic references between bodies (merged frames)

            var cyclicBodies =
                CelestialBodies.Where(c => c.FrameId == body.Id)                       // for all celestials orbiting this object
                .Where(c => body.CelestialContexts.Any(cc => cc.FrameId == c.Body.Id)) // for all orbiters that have a celestial-context whose frame is this object
                .Select(c => c.Body);                                                  // select those orbiters

            frame.Reference.Add(body);
            frame.Reference.AddRange(cyclicBodies);


            //  Find children of merged frame celestials
            var children = CelestialBodies.Where(c => frame.Reference.Any(r => r.Id == c.FrameId));

            frame.CelestialBodies.AddRange(children);
            frame.CelestialBodies.RemoveAll(c => frame.Reference.Any(r => r.Id == c.BodyId));



            frame.CelestialBodies = frame.CelestialBodies.OrderBy(cb => cb.CenterDistance.AsMeters).ToList();

            return(frame);
        }
예제 #2
0
        String SaveBody(String bodyFile, FreeBody body)
        {
            switch (body.Type)
            {
            case FreeBody.BodyType.Asteroid: return(SaveBody(bodyFile, body as Asteroid));

            case FreeBody.BodyType.Belt: return(SaveBody(bodyFile, body as Belt));

            case FreeBody.BodyType.BlackHole: return(SaveBody(bodyFile, body as BlackHole));

            case FreeBody.BodyType.Comet: return(SaveBody(bodyFile, body as Comet));

            case FreeBody.BodyType.MegaStructure: return(SaveBody(bodyFile, body as MegaStructure));

            case FreeBody.BodyType.Moon: return(SaveBody(bodyFile, body as Moon));

            case FreeBody.BodyType.Planet: return(SaveBody(bodyFile, body as Planet));

            case FreeBody.BodyType.Star: return(SaveBody(bodyFile, body as Star));

            case FreeBody.BodyType.Settlement: return(SaveBody(bodyFile, body as Settlement));

            case FreeBody.BodyType.WarpGate: return(SaveBody(bodyFile, body as WarpGate));
            }

            throw new InvalidOperationException();
        }
예제 #3
0
        public void Delete(FreeBody body)
        {
            var frame = FrameFor(body);

            //  If the body shares a frame, transfer its celestials to the co-body
            if (frame.Reference.Count > 1)
            {
                var alternate = frame.Reference.First(r => r.Id != body.Id);
                foreach (var celestial in frame.CelestialBodies)
                {
                    if (celestial.FrameId == body.Id)
                    {
                        celestial.SetFrame(alternate);
                    }
                }
            }
            else
            {
                //  Otherwise it's removed as a reference from children referencing it
                foreach (var celestial in frame.CelestialBodies)
                {
                    celestial.Body.CelestialContexts.Remove(celestial);
                }
            }



            _Bodies.Remove(body);
            _WorkingDefaults.Remove(body);

            File.Delete(_WorkingSerializations.Single(p => p.Key.Id == body.Id).Value.Filename);
            _WorkingSerializations.Remove(body);
        }
예제 #4
0
 public FreeBody(FreeBody source)
 {
     Name  = source.Name;
     Notes = source.Notes;
     GalacticCoordinate = new Coordinate(source.GalacticCoordinate);
     Radiation          = new Percent(source.Radiation);
     RotationsPerYear   = source.RotationsPerYear;
     Axis = new Coordinate(source.Axis);
     CelestialContexts = new List <CelestialBody>();
 }
예제 #5
0
        private int RankBody(String search, FreeBody body)
        {
            List <int> diffs = new List <int>();

            diffs.Add(Levenshtein(search, body.Name));
            diffs.Add(Levenshtein(search, body.Type.ToString()));
            diffs.Add(Levenshtein(search, body.Notes));

            diffs.Add(Math.Max(0, search.Length - body.Name.LongestCommonSubsequence(search).Length));
            diffs.Add(Math.Max(0, search.Length - body.Type.ToString().LongestCommonSubsequence(search).Length));
            diffs.Add(Math.Max(0, search.Length - body.Notes.LongestCommonSubsequence(search).Length));

            switch (body.Type)
            {
            case FreeBody.BodyType.MegaStructure:
                diffs.Add(Levenshtein(search, (body as MegaStructure).StructureKind.ToString()));
                break;
            }

            return(diffs.Min());
        }
예제 #6
0
 public void Add(FreeBody body, FreeBody defaultSample)
 {
     _Bodies.Add(body);
     _WorkingDefaults.Add(body, defaultSample);
 }
예제 #7
0
        /*
         * A default is a set of assumptions about some system
         * Some properties based on a default may have different values
         * We want to keep these properties but also maintain relativity to the default
         * Particularly - the default also represents an additional intent for the subject; the default acts as its context
         *          .. a default needs a DATE of last significant edit
         *
         * As such, for continuous default manipulation, a history of the default must be kept in order to recognize
         * previous references (and thus synchronize procedural manipulations)
         */

        public void ChangeDefault(FreeBody body, FreeBody newDefault)
        {
            //  update the defaults used in the body's values, changes the associated default
        }
예제 #8
0
 public void SetBody(FreeBody body)
 {
     BodyId = body.Id;
     Body   = body;
 }
예제 #9
0
 public void SetFrame(FreeBody frame)
 {
     FrameId = frame.Id;
     Frame   = frame;
 }