FSO.SimAntics.VM.Save C# (CSharp) Method

Save() public method

public Save ( ) : VMMarshal
return FSO.SimAntics.Marshals.VMMarshal
        public VMMarshal Save()
        {
            var ents = new VMEntityMarshal[Entities.Count];
            var threads = new VMThreadMarshal[Entities.Count];
            var mult = new List<VMMultitileGroupMarshal>();

            int i = 0;
            foreach (var ent in Entities)
            {
                if (ent is VMAvatar)
                {
                    ents[i] = ((VMAvatar)ent).Save();
                }
                else
                {
                    ents[i] = ((VMGameObject)ent).Save();
                }
                threads[i++] = ent.Thread.Save();
                if (ent.MultitileGroup.BaseObject == ent)
                {
                    mult.Add(ent.MultitileGroup.Save());
                }
            }

            return new VMMarshal
            {
                Context = Context.Save(),
                Entities = ents,
                Threads = threads,
                MultitileGroups = mult.ToArray(),
                GlobalState = GlobalState,
                PlatformState = PlatformState,
                ObjectId = ObjectId
            };
        }

Usage Example

        private void SaveHouseButton_OnButtonClick(UIElement button)
        {
            if (vm == null)
            {
                return;
            }

            var exporter = new VMWorldExporter();

            exporter.SaveHouse(vm, lotName);
            var marshal = vm.Save();

            if (!Directory.Exists(Path.Combine(FSOEnvironment.UserDir, "Houses/")))
            {
                Directory.CreateDirectory(Path.Combine(FSOEnvironment.UserDir, "Houses/"));
            }


            using (var output = new FileStream(Path.Combine(FSOEnvironment.UserDir, "Houses/house_00.fsov"), FileMode.Create))
            {
                marshal.SerializeInto(new BinaryWriter(output));
            }
            if (vm.GlobalLink != null)
            {
                ((VMTSOGlobalLinkStub)vm.GlobalLink).Database.Save();
            }
        }
All Usage Examples Of FSO.SimAntics.VM::Save