Skip to content

Commit

Permalink
Found a simpler solution for getting the time of day.
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeStrout committed Apr 10, 2022
1 parent 64b9d2a commit 6489ff0
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 46 deletions.
2 changes: 1 addition & 1 deletion M1/M1API.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1635,7 +1635,7 @@ static ValMap WorldModule() {
// Can exceed 2400 when the farmer refuses to sleep.
Intrinsic f = Intrinsic.Create("");
f.code = (context, partialResult) => {
return new Intrinsic.Result(new ValNumber(ModEntry.instance.CurrentGameTime));
return new Intrinsic.Result(new ValNumber(Game1.timeOfDay));
};
worldModule["timeOfDay"] = f.GetFunc();

Expand Down
46 changes: 1 addition & 45 deletions M1/ModEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ public override void Entry(IModHelper helper) {
helper.Events.GameLoop.Saved += this.OnSaved;
helper.Events.GameLoop.SaveLoaded += this.OnSaveLoaded;
helper.Events.GameLoop.DayStarted += this.OnDayStarted;
helper.Events.GameLoop.TimeChanged += this.OnTimeChanged;

print($"CurrentSavePath: {Constants.CurrentSavePath}");
}
Expand Down Expand Up @@ -153,19 +152,6 @@ public void OnDayStarted(object sender, DayStartedEventArgs args) {
Bot.InitShellAll();
}

// The day always starts at 0600.
private int currentGameTime = 600;

/// <summary>
/// Gets the current in-game time.
/// The time is formatted as HHmm, so 15:20 just becomes 1520 for example.
/// </summary>
public int CurrentGameTime => currentGameTime;
private void OnTimeChanged(object sender, TimeChangedEventArgs e) {
// Update the registered game time.
currentGameTime = e.NewTime;
}

/// <summary>
/// Initializes the home computer shell.
/// Effectively boots up the home computer if it is not already running.
Expand All @@ -178,39 +164,9 @@ private void InitComputerShell() {
}

private void PresentComputer() {
// Initialize the home computer if it is not already running.
// Initialize the home computer if it is not already running, then present it.
InitComputerShell();
shell.console.Present();

/*
var farm = (Farm)Game1.getLocationFromName("Farm");
var layer = farm.map.Layers[0];
shell.PrintLine($"Farm size: {layer.LayerWidth} x {layer.LayerHeight}");
shell.PrintLine($"Farm animals: {farm.getAllFarmAnimals().Count}");
shell.PrintLine($"Buildings: {farm.buildings.Count}");
int featureCount = 0;
int trees=0, bushes=0, grasses=0, hoeDirts=0, paths=0;
var hoeLocs = new List<string>();
foreach (KeyValuePair<Vector2, TerrainFeature> kvp in farm.terrainFeatures.Pairs) {
if (kvp.Value is Tree) trees++;
else if (kvp.Value is Bush) bushes++;
else if (kvp.Value is Grass) grasses++;
else if (kvp.Value is HoeDirt) {
hoeDirts++;
hoeLocs.Add(kvp.Key.ToString()); // locations are integers, X right and Y down from top-left
}
else if (kvp.Value is Flooring) paths++;
featureCount++;
}
shell.PrintLine($"Trees: {trees}");
shell.PrintLine($"Bushes: {bushes}");
shell.PrintLine($"Grass: {grasses}");
shell.PrintLine($"Tilled Ground: {hoeDirts}");// at: {string.Join(',', hoeLocs)}");
shell.PrintLine($"Paved: {paths}");
shell.PrintLine($"Total features: {featureCount}");
*/
}

bool IAssetEditor.CanEdit<T>(IAssetInfo asset) {
Expand Down

0 comments on commit 6489ff0

Please sign in to comment.