protected override void StaticInitialize()
            {
                // Load all entities upon world load (single, server)
                if (Main.netMode != 1)
                {
                    Promises.AddValidatedPromise <PromiseArguments>(ModHelpersWorld.LoadValidator, (_) => {
                        MyStaticInitializer.LoadAll();
                        SaveableEntityComponent.PostLoadAll();
                        return(true);
                    });
                }

                // Save all entities upon world save (single, server)
                if (Main.netMode != 1)
                {
                    Promises.AddValidatedPromise <PromiseArguments>(ModHelpersWorld.SaveValidator, (_) => {
                        MyStaticInitializer.SaveAll();
                        return(true);
                    });
                }

                // Unload entities after world closes
                Promises.AddPostWorldUnloadEachPromise(() => {
                    SaveableEntityComponent.PostUnloadAll();
                });
            }
Пример #2
0
        ////////////////

        internal LoadHelpers()
        {
            Promises.AddWorldLoadEachPromise(() => {
                this.StartupDelay = 0;
            });
            Promises.AddWorldUnloadEachPromise(() => {
                this.StartupDelay            = 0;
                this.IsClientPlaying_Hackish = false;
            });
            Promises.AddPostWorldUnloadEachPromise(() => {              // Redundant?
                this.StartupDelay            = 0;
                this.IsClientPlaying_Hackish = false;
            });
        }
        internal CustomEntityManager()
        {
            this.InitializeUpdate();
            this.InitializeEntityTypes();
            this.InitializeComponentTypes();
            this.InitializeDrawingLayer();

            // Reset any data from previous games
            Promises.AddPostWorldUnloadEachPromise(() => {
                lock (CustomEntityManager.MyLock) {
                    this.WorldEntitiesByIndexes.Clear();
                    this.WorldEntitiesByComponentType.Clear();
                }
            });

            // Bind 'data dump' hotkey
            DataDumper.SetDumpSource("CustomEntityList", () => {
                lock (CustomEntityManager.MyLock) {
                    return(string.Join("\n  ", this.WorldEntitiesByIndexes.OrderBy(kv => kv.Key)
                                       .SafeSelect(kv => kv.Key + ": " + kv.Value?.ToString() ?? "null")));
                }
            });

            // Refresh entity owners on player connect and sync entities to player
            if (Main.netMode == 2)
            {
                Promises.AddValidatedPromise <PlayerLogicPromiseArguments>(PlayerLogic.ServerConnectValidator, (args) => {
                    if (this.WorldEntitiesByIndexes.Count == 0)
                    {
                        return(true);
                    }

                    foreach (var ent in this.WorldEntitiesByIndexes.Values)
                    {
                        ent.RefreshOwnerWho();
                    }

                    PacketProtocolSendToClient.QuickSend <CustomEntityAllProtocol>(args.Who, -1);

                    return(true);
                });
            }
        }
 public static void AddPostWorldUnloadEachPromise(Action action)
 {
     Promises.AddPostWorldUnloadEachPromise(action);
 }
        ////////////////

        internal void OnPostSetupContent()
        {
            Promises.AddPostWorldUnloadEachPromise(() => {
                this.PlayerIds = new Dictionary <int, string>();
            });
        }