示例#1
0
        /// <summary>Raised after a mod message is received over the network.</summary>
        private void OnModMessageReceived(object sender, ModMessageReceivedEventArgs e)
        {
            if (e.FromModID == ModManifest.UniqueID)
            {
                if (e.Type == saveDataRefreshedMessage)
                {
                    // Receive the save data
                    modSaveData = e.ReadAs <ModSaveData>();
                    // Refresh the furnace data
                    InitializeFurnaceControllers(false);

                    // If we have a menu open and we're looking at a furnace, the menu is most likely the output menu. Redraw it!
                    if (Game1.activeClickableMenu != null && currentlyLookingAtFurnace != -1)
                    {
                        DrawOutputMenu(furnaces[GetIndexOfFurnaceControllerWithTag(currentlyLookingAtFurnace)]);
                    }

                    UpdateTextures();
                    UpdateFurnaceLights();
                }
                else if (e.Type == requestSaveData)
                {
                    RequestSaveData request = e.ReadAs <RequestSaveData>();
                    Helper.Multiplayer.SendMessage <ModSaveData>(modSaveData, saveDataRefreshedMessage, new string[] { ModManifest.UniqueID }, new long[] { request.PlayerID });
                }
            }
        }
示例#2
0
 /// <summary>Raised after the game returns to the title screen.</summary>
 private void OnReturnedToTitle(object sender, ReturnedToTitleEventArgs e)
 {
     // Reset stuff
     modSaveData = null;
     furnaces.Clear();
     furnaces.Clear();
 }
示例#3
0
        /// <summary>Update the furnace data from the save data</summary>
        private void InitializeFurnaceControllers(bool readSaveData)
        {
            // Initialize the lists to prevent data leaking from previous games
            furnaces.Clear();
            furnaces.Clear();

            // Load the saved data. If not present, initialize new
            if (readSaveData)
            {
                modSaveData = Helper.Data.ReadSaveData <ModSaveData>(controllerDataSaveKey);
            }

            if (modSaveData is null)
            {
                modSaveData = new ModSaveData();
            }
            else
            {
                modSaveData.ParseModSaveDataToControllers(furnaces, this);
            }

            // Update furnacesBuilt counter to match the highest id of built furnaces (+1)
            int highestId = -1;

            for (int i = 0; i < furnaces.Count; i++)
            {
                if (furnaces[i].ID > highestId)
                {
                    highestId = furnaces[i].ID;
                }
            }
            furnacesBuilt = highestId + 1;

            // Repopulate the list of furnaces, only checks the farm!
            foreach (Building building in ((BuildableGameLocation)Game1.getFarm()).buildings)
            {
                if (IsBuildingIndustrialFurnace(building))
                {
                    for (int i = 0; i < furnaces.Count; i++)
                    {
                        if (building.maxOccupants.Value == furnaces[i].ID)
                        {
                            furnaces[i].furnace = building;
                        }
                    }
                }
            }
        }