Example #1
0
    public void Save()
    {
        var pEntity = new PlayerEntity()
        {
            Position = picker.transform.position, Speed = 4
        };
        var lEntitiy = new LevelEntity()
        {
            CurrentProbCount  = LevelManager.CurrentSection.CurrentProbCount,
            ExpectedProbCount = LevelManager.CurrentSection.ExpectedProbCount,
            ActiveProbs       = LevelManager.CurrentSection.ActiveProbs.Select(x => new ProbEntity()
            {
                Position        = x.transform.position,
                Velocity        = x.GetComponent <Rigidbody>().velocity,
                AngularVelocity = x.GetComponent <Rigidbody>().angularVelocity,
                ProbType        = x.GetComponent <Probs>().ProbType,
            }).ToList(),
            CurrentLevel = LevelManager.CurrentLevel,
            LevelIndex   = LevelManager.CurrentSection.LevelIndex,
            Position     = LevelManager.CurrentSection.transform.position
        };

        var sEntity = new SaveEntity()
        {
            CurrentLevel = 0,
            LevelEntity  = lEntitiy,
            PlayerEntity = pEntity,
        };

        var json = JsonConvert.SerializeObject(sEntity);

        _savePath = Path.Combine(Application.persistentDataPath, "SaveData.json");
        File.WriteAllText(_savePath, json);
    }
Example #2
0
        /// <summary>
        /// Método invocado para iniciar el hilo para guardar entidades
        /// </summary>
        /// <param name="control">El componente que invoca al método</param>
        /// <param name="saver">El delegado que realiza el guardado</param>
        /// <param name="session">La clave de sesión</param>
        /// <param name="entity">La entidad a guardar</param>
        /// <param name="onFinished">Método invocado al finalizar</param>
        static public void Save(UserControl1 control, SaveEntity saver, string session, IEntity entity, OnSaveFinished onFinished)
        {
            SaverParameters saverParams = new SaverParameters(control, saver, session, entity, onFinished);
            Thread          thread      = new Thread(new ParameterizedThreadStart(DoSave));

            thread.Start(saverParams);
        }
        internal static void RegisterEntity(SaveEntity e)
        {
            if (SceneEntities.ContainsKey(e.ID))
            {
                Debug.Log("Entity with this ID already exists, i will assume you duplicated it in the editor, so ill assign a new instance ID for you.");
                e.instanceID = 0;
            }
            SceneEntities.Add(e.ID, e);

            //var persistent_root = e.transform.GetComponentInParent<PersistentDataSystem>();
            //if (persistent_root != null) {
            //
            //
            //}
            //else {
            //    if (PersistentEntities.ContainsKey(e.ID)) {
            //        Debug.Log("Entity with this ID already exists, i will assume you duplicated it in the editor, so ill /assign /a new instance ID for you.");
            //        e.instanceID = 0;
            //    }
            //    PersistentEntities.Add(e.ID, e);
            //}

            if (OnAdded != null)
            {
                OnAdded(e);
            }
        }
        public static void MakePersistent(SaveEntity entity)
        {
            UnityEngine.Object.DontDestroyOnLoad(entity.gameObject);

            entity.transform.parent = instance.PersistentDataRoot;

            SaveEntityManager.MarkPersistent(entity);
        }
 /// <summary>
 /// Constructor de clase
 /// </summary>
 /// <param name="control">El componente que invoca el proceso</param>
 /// <param name="saver">El delegado que realiza el proceso</param>
 /// <param name="session">La clave de sesión</param>
 /// <param name="entity">La entidad a guardar</param>
 /// <param name="onFinished">Método invocado cuando finaliza el proceso</param>
 public SaverParameters(UserControl1 control, SaveEntity saver, string session, IEntity entity, OnSaveFinished onFinished)
 {
     this.control    = control;
     this.saver      = saver;
     this.session    = session;
     this.entity     = entity;
     this.onFinished = onFinished;
 }
 internal static void UnRegisterEntity(SaveEntity e)
 {
     if (Application.isPlaying)
     {
         SceneEntities.Remove(e.ID);
         PersistentEntities.Remove(e.ID);
         if (OnRemoved != null)
         {
             OnRemoved(e);
         }
     }
 }
 /// <summary>
 /// Constructor de clase.
 /// </summary>
 /// <param name="control">Una referencia al control que contiene este componente.</param>
 /// <param name="manager">El componente que muestra la lista de entidades.</param>
 /// <param name="editor">El componente que permite añadir o modificar una entidad.</param>
 /// <param name="firstElement">El componente que debe enfocarse cuando se muestra el editor.</param>
 /// <param name="loader">Un método para cargar las entidades en un hilo separado.</param>
 /// <param name="saver">Un método para guardar una entidad en un hilo separado.</param>
 /// <param name="remover">Un método para eliminar una entidad en un hilo separado.</param>
 protected ControllerBase(UserControl1 control, FrameworkElement manager, FrameworkElement editor,
                          FrameworkElement firstElement, LoadList loader, SaveEntity saver,
                          RemoveEntity remover)
 {
     this.control      = control;
     this.manager      = manager;
     this.editor       = editor;
     this.firstElement = firstElement;
     this.loader       = loader;
     this.saver        = saver;
     this.remover      = remover;
 }
        public WeeklyNotes SaveNote([FromBody] WeeklyNotes value)
        {
            SaveEntity se = new SaveEntity();

            if (se.SaveWeeklyNote(value))
            {
                return(value);
            }
            else
            {
                return(null);
            }
        }
        public int SaveSummaryAndPlan([FromBody] SummaryAndPlan value)
        {
            SaveEntity se = new SaveEntity();

            if (se.SaveSummary(value))
            {
                return(1);
            }
            else
            {
                return(0);
            }
        }
Example #10
0
        public override void Save(SaveEntity <Order> saveEntity)
        {
            Order order = saveEntity.Entity;

            if (saveEntity.IsAdded)
            {
                order = new Order
                {
                    UserId = 1,
                    IsPaid = false,
                    Lines  = new List <OrderLine>()
                };

                this.Context.Orders.Add(order);
                saveEntity.Entity = order;
            }
            else
            {
                if (order.IsPaid)
                {
                    throw new Exception("Cannot modify an order after it has been paid.");
                }
            }

            foreach (var orderLineInfo in saveEntity.Get <OrderLine>())
            {
                OrderLine orderLine = orderLineInfo.Entity;

                if (orderLineInfo.IsAdded)
                {
                    orderLine = new OrderLine();
                    order.Lines.Add(orderLine);
                    orderLineInfo.Entity = orderLine;
                }

                orderLineInfo.Apply(ol => ol.Quantity);
                orderLineInfo.Apply(ol => ol.ProductId);

                if (orderLineInfo.IsDeleted)
                {
                    this.Context.Entry(orderLine).State = EntityState.Deleted;
                }
            }

            if (saveEntity.IsDeleted)
            {
                this.Context.Entry(order).State = EntityState.Deleted;
            }
        }
        public bool Apply(SaveObjectModel rootItem)
        {
            var players = rootItem.FindChild("Char_Player.Char_Player_C", false);

            if (players == null)
            {
                MessageBox.Show("This save does not contain a Player.\nThis means that the loaded save is probably corrupt. Aborting.", "Cannot find Player", MessageBoxButton.OK, MessageBoxImage.Error);
                return(false);
            }
            int currentStorageID = 0;

            foreach (SaveObjectModel player in players.DescendantSelfViewModel)
            {
                string          inventoryPath      = player.FindField <ObjectPropertyViewModel>("mInventory").Str2;
                SaveObjectModel inventoryState     = rootItem.FindChild(inventoryPath, false);
                SaveComponent   inventoryComponent = (SaveComponent)inventoryState.Model;
                currentStorageID = GetNextStorageID(currentStorageID, rootItem);
                SaveComponent newInventory = new SaveComponent(inventoryComponent.TypePath, inventoryComponent.RootObject, $"Persistent_Level:PersistentLevel.BP_Crate_C_{currentStorageID}.inventory")
                {
                    ParentEntityName = $"Persistent_Level:PersistentLevel.BP_Crate_C_{currentStorageID}",
                    DataFields       = inventoryComponent.DataFields
                };
                rootItem.FindChild("FactoryGame.FGInventoryComponent", false).Items.Add(new SaveComponentModel(newInventory));
                SaveEntity newSaveObject = new SaveEntity("/Game/FactoryGame/-Shared/Crate/BP_Crate.BP_Crate_C", "Persistent_Level", $"Persistent_Level:PersistentLevel.BP_Crate_C_{currentStorageID}")
                {
                    NeedTransform = true,
                    Rotation      = ((SaveEntity)player.Model).Rotation,
                    Position      = ((SaveEntity)player.Model).Position,
                    Scale         = new SatisfactorySaveParser.Structures.Vector3()
                    {
                        X = 1, Y = 1, Z = 1
                    },
                    WasPlacedInLevel = false,
                    ParentObjectName = "",
                    ParentObjectRoot = ""
                };
                newSaveObject.DataFields = new SerializedFields();
                newSaveObject.DataFields.Add(new ObjectProperty("mInventory", 0)
                {
                    LevelName = "Persistent_Level", PathName = $"Persistent_Level:PersistentLevel.BP_Crate_C_{currentStorageID}.inventory"
                });
                rootItem.FindChild("BP_Crate.BP_Crate_C", false).Items.Add(new SaveEntityModel(newSaveObject));
                rootItem.Remove(player);
                rootItem.Remove(inventoryState);
                MessageBox.Show($"Killed {player.Title}.", "Success", MessageBoxButton.OK, MessageBoxImage.Information);
            }
            return(true);
        }
Example #12
0
    // 加载数据
    static public void Load()
    {
        // 读取存档文件
        string    savePath = "Save/save";
        TextAsset text     = Resources.Load <TextAsset>(savePath);
        string    json     = text.text;

        saveEntity = SaveEntity.fromJson(json);

        // 读取CardsInfo
        string cardsInfoPath = "Save/CardsInfo";

        text            = Resources.Load <TextAsset>(cardsInfoPath);
        json            = text.text;
        cardsInfoEntity = CardsInfoEntity.fromJson(json);
    }
Example #13
0
        /// <summary>
        /// 保存实体
        /// </summary>
        /// <param name="fbEntityList"></param>
        /// <returns></returns>
        public SaveResult Save(SaveEntity saveEntity)
        {
            SaveResult result = new SaveResult();

            try
            {
                result.FBEntity   = base.SaveEntityBLLSave(saveEntity);
                result.Successful = true;
            }
            catch (FBBLLException ex)
            {
                result.Successful = false;
                result.Exception  = ex.Message;
                SystemBLL.Debug(ex.ToString());
            }
            return(result);
        }
Example #14
0
        /// <summary>
        /// 保存实体
        /// </summary>
        /// <param name="fbEntityList"></param>
        /// <returns></returns>
        public SaveResult Save(SaveEntity saveEntity)
        {

            SaveResult result = new SaveResult();
            try
            {
                result.FBEntity = base.SaveEntityBLLSave(saveEntity);
                result.Successful = true;
            }
            catch (FBBLLException ex)
            {
                result.Successful = false;
                result.Exception = ex.Message;
                SystemBLL.Debug(ex.ToString());

            }
            return result;
        }
Example #15
0
 public SaveResult Save(SaveEntity saveEntity)
 {
     using (FBCommonBLL fbCommonBLL = new FBCommonBLL())
     {
         SaveResult result = new SaveResult();
         try
         {
             result = fbCommonBLL.Save(saveEntity);
         }
         catch (Exception ex)
         {
             result.Successful = false;
             result.Exception  = ex.Message;
             Tracer.Debug(ex.ToString());
         }
         return(result);
     }
 }
        public NoteAndSummary SaveNoteAndSumAndPlan([FromBody] NoteAndSummary value)
        {
            NoteAndSummary Item = (NoteAndSummary)value;
            SaveEntity     se   = new SaveEntity();

            if (value == null)
            {
                return(value);
            }
            if (se.SaveWeeklyNote(Item.notes) && se.SaveSummary(Item.sumandplan))
            {
                return(value);
            }
            else
            {
                return(null);
            }
        }
Example #17
0
            public IUserAssetEntity GetEntity(Guid guid)
            {
                return(entities.GetOrCreate(guid, () =>
                {
                    var element = elements.GetOrThrow(guid);

                    Type type = UserAssetNames.GetOrThrow(element.Name.ToString());

                    var entity = giRetrieveOrCreate.GetInvoker(type)(guid);

                    if (entity.IsNew || overrideEntity.ContainsKey(guid))
                    {
                        entity.FromXml(element, this);

                        SaveEntity.Invoke((Entity)entity);
                    }

                    return entity;
                }));
            }
Example #18
0
        public static void UnboxSaveObject(SaveObject save, Transform root)
        {
            if (save == null)
            {
                Debug.LogError("Save object is null");
                return;
            }

            var initializedfield = typeof(SavedComponent).GetField("m_initialized", BindingFlags.NonPublic | BindingFlags.Instance);

            Dictionary <int, SaveEntity> bp_entity = null;
            Dictionary <int, Dictionary <int, SavedComponent> > bp_parent_component = null;
            Dictionary <int, Dictionary <int, SavedComponent> > bp_all_comp         = new Dictionary <int, Dictionary <int, SavedComponent> >();

            if (save.isBlueprint)
            {
                bp_entity           = new Dictionary <int, SaveEntity>();
                bp_parent_component = new Dictionary <int, Dictionary <int, SavedComponent> >();
                bp_all_comp         = new Dictionary <int, Dictionary <int, SavedComponent> >();
            }

            bool blueprintEditorMode = save.isBlueprint && !Application.isPlaying;

            Dictionary <int, ComponentObject> cobjects = null;
            Dictionary <int, Dictionary <int, SavedComponent> > allComps = new Dictionary <int, Dictionary <int, SavedComponent> >();
            Dictionary <int, SaveEntity>          allEntities            = new Dictionary <int, SaveEntity>();
            Dictionary <EntityObject, SaveEntity> toParent = new Dictionary <EntityObject, SaveEntity>();
            List <SavedComponent> allComponents            = new List <SavedComponent>();

            foreach (var eobj in save.entities)
            {
                var prefab = SaveEntityDatabase.GetPrefab(eobj.database_ID);

                if (!prefab)
                {
                    Debug.LogError("When loading, database entity: " + eobj.database_ID + " was not found, this probably means you saved an entity that is not registered in database. Make it a prefab in Entity folder and run database scan.");
                    continue;
                }
                bool prefabState = prefab.activeSelf;
                prefab.SetActive(false);
                GameObject gameobj = null;
#if UNITY_EDITOR
                if (blueprintEditorMode)
                {
                    gameobj = PrefabUtility.InstantiatePrefab(prefab) as GameObject;
                }
                else
                {
                    gameobj = GameObject.Instantiate(prefab);
                }
#else
                gameobj = GameObject.Instantiate(prefab);
#endif
                gameobj.name = eobj.gameObjectName;
                var tr = gameobj.transform;

                GameObject parentGo = null;
                if (eobj.parentName != "null")
                {
                    parentGo = GameObject.Find(eobj.parentName);
                }

                if (save.isBlueprint)
                {
                    tr.parent        = root;
                    tr.localPosition = eobj.position;
                    tr.localRotation = Quaternion.Euler(eobj.rotation);
                }
                else
                {
                    tr.position = eobj.position;
                    tr.rotation = Quaternion.Euler(eobj.rotation);
                    tr.parent   = eobj.parentName == "null" ? root : parentGo == null ? root : parentGo.transform;
                }

                var entity = gameobj.GetComponent <SaveEntity>();
                Dictionary <int, SavedComponent> ecomps  = null;
                Dictionary <int, SavedComponent> bpcomps = null;

                if (save.isBlueprint)
                {
                    bp_entity.Add(eobj.blueprint_ID, entity);
                    bp_all_comp.TryGetValue(eobj.blueprint_ID, out bpcomps);
                    if (bpcomps == null)
                    {
                        bpcomps = new Dictionary <int, SavedComponent>();
                        bp_parent_component.Add(eobj.blueprint_ID, bpcomps);
                    }
                    bp_parent_component.TryGetValue(eobj.blueprint_ID, out ecomps);
                    if (ecomps == null)
                    {
                        ecomps = new Dictionary <int, SavedComponent>();
                        bp_parent_component.Add(eobj.blueprint_ID, ecomps);
                    }
                }
                else
                {
                    allEntities.Add(eobj.instance_ID, entity);
                }

                entity.instanceID  = eobj.instance_ID;
                entity.blueprintID = eobj.blueprint_ID;

                if (eobj.parentIsComponent || eobj.parentIsEntity)
                {
                    toParent.Add(eobj, entity);
                }

                var comps = gameobj.GetComponentsInChildren <SavedComponent>(true);
                if (comps.Length != 0)
                {
                    if (save.isBlueprint)
                    {
                        save.components.TryGetValue(entity.blueprintID, out cobjects);
                    }
                    else
                    {
                        save.components.TryGetValue(entity.instanceID, out cobjects);
                    }

                    if (cobjects != null)
                    {
                        foreach (var component in comps)
                        {
                            if (save.isBlueprint)
                            {
                                ecomps.Add(component.componentID, component);
                            }

                            ComponentObject cobj = null;
                            cobjects.TryGetValue(component.componentID, out cobj);
                            if (cobj != null)
                            {
                                SetDataForComponent(component, cobj.data);
                                initializedfield.SetValue(component, cobj.initialized);
                                component.enabled = cobj.enabled;
                            }

                            //Storing for later reference injection
                            Dictionary <int, SavedComponent> injectionDict = null;
                            allComps.TryGetValue(entity.ID, out injectionDict);
                            if (injectionDict == null)
                            {
                                injectionDict = new Dictionary <int, SavedComponent>();
                                allComps.Add(entity.ID, injectionDict);
                            }
                            injectionDict.Add(component.componentID, component);

                            allComponents.Add(component);
                        }
                    }
                }

                if (save.isBlueprint)
                {
                    entity.instanceID = 0;
                }



                prefab.SetActive(prefabState);

                if (eobj.Enabled)
                {
                    entity.gameObject.SetActive(true);
                }
                else
                {
                    entity.InitializeDisabled();
                }
                //HACK change this to something like interface.
                //entity.gameObject.BroadcastMessage("OnAfterLoad", SendMessageOptions.DontRequireReceiver);
            }

            if (CompRefSerializationProcessor.refs != null && CompRefSerializationProcessor.refs.Count > 0)
            {
                foreach (var compref in CompRefSerializationProcessor.refs)
                {
                    if (!compref.isNull)
                    {
                        Dictionary <int, SavedComponent> comps = null;
                        SavedComponent cbase = null;

                        if (save.isBlueprint)
                        {
                            bp_parent_component.TryGetValue(compref.entity_ID, out comps);
                        }
                        else
                        {
                            allComps.TryGetValue(compref.entity_ID, out comps);
                        }

                        if (comps != null)
                        {
                            if (save.isBlueprint)
                            {
                                bp_parent_component[compref.entity_ID].TryGetValue(compref.component_ID, out cbase);
                            }
                            else
                            {
                                comps.TryGetValue(compref.component_ID, out cbase);
                            }
                            if (cbase != null)
                            {
                                compref.component = cbase;
                            }
                            else
                            {
                                Debug.LogError("CompRef linker could not find component with id: " + compref.component_ID + " on entity: " + compref.entityName);
                            }
                        }
                        else
                        {
                            Debug.LogError("CompRef linker could not find entity with id: " + compref.entity_ID + " on entity: " + compref.entityName);
                        }
                    }
                }
            }
#if UNITY_EDITOR
            if (blueprintEditorMode)
            {
                foreach (var e in bp_entity)
                {
                    var go = PrefabUtility.FindPrefabRoot(e.Value.gameObject);
                    PrefabUtility.DisconnectPrefabInstance(go);
                    PrefabUtility.ReconnectToLastPrefab(go);
                }
            }
#endif
            if (save.isBlueprint)
            {
                if (blueprintEditorMode)
                {
#if UNITY_EDITOR
                    foreach (var pair in toParent)
                    {
                        SaveEntity e  = pair.Value;
                        var        go = PrefabUtility.FindPrefabRoot(e.gameObject);
                        PrefabUtility.DisconnectPrefabInstance(go);

                        EntityObject eobj   = pair.Key;
                        Transform    parent = null;
                        if (eobj.parentIsComponent)
                        {
                            parent = bp_parent_component[eobj.parent_entity_ID][eobj.parent_component_ID].transform;
                        }
                        else if (eobj.parentIsEntity)
                        {
                            parent = bp_entity[eobj.parent_entity_ID].transform;
                        }
                        e.transform.SetParent(parent);
                        PrefabUtility.ReconnectToLastPrefab(go);
                    }
#endif
                }
                else
                {
                    foreach (var pair in toParent)
                    {
                        SaveEntity   e      = pair.Value;
                        EntityObject eobj   = pair.Key;
                        Transform    parent = null;
                        if (eobj.parentIsComponent)
                        {
                            parent = bp_parent_component[eobj.parent_entity_ID][eobj.parent_component_ID].transform;
                        }
                        else if (eobj.parentIsEntity)
                        {
                            parent = bp_entity[eobj.parent_entity_ID].transform;
                        }
                        e.transform.SetParent(parent);
                    }
                }
            }
            else
            {
                foreach (var pair in toParent)
                {
                    SaveEntity   e      = pair.Value;
                    EntityObject eobj   = pair.Key;
                    Transform    parent = null;
                    if (eobj.parentIsComponent)
                    {
                        parent = allComps[eobj.parent_entity_ID][eobj.parent_component_ID].transform;
                    }
                    else if (eobj.parentIsEntity)
                    {
                        parent = allEntities[eobj.parent_entity_ID].transform;
                    }
                    e.transform.SetParent(parent);
                }
            }

            foreach (var comp in allComponents)
            {
                comp.SendMessage("OnAfterLoad", SendMessageOptions.DontRequireReceiver);
            }
        }
Example #19
0
        public SaveResult Save(SaveEntity saveEntity)
        {
            using (FBCommonBLL fbCommonBLL = new FBCommonBLL())
            {
                SaveResult result = new SaveResult();
                try
                {
                    result = fbCommonBLL.Save(saveEntity);
                }
                catch (Exception ex)
                {
                    result.Successful = false;
                    result.Exception = ex.Message;
                    Tracer.Debug(ex.ToString());

                }
                return result;
            }
        }
Example #20
0
        /// <summary>
        /// 保存预算申请单
        /// </summary>
        /// <param name="statates">当前表单状态</param>
        public void Save(CheckStates statates)
        {
            List <string> listMsg = this.OnSaveCheck();

            if (listMsg.Count > 0)
            {
                OnSaveCompleted(listMsg);
                return;
            }
            this.GetValue();


            if (statates == CheckStates.Delete)
            {
                ExtensionalOrderFBEntity.FBEntityState = FBEntityState.Detached;
            }
            // else if如果是重新提交,如果当前单据是审核不通过的状态才可以重新提交,否则提示异常。
            // 需处理 this.Order.CHECKSTATES 为提交状态,并this.CurrentOrderEntity.FBEntityState 为重新提交
            else
            {
                if (submitFBFormTypes == FormTypes.Audit && statates == CheckStates.Approving)
                {
                    return;
                }


                this.ExtensionalOrder.CHECKSTATES = Convert.ToDecimal((int)statates);

                if (submitFBFormTypes == FormTypes.Resubmit)
                {
                    this.ExtensionalOrderFBEntity.FBEntityState = FBEntityState.ReSubmit;
                }
                else
                {
                    if (this.ExtensionalOrderFBEntity.FBEntityState == FBEntityState.Unchanged)
                    {
                        this.ExtensionalOrderFBEntity.FBEntityState = FBEntityState.Modified;
                    }
                }
            }
            if (this.IsFromFB)
            {
                QueryExpression qeSave = this.GetOrderQueryExp();
                SaveEntity      se     = new SaveEntity();
                se.QueryExpression = qeSave;
                se.FBEntity        = ExtensionalOrderFBEntity;
                FBServiceLoacal.SaveEntityAsync(se);
            }
            else
            {
                ObservableCollection <SMT.Saas.Tools.WpServiceWS.BussinessTripBudget> listTripBudget = new ObservableCollection <Saas.Tools.WpServiceWS.BussinessTripBudget>();

                foreach (var itemRM in ExtensionalOrderFBEntity.CollectionEntity)
                {
                    if (itemRM.EntityType == typeof(T_FB_EXTENSIONORDERDETAIL).Name ||
                        itemRM.EntityType == "T_FB_EXTENSIONORDERDETAIL_Travel")
                    {
                        foreach (var item in itemRM.FBEntities)
                        {
                            SMT.Saas.Tools.WpServiceWS.BussinessTripBudget saveItem = new Saas.Tools.WpServiceWS.BussinessTripBudget();
                            T_FB_EXTENSIONORDERDETAIL detail = item.Entity as T_FB_EXTENSIONORDERDETAIL;
                            //saveItem.SubjectID = detail.T_FB_SUBJECT.SUBJECTID;
                            saveItem.SubjectName = detail.T_FB_SUBJECT.SUBJECTNAME;
                            saveItem.SubjectCode = detail.T_FB_SUBJECT.SUBJECTCODE;
                            saveItem.PaidMoney   = detail.APPLIEDMONEY;
                            saveItem.UseMoney    = detail.USABLEMONEY.Value;
                            saveItem.NormName    = detail.REMARK;                 //摘要
                            saveItem.NormID      = detail.T_FB_SUBJECT.SUBJECTID; //摘要
                            if (string.IsNullOrEmpty(saveItem.NormID))
                            {
                                MessageBox.Show("工作计划保存科目Id失败,请联系管理员!");
                            }
                            listTripBudget.Add(saveItem);
                        }
                    }
                }
                string msg = string.Empty;
                WpServiceClient.TripSubjectSaveAsync(strBussinessTripID, listTripBudget, msg);
            }
        }
Example #21
0
        public bool AddDoggo(SaveObjectModel rootItem, SatisfactorySave saveGame)
        {
            currentDoggoID = GetNextDoggoID(currentDoggoID, rootItem);

            var hostPlayerModel = rootItem.FindChild("Char_Player.Char_Player_C", false);

            if (hostPlayerModel == null || hostPlayerModel.Items.Count < 1)
            {
                MessageBox.Show("This save does not contain a host player or it is corrupt.", "Cannot find host player", MessageBoxButton.OK, MessageBoxImage.Error);
                return(false);
            }
            var player = (SaveEntityModel)hostPlayerModel.Items[0];

            SaveComponent healthComponent = new SaveComponent("/Script/FactoryGame.FGHealthComponent", "Persistent_Level", $"Persistent_Level:PersistentLevel.Char_SpaceRabbit_C_{currentDoggoID}.HealthComponent")
            {
                DataFields       = new SerializedFields(),
                ParentEntityName = $"Persistent_Level:PersistentLevel.Char_SpaceRabbit_C_{currentDoggoID}"
            };

            byte[]        bytes = PrepareForParse("", 0);
            SaveComponent inventoryComponent;

            using (BinaryReader reader = new BinaryReader(new MemoryStream(bytes)))
            {
                inventoryComponent = new SaveComponent("/Script/FactoryGame.FGInventoryComponent", "Persistent_Level", $"Persistent_Level:PersistentLevel.Char_SpaceRabbit_C_{currentDoggoID}.mInventory")
                {
                    DataFields = new SerializedFields()
                    {
                        new ArrayProperty("mInventoryStacks")
                        {
                            Type     = StructProperty.TypeName,
                            Elements = new System.Collections.Generic.List <SerializedProperty>()
                            {
                                SerializedProperty.Parse(reader, saveGame.Header.BuildVersion)
                            }
                        },
                        new ArrayProperty("mArbitrarySlotSizes")
                        {
                            Type     = IntProperty.TypeName,
                            Elements = new System.Collections.Generic.List <SerializedProperty>()
                            {
                                new IntProperty("Element")
                                {
                                    Value = 0
                                }
                            }
                        },
                        new ArrayProperty("mAllowedItemDescriptors")
                        {
                            Type     = ObjectProperty.TypeName,
                            Elements = new System.Collections.Generic.List <SerializedProperty>()
                            {
                                new ObjectProperty("Element")
                                {
                                    LevelName = "", PathName = ""
                                }
                            }
                        }
                    },
                    ParentEntityName = $"Persistent_Level:PersistentLevel.Char_SpaceRabbit_C_{currentDoggoID}"
                };
            }
            SaveEntity doggo = new SaveEntity("/Game/FactoryGame/Character/Creature/Wildlife/SpaceRabbit/Char_SpaceRabbit.Char_SpaceRabbit_C", "Persistent_Level", $"Persistent_Level:PersistentLevel.Char_SpaceRabbit_C_{currentDoggoID}")
            {
                NeedTransform = true,
                Rotation      = ((SaveEntity)player.Model).Rotation,
                Position      = new Vector3()
                {
                    X = ((SaveEntity)player.Model).Position.X,
                    Y = ((SaveEntity)player.Model).Position.Y + 100 + 10 * currentDoggoID, // so they don't glitch one into another like the tractors did
                    Z = ((SaveEntity)player.Model).Position.Z + 10
                },
                Scale = new Vector3()
                {
                    X = 1, Y = 1, Z = 1
                },
                WasPlacedInLevel = false,
                ParentObjectName = "",
                ParentObjectRoot = ""
            };

            doggo.Components = new System.Collections.Generic.List <SatisfactorySaveParser.Structures.ObjectReference>()
            {
                new SatisfactorySaveParser.Structures.ObjectReference()
                {
                    LevelName = "Persistent_Level", PathName = $"Persistent_Level:PersistentLevel.Char_SpaceRabbit_C_{currentDoggoID}.mInventory"
                },
                new SatisfactorySaveParser.Structures.ObjectReference()
                {
                    LevelName = "Persistent_Level", PathName = $"Persistent_Level:PersistentLevel.Char_SpaceRabbit_C_{currentDoggoID}.HealthComponent"
                }
            };
            byte[] emptyDynamicStructData = { 0x05, 0x00, 0x00, 0x00, 0x4e, 0x6f, 0x6e, 0x65 }; // Length prefixed "None"
            using (BinaryReader binaryReader = new BinaryReader(new MemoryStream(emptyDynamicStructData)))
            {
                doggo.DataFields = new SerializedFields()
                {
                    new ObjectProperty("mFriendActor")
                    {
                        LevelName = "Persistent_Level", PathName = player.Title
                    },
                    new IntProperty("mLootTableIndex")
                    {
                        Value = 0
                    },
                    new StructProperty("mLootTimerHandle")
                    {
                        Data = new DynamicStructData(binaryReader, "TimerHandle", saveGame.Header.BuildVersion),
                        Unk1 = 0,
                        Unk2 = 0,
                        Unk3 = 0,
                        Unk4 = 0,
                        Unk5 = 0
                    },
                    new BoolProperty("mIsPersistent")
                    {
                        Value = true
                    },
                    new ObjectProperty("mHealthComponent")
                    {
                        LevelName = "Persistent_Level", PathName = $"Persistent_Level:PersistentLevel.Char_SpaceRabbit_C_{currentDoggoID}.HealthComponent"
                    }
                };
            }
            FindOrCreatePath(rootItem, new string[] { "Character", "Creature", "Wildlife", "SpaceRabbit", "Char_SpaceRabbit.Char_SpaceRabbit_C" }).Items.Add(new SaveEntityModel(doggo));
            rootItem.FindChild("FactoryGame.FGInventoryComponent", false).Items.Add(new SaveComponentModel(inventoryComponent));
            rootItem.FindChild("FactoryGame.FGHealthComponent", false).Items.Add(new SaveComponentModel(healthComponent));
            return(true);
        }
 public static void MarkPersistent(SaveEntity e)
 {
     SceneEntities.Remove(e.entityID);
     PersistentEntities.Add(e.entityID, e);
 }
        public static SaveEntityModel CreateCrateEntityFromInventory(SaveObjectModel rootItem, ArrayProperty inventory)
        {
            inventory = ArrangeInventory(inventory);
            int           currentStorageID = GetNextStorageID(0, rootItem);
            SaveComponent newInventory     = new SaveComponent("/Script/FactoryGame.FGInventoryComponent", "Persistent_Level", $"Persistent_Level:PersistentLevel.BP_Crate_C_{currentStorageID}.inventory")
            {
                ParentEntityName = $"Persistent_Level:PersistentLevel.BP_Crate_C_{currentStorageID}",
                DataFields       = new SerializedFields()
                {
                    inventory,
                    new ArrayProperty("mArbitrarySlotSizes")
                    {
                        Type     = "IntProperty",
                        Elements = Enumerable.Repeat(new IntProperty("Element")
                        {
                            Value = 0
                        }, inventory.Elements.Count).Cast <SerializedProperty>().ToList()
                    },
                    new ArrayProperty("mAllowedItemDescriptors")
                    {
                        Type     = "ObjectProperty",
                        Elements = Enumerable.Repeat(new ObjectProperty("Element")
                        {
                            LevelName = "", PathName = ""
                        }, inventory.Elements.Count).Cast <SerializedProperty>().ToList()
                    },
                    new BoolProperty("mCanBeRearrange")
                    {
                        Value = false
                    }
                }
            };

            rootItem.FindChild("FactoryGame.FGInventoryComponent", false).Items.Add(new SaveComponentModel(newInventory));
            SaveEntity player        = (SaveEntity)rootItem.FindChild("Char_Player.Char_Player_C", false).DescendantSelf[0];
            SaveEntity newSaveObject = new SaveEntity("/Game/FactoryGame/-Shared/Crate/BP_Crate.BP_Crate_C", "Persistent_Level", $"Persistent_Level:PersistentLevel.BP_Crate_C_{currentStorageID}")
            {
                NeedTransform = true,
                Rotation      = player.Rotation,
                Position      = new Vector3()
                {
                    X = player.Position.X, Y = player.Position.Y + 100, Z = player.Position.Z
                },
                Scale = new Vector3()
                {
                    X = 1, Y = 1, Z = 1
                },
                WasPlacedInLevel = false,
                ParentObjectName = "",
                ParentObjectRoot = ""
            };

            newSaveObject.DataFields = new SerializedFields()
            {
                new ObjectProperty("mInventory", 0)
                {
                    LevelName = "Persistent_Level", PathName = $"Persistent_Level:PersistentLevel.BP_Crate_C_{currentStorageID}.inventory"
                }
            };
            if (rootItem.FindChild("Crate", false) == null)
            {
                rootItem.FindChild("-Shared", false).Items.Add(new SaveObjectModel("Crate"));
            }
            if (rootItem.FindChild("BP_Crate.BP_Crate_C", false) == null)
            {
                rootItem.FindChild("Crate", false).Items.Add(new SaveObjectModel("BP_Crate.BP_Crate_C"));
            }
            var crate = new SaveEntityModel(newSaveObject);

            rootItem.FindChild("BP_Crate.BP_Crate_C", false).Items.Add(crate);
            return(crate);
        }
Example #24
0
        static SaveObject PackSingleEntityAsBlueprint(SaveObject file, SaveEntity entity)
        {
            ProcessEntity(file, entity, null, null);

            return(file);
        }
Example #25
0
        static void ProcessEntity(SaveObject file, SaveEntity ent, HashSet <int> bp_ids, Transform root)
        {
            EntityObject eobj        = new EntityObject();
            SaveEntity   entity      = ent;
            bool         isBlueprint = bp_ids != null;

            file.isBlueprint = isBlueprint;
            CompRefSerializationProcessor.blueprint = isBlueprint;
            if (isBlueprint && entity.blueprintID == 0)
            {
                entity.blueprintID = SaveSystemUtilities.GetUniqueID(bp_ids);
            }

            eobj.blueprint_ID = entity.blueprintID;
            Transform tr = entity.transform;

            eobj.database_ID = entity.entityID;
            eobj.instance_ID = entity.instanceID;
            eobj.prefabPath  = SaveEntityDatabase.GetPrefabPath(entity.entityID);
            eobj.Enabled     = ent.gameObject.activeSelf;

            if (isBlueprint)
            {
                eobj.position = root.InverseTransformPoint(tr.position);
                eobj.rotation = tr.localRotation.eulerAngles;
            }
            else
            {
                eobj.position = tr.position;
                eobj.rotation = tr.rotation.eulerAngles;
            }
            bool           hasParent  = tr.parent != null;
            SavedComponent parentComp = null;

            if (hasParent)
            {
                parentComp = tr.parent.GetComponent <SavedComponent>();
            }
            if (tr.parent != root && parentComp)
            {
                eobj.parentIsComponent = true;
                if (isBlueprint)
                {
                    eobj.parent_entity_ID = parentComp.Entity.blueprintID;
                }
                else
                {
                    eobj.parent_entity_ID = parentComp.Entity.ID;
                }
                eobj.parent_component_ID = parentComp.componentID;
            }
            else
            {
                SaveEntity parentEntity = null;
                if (hasParent)
                {
                    parentEntity = tr.parent.GetComponent <SaveEntity>();
                }
                if (tr.parent != root && parentEntity)
                {
                    eobj.parentIsEntity = true;
                    if (isBlueprint)
                    {
                        eobj.parent_entity_ID = parentEntity.blueprintID;
                    }
                    else
                    {
                        eobj.parent_entity_ID = parentEntity.ID;
                    }
                }
                else
                {
                    if (isBlueprint)
                    {
                        eobj.parentName = "null";
                    }
                    else
                    {
                        eobj.parentName = tr.parent == null ? "null" : tr.parent.name;
                    }
                }
            }
            eobj.gameObjectName = entity.name;

            file.entities.Add(eobj);

            getComponentsSwapList.Clear();

            entity.GetComponentsInChildren <SavedComponent>(true, getComponentsSwapList);

            foreach (var comp in getComponentsSwapList)
            {
                if (comp.componentID == 0)
                {
                    //Debug.Log("Skipping component without ID : " + comp.GetType(), entity.gameObject);
                    continue;
                }

                comp.SendMessage("OnBeforeSave", SendMessageOptions.DontRequireReceiver);

                ComponentObject cobj = new ComponentObject();

                cobj.component_ID = comp.componentID;
                cobj.data         = GetDataFromComponent(comp);
                cobj.initialized  = comp.Initialized;
                cobj.enabled      = comp.enabled;

                Dictionary <int, ComponentObject> entityComponents = null;
                if (isBlueprint)
                {
                    file.components.TryGetValue(entity.blueprintID, out entityComponents);
                }
                else
                {
                    file.components.TryGetValue(entity.instanceID, out entityComponents);
                }

                if (entityComponents == null)
                {
                    entityComponents = new Dictionary <int, ComponentObject>();
                    if (isBlueprint)
                    {
                        file.components.Add(entity.blueprintID, entityComponents);
                    }
                    else
                    {
                        file.components.Add(entity.instanceID, entityComponents);
                    }
                }

                if (entityComponents.ContainsKey(comp.componentID))
                {
                    Debug.LogError("Super fatal error with duplicate component id's on entity.", entity.gameObject);
                }
                entityComponents.Add(comp.componentID, cobj);
                if (cobj.data != null)
                {
                    Type t      = cobj.data.GetType();
                    var  fields = t.GetFields();
                    foreach (var f in fields)
                    {
                        if (f.FieldType == typeof(CompRef))
                        {
                            file.comprefs.Add(f.GetValue(cobj.data) as CompRef);
                        }
                    }
                }
            }
        }
        public bool Apply(SaveObjectModel rootItem)
        {
            BuildPolygon();
            if (polygon.Length < 2)
            {
                MessageBox.Show("At least 2 points needed to mass dismantle", "Could not mass dismantle", MessageBoxButton.OK, MessageBoxImage.Error);
                return(false);
            }
            ArrayProperty inventory = new ArrayProperty("mInventoryStacks")
            {
                Type = "StructProperty"
            };
            int countFactory = 0, countBuilding = 0, countCrate = 0;

            try
            {
                countFactory = MassDismantle(rootItem.FindChild("Buildable", true).FindChild("Factory", true).DescendantSelfViewModel, inventory, rootItem);
            }
            catch (NullReferenceException) { }
            try
            {
                countBuilding = MassDismantle(rootItem.FindChild("Buildable", true).FindChild("Building", true).DescendantSelfViewModel, inventory, rootItem);
            }
            catch (NullReferenceException) { }
            try
            {
                countCrate = MassDismantle(rootItem.FindChild("-Shared", true).FindChild("BP_Crate.BP_Crate_C", true).DescendantSelfViewModel, inventory, rootItem);
            }
            catch (NullReferenceException) { }
            if (countFactory + countBuilding + countCrate == 0)
            {
                MessageBox.Show("Nothing was dismantled. Make sure the coordinates are correct and in clockwise order.", "Mass dismantle", MessageBoxButton.OK, MessageBoxImage.Error);
                return(false);
            }
            MessageBoxResult result = MessageBox.Show($"Dismantled {countFactory} factory buildings, {countBuilding} foundations and {countCrate} crates. Drop the items (including items in storages) in a single crate?", "Dismantled", MessageBoxButton.YesNo, MessageBoxImage.Question);

            if (result == MessageBoxResult.Yes)
            {
                inventory = ArrangeInventory(inventory);
                int           currentStorageID = GetNextStorageID(0, rootItem);
                SaveComponent newInventory     = new SaveComponent("/Script/FactoryGame.FGInventoryComponent", "Persistent_Level", $"Persistent_Level:PersistentLevel.BP_Crate_C_{currentStorageID}.inventory")
                {
                    ParentEntityName = $"Persistent_Level:PersistentLevel.BP_Crate_C_{currentStorageID}",
                    DataFields       = new SerializedFields()
                    {
                        inventory,
                        new ArrayProperty("mArbitrarySlotSizes")
                        {
                            Type     = "IntProperty",
                            Elements = Enumerable.Repeat(new IntProperty("Element")
                            {
                                Value = 0
                            }, inventory.Elements.Count).Cast <SerializedProperty>().ToList()
                        },
                        new ArrayProperty("mAllowedItemDescriptors")
                        {
                            Type     = "ObjectProperty",
                            Elements = Enumerable.Repeat(new ObjectProperty("Element")
                            {
                                LevelName = "", PathName = ""
                            }, inventory.Elements.Count).Cast <SerializedProperty>().ToList()
                        },
                        new BoolProperty("mCanBeRearrange")
                        {
                            Value = false
                        }
                    }
                };
                rootItem.FindChild("FactoryGame.FGInventoryComponent", false).Items.Add(new SaveComponentModel(newInventory));
                SaveEntity player        = (SaveEntity)rootItem.FindChild("Char_Player.Char_Player_C", false).DescendantSelf[0];
                SaveEntity newSaveObject = new SaveEntity("/Game/FactoryGame/-Shared/Crate/BP_Crate.BP_Crate_C", "Persistent_Level", $"Persistent_Level:PersistentLevel.BP_Crate_C_{currentStorageID}")
                {
                    NeedTransform = true,
                    Rotation      = player.Rotation,
                    Position      = new Vector3()
                    {
                        X = player.Position.X, Y = player.Position.Y + 100, Z = player.Position.Z
                    },
                    Scale = new Vector3()
                    {
                        X = 1, Y = 1, Z = 1
                    },
                    WasPlacedInLevel = false,
                    ParentObjectName = "",
                    ParentObjectRoot = ""
                };
                newSaveObject.DataFields = new SerializedFields()
                {
                    new ObjectProperty("mInventory", 0)
                    {
                        LevelName = "Persistent_Level", PathName = $"Persistent_Level:PersistentLevel.BP_Crate_C_{currentStorageID}.inventory"
                    }
                };
                if (rootItem.FindChild("Crate", false) == null)
                {
                    rootItem.FindChild("-Shared", false).Items.Add(new SaveObjectModel("Crate"));
                }
                if (rootItem.FindChild("BP_Crate.BP_Crate_C", false) == null)
                {
                    rootItem.FindChild("Crate", false).Items.Add(new SaveObjectModel("BP_Crate.BP_Crate_C"));
                }
                rootItem.FindChild("BP_Crate.BP_Crate_C", false).Items.Add(new SaveEntityModel(newSaveObject));
            }
            return(true);
        }
Example #27
0
        /// <summary>
        /// Creates a file with single entity
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public static SaveObject CreateSaveObjectFromEntity(SaveEntity entity)
        {
            SaveObject file = new SaveObject();

            return(PackSingleEntityAsBlueprint(file, entity));
        }