Skip to content

Commit

Permalink
v1.1
Browse files Browse the repository at this point in the history
v1.1
  • Loading branch information
TheMasterCado authored Feb 8, 2019
2 parents 4bcc157 + ef05f7a commit 22489d7
Show file tree
Hide file tree
Showing 14 changed files with 86 additions and 37 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,6 @@ _UpgradeReport_Files/
Thumbs.db
Desktop.ini
.DS_Store

# Debug version
MoreRealism_debug\
2 changes: 1 addition & 1 deletion BaseWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class BaseWindow
protected bool usesSkin = true;

protected string windowName = "Base window - More Realism";
protected Rect WindowRect = new Rect(20, 20, 200, 200);
protected Rect WindowRect = new Rect(100, 100, 200, 200);

public BaseWindow(MoreRealismController controller)
{
Expand Down
7 changes: 5 additions & 2 deletions Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public class Main : IMod
public Main()
{
SetupKeyBinding();

}

public void onEnabled()
Expand All @@ -26,7 +27,8 @@ public void onEnabled()

public void onDisabled()
{
MoreRealismController.Instance.Kill();
if (MoreRealismController.Instance != null)
MoreRealismController.Instance.Kill();
AssetManager.Instance.unregisterObject(_controllerPrefab);
_controllerPrefab.Kill();
}
Expand Down Expand Up @@ -54,9 +56,10 @@ private void RegisterKey(string identifier, KeyCode keyCode, string name, string

public string Name => "More Realism";

public string Description => "Add more realism to Parkitect (day/night cycle, etc.).";
public string Description => "Add new mechanics to make the game more realistic";

public string Identifier => "TheMasterCado@MoreRealism";

public string Version => MoreRealismController.Version;
}
}
12 changes: 9 additions & 3 deletions MoreRealism.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>TheMasterCado%40MoreRealism\</OutputPath>
<OutputPath>MoreRealism_debug\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<DebugType>none</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<OutputPath>TheMasterCado%40MoreRealism\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
Expand Down Expand Up @@ -72,9 +72,15 @@
</ItemGroup>
<ItemGroup>
<None Include="LICENSE" />
<None Include="steam_workshop-id">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup>
<Content Include=".gitignore" />
<Content Include="preview.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<Folder Include="Properties\" />
Expand Down
35 changes: 26 additions & 9 deletions MoreRealismController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ namespace MoreRealism
{
public class MoreRealismController : SerializedMonoBehaviour
{
public static string Version = "1.1";
public static MoreRealismController Instance;
public static string VERSION = "1.0";

public List<BaseWindow> windows = new List<BaseWindow>();
public MoreRealismSettings settings = null;
Expand All @@ -31,7 +31,7 @@ public void SetAsPrefab()

public void Load()
{
if (_prefabFlag)
if (_prefabFlag || GameController.Instance.isInScenarioEditor)
return;

if (isLoaded)
Expand Down Expand Up @@ -87,7 +87,7 @@ private void CheckDayNightCycle()
if (ParkInfo.ParkTime >= settings.nextDayNightSwitchTime)
{
GameController.Instance.park.weatherController.IsNight = !GameController.Instance.park.weatherController.IsNight;
settings.nextDayNightSwitchTime = ParkInfo.ParkTime + settings.cycleLenghtMonths * 300;
settings.nextDayNightSwitchTime = (int)(ParkInfo.ParkTime + settings.cycleLenghtMonths * 300);
}

if (settings.kickOutGuestsAtNight && ParkInfo.ParkTime >= settings.nextParkStateSwitchTime)
Expand All @@ -100,14 +100,19 @@ private void CheckDayNightCycle()
else
{
GameController.Instance.park.setState(Park.State.OPENED);
settings.nextParkStateSwitchTime = settings.nextDayNightSwitchTime + settings.cycleLenghtMonths * 150;
settings.nextParkStateSwitchTime = (int)(settings.nextDayNightSwitchTime + settings.cycleLenghtMonths * 150);
}

}

if (settings.closeEverythingAtNight && ParkInfo.ParkTime >= settings.nextEverythingStateSwitchTime)
{
if (settings.nextParkStateSwitchTime - settings.nextEverythingStateSwitchTime > 70)
int compareDiff;
if (settings.cycleLenghtMonths < 1)
compareDiff = (int)(settings.cycleLenghtMonths * 60 + 2);
else
compareDiff = 65;
if (settings.nextParkStateSwitchTime - settings.nextEverythingStateSwitchTime > compareDiff)
{
foreach (Attraction attr in GameController.Instance.park.getAttractions())
{
Expand All @@ -118,7 +123,10 @@ private void CheckDayNightCycle()
{
sh.close();
}
settings.nextEverythingStateSwitchTime = settings.nextParkStateSwitchTime - 60;
if (settings.cycleLenghtMonths < 1)
settings.nextEverythingStateSwitchTime = (int)(settings.nextParkStateSwitchTime - (settings.cycleLenghtMonths * 60));
else
settings.nextEverythingStateSwitchTime = settings.nextParkStateSwitchTime - 60;
}
else
{
Expand All @@ -131,7 +139,10 @@ private void CheckDayNightCycle()
{
sh.open();
}
settings.nextEverythingStateSwitchTime = settings.nextParkStateSwitchTime + 60 + settings.cycleLenghtMonths * 450;
if (settings.cycleLenghtMonths < 1)
settings.nextEverythingStateSwitchTime = (int)(settings.nextParkStateSwitchTime + (settings.cycleLenghtMonths * 60) + settings.cycleLenghtMonths * 450);
else
settings.nextEverythingStateSwitchTime = (int)(settings.nextParkStateSwitchTime + 60 + settings.cycleLenghtMonths * 450);
}
}

Expand All @@ -145,11 +156,11 @@ public void SaveSettings()

GameController.Instance.park.weatherController.IsNight = false;

settings.nextDayNightSwitchTime = ParkInfo.ParkTime + settings.cycleLenghtMonths * 300;
settings.nextDayNightSwitchTime = (int)(ParkInfo.ParkTime + settings.cycleLenghtMonths * 300);

if (settings.kickOutGuestsAtNight)
{
settings.nextParkStateSwitchTime = settings.nextDayNightSwitchTime + settings.cycleLenghtMonths * 150;
settings.nextParkStateSwitchTime = (int)(settings.nextDayNightSwitchTime + settings.cycleLenghtMonths * 150);

if (settings.closeEverythingAtNight)
{
Expand Down Expand Up @@ -199,6 +210,12 @@ public override void serialize(SerializationContext context, Dictionary<string,
base.serialize(context, values);
}

public void closeAllWindows()
{
foreach (BaseWindow w in windows)
w.CloseWindow();
}

public override string getReferenceName()
{
return "MoreRealismController";
Expand Down
27 changes: 19 additions & 8 deletions MoreRealismSettings.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using UnityEngine;

namespace MoreRealism
{
public class MoreRealismSettings : SerializedRawObject
{
public int cycleLenghtMonths = 4;
public static int VERSION = 1;

public decimal cycleLenghtMonths = 4m;
public bool dayNightCycleEnabled = true;
public bool kickOutGuestsAtNight = true;
public bool closeEverythingAtNight = true;
Expand All @@ -19,35 +22,40 @@ public MoreRealismSettings()
{
try
{
nextDayNightSwitchTime = ParkInfo.ParkTime + cycleLenghtMonths * 300;
nextParkStateSwitchTime = nextDayNightSwitchTime + cycleLenghtMonths * 150;
nextEverythingStateSwitchTime = nextParkStateSwitchTime + 60;
nextDayNightSwitchTime = (int)(ParkInfo.ParkTime + cycleLenghtMonths * 300);
nextParkStateSwitchTime = (int)(nextDayNightSwitchTime + cycleLenghtMonths * 150);
if (cycleLenghtMonths < 1)
nextEverythingStateSwitchTime = (int)(nextParkStateSwitchTime + (cycleLenghtMonths * 60));
else
nextEverythingStateSwitchTime = nextParkStateSwitchTime + 60;
}
catch
{
Debug.Log("[MoreRealism] Couln'd set default values for switch times");
Debug.Log("[MoreRealism] Couldn't set default values for switch times");
}
}

public override void serialize(SerializationContext context, Dictionary<string, object> values)
{
values.Add("cycleLenghtMonths", cycleLenghtMonths);
values.Add("cycleLenghtMonths", cycleLenghtMonths.ToString().Replace(",", "."));
values.Add("dayNightCycleEnabled", dayNightCycleEnabled);
values.Add("kickOutGuestsAtNight", kickOutGuestsAtNight);
values.Add("nextDayNightSwitchTime", nextDayNightSwitchTime);
values.Add("nextParkStateSwitchTime", nextParkStateSwitchTime);
values.Add("nextEverythingStateSwitchTime", nextEverythingStateSwitchTime);
values.Add("settingsVersion", VERSION);

base.serialize(context, values);
}

public override void deserialize(SerializationContext context, Dictionary<string, object> values)
{
object tmp;
int loadedVersion;
try
{
if (values.TryGetValue("cycleLenghtMonths", out tmp))
cycleLenghtMonths = Convert.ToInt32(tmp);
cycleLenghtMonths = decimal.Parse(Convert.ToString(tmp), CultureInfo.GetCultureInfo("en-US"));
if (values.TryGetValue("dayNightCycleEnabled", out tmp))
dayNightCycleEnabled = Convert.ToBoolean(tmp);
if (values.TryGetValue("kickOutGuestsAtNight", out tmp))
Expand All @@ -58,10 +66,13 @@ public override void deserialize(SerializationContext context, Dictionary<string
nextParkStateSwitchTime = Convert.ToInt32(tmp);
if (values.TryGetValue("nextEverythingStateSwitchTime", out tmp))
nextEverythingStateSwitchTime = Convert.ToInt32(tmp);

if (values.TryGetValue("settingsVersion", out tmp))
loadedVersion = Convert.ToInt32(tmp);
}
catch
{
Debug.Log("[MoreRealism] Couln'd load saved controller");
Debug.Log("[MoreRealism] Controller didn't load correctly");
}
base.deserialize(context, values);
}
Expand Down
Binary file modified TheMasterCado@MoreRealism/MoreRealism.dll
Binary file not shown.
Binary file removed TheMasterCado@MoreRealism/MoreRealism.pdb
Binary file not shown.
Binary file added TheMasterCado@MoreRealism/preview.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions TheMasterCado@MoreRealism/steam_workshop-id
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1638239864
4 changes: 2 additions & 2 deletions Windows/DebuggingWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ public class DebuggingWindow : BaseWindow
public DebuggingWindow(MoreRealismController mrController) : base(mrController)
{
windowName = "More Realism - Debug";
WindowRect = new Rect(20, 20, 250, 250);
WindowRect = new Rect(400, 100, 250, 250);
}

public override void DrawContent()
{
GUILayout.BeginHorizontal();
GUILayout.FlexibleSpace();
GUILayout.Label(string.Format("MoreRealism {0}", MoreRealismController.VERSION));
GUILayout.Label(string.Format("MoreRealism {0}", MoreRealismController.Version));
GUILayout.FlexibleSpace();
GUILayout.EndHorizontal();

Expand Down
31 changes: 19 additions & 12 deletions Windows/MainWindow.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Globalization;
using UnityEngine;

namespace MoreRealism.Windows
Expand All @@ -12,7 +13,7 @@ public class MainWindow : BaseWindow
public MainWindow(MoreRealismController mrController) : base(mrController)
{
windowName = "More Realism";
WindowRect = new Rect(20, 20, 300, 250);
WindowRect = new Rect(100, 100, 300, 250);
}

public override void OnOpen()
Expand All @@ -21,7 +22,7 @@ public override void OnOpen()
_dayNightCycleEnabled = Controller.settings.dayNightCycleEnabled;
_kickOutGuestsAtNight = Controller.settings.kickOutGuestsAtNight;
_closeEverythingAtNight = Controller.settings.closeEverythingAtNight;
_cycleLenghtMonths = Controller.settings.cycleLenghtMonths.ToString();
_cycleLenghtMonths = Controller.settings.cycleLenghtMonths.ToString().Replace(",", ".");
}

public override void DrawContent()
Expand Down Expand Up @@ -63,19 +64,25 @@ public override void DrawContent()
GUILayout.FlexibleSpace();
if (GUILayout.Button("Save"))
{
int cycleLenghtMonths_int;
if(int.TryParse(_cycleLenghtMonths, out cycleLenghtMonths_int)) {
decimal cycleLenghtMonths_num;
_cycleLenghtMonths = _cycleLenghtMonths.Replace(",", ".");
if(decimal.TryParse(_cycleLenghtMonths, NumberStyles.AllowDecimalPoint, CultureInfo.GetCultureInfo("en-US"), out cycleLenghtMonths_num)) {
if (cycleLenghtMonths_num > 0)
{
Controller.settings.cycleLenghtMonths = Math.Round(cycleLenghtMonths_num, 1);
Controller.settings.dayNightCycleEnabled = _dayNightCycleEnabled;
Controller.settings.kickOutGuestsAtNight = _kickOutGuestsAtNight;
Controller.settings.closeEverythingAtNight = _closeEverythingAtNight;

Controller.settings.cycleLenghtMonths = cycleLenghtMonths_int;
Controller.settings.dayNightCycleEnabled = _dayNightCycleEnabled;
Controller.settings.kickOutGuestsAtNight = _kickOutGuestsAtNight;
Controller.settings.closeEverythingAtNight = _closeEverythingAtNight;

Controller.SaveSettings();
Controller.GetWindow<MessageBoxWindow>().Show("Settings saved, the cycle have been reset");
Controller.SaveSettings();
Controller.closeAllWindows();
Controller.GetWindow<MessageBoxWindow>().Show("Settings saved, the cycle have been reset");
}
else
Controller.GetWindow<MessageBoxWindow>().Show("Please enter number higher than 0");
}
else
Controller.GetWindow<MessageBoxWindow>().Show("Please enter a valid integer");
Controller.GetWindow<MessageBoxWindow>().Show("Please enter a valid number");

}
GUILayout.EndHorizontal();
Expand Down
Binary file added preview.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions steam_workshop-id
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1638239864

0 comments on commit 22489d7

Please sign in to comment.