Skip to content

Commit

Permalink
Substantial enhancements to the editor; added world.luck.
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeStrout committed Jun 18, 2022
1 parent 5c8901f commit 589714f
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 45 deletions.
75 changes: 33 additions & 42 deletions M1/M1API.cs
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ public static void Init(Shell shell) {
// Currently mostly the things related to time.
f = Intrinsic.Create("world");
f.code = (context, partialResult) => {
return new Intrinsic.Result(WorldModule());
return new Intrinsic.Result(WorldInfo());
};
}

Expand Down Expand Up @@ -1619,69 +1619,60 @@ public static ValMap TextModule() {



static ValMap worldModule;
static ValMap worldInfo;

/// <summary>
/// Creates a module for accessing data about the SDV world.
/// </summary>
/// <returns>A value map with functions to get information about the world.</returns>
static ValMap WorldModule() {
if(worldModule != null) { return worldModule; }
worldModule = new ValMap();
worldModule.assignOverride = DisallowAllAssignment;
static ValMap WorldInfo() {
if (worldInfo == null) {
worldInfo = new ValMap();
worldInfo.assignOverride = DisallowAllAssignment;
}

// The in-game time on this day.
// Can exceed 2400 when the farmer refuses to sleep.
Intrinsic f = Intrinsic.Create("");
f.code = (context, partialResult) => {
return new Intrinsic.Result(new ValNumber(Game1.timeOfDay));
};
worldModule["timeOfDay"] = f.GetFunc();
worldInfo["timeOfDay"] = new ValNumber(Game1.timeOfDay);

// Days since start is the amount of in-game days since this farm was started.
// Day 1 of year 1 is 1 in this function.
f = Intrinsic.Create("");
f.code = (context, partialResult) => {
return new Intrinsic.Result(new ValNumber(SDate.Now().DaysSinceStart));
};
worldModule["daySinceGameStart"] = f.GetFunc();
worldInfo["daySinceGameStart"] = new ValNumber(SDate.Now().DaysSinceStart);

// The current day in the in-game season.
f = Intrinsic.Create("");
f.code = (context, partialResult) => {
return new Intrinsic.Result(new ValNumber(SDate.Now().Day));
};
worldModule["dayOfSeason"] = f.GetFunc();
worldInfo["dayOfSeason"] = new ValNumber(SDate.Now().Day);

// The number of the in-game day of week (0 = Sunday).
worldInfo["dayOfWeek"] = new ValNumber((int)SDate.Now().DayOfWeek);

// The name of the in-game day.
f = Intrinsic.Create("");
f.code = (context, partialResult) => {
return new Intrinsic.Result(new ValString(SDate.Now().DayOfWeek.ToString()));
};
worldModule["dayOfWeekName"] = f.GetFunc();
worldInfo["dayOfWeekName"] = new ValString(SDate.Now().DayOfWeek.ToString());

// The in-game year, starts at 1.
f = Intrinsic.Create("");
f.code = (context, partialResult) => {
return new Intrinsic.Result(new ValNumber(SDate.Now().Year));
};
worldModule["year"] = f.GetFunc();
worldInfo["year"] = new ValNumber(SDate.Now().Year);

// The numeric representation for the current in-game season.
f = Intrinsic.Create("");
f.code = (context, partialResult) => {
return new Intrinsic.Result(new ValNumber(SDate.Now().SeasonIndex));
};
worldModule["season"] = f.GetFunc();
// The numeric representation for the current in-game season (0 = spring).
worldInfo["season"] = new ValNumber(SDate.Now().SeasonIndex);

// The human-readable representation for the current in-game season.
f = Intrinsic.Create("");
f.code = (context, partialResult) => {
return new Intrinsic.Result(new ValString(SDate.Now().Season));
worldInfo["seasonName"] = new ValString(SDate.Now().Season);

// The current weather
{
var loc = (Farm)Game1.getLocationFromName("Farm");
var weather = Game1.netWorldState.Value.GetWeatherForLocation(loc.GetLocationContext());
string result = "Sunny";
if (weather.isLightning) result = "stormy";
else if (weather.isRaining) result = "raining";
else if (weather.isSnowing) result = "snowing";
else if (weather.isDebrisWeather) result = "windy";
worldInfo["weather"] = new ValString(result);
};
worldModule["seasonName"] = f.GetFunc();

return worldModule;
// Daily luck
worldInfo["luck"] = new ValNumber(Game1.player.DailyLuck);

return worldInfo;
}

/// <summary>
Expand Down
3 changes: 2 additions & 1 deletion M1/assets/sysdisk/help/topics.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
Available topics:
files coding demos
text input community
farm bot toDo
farm bot world
toDo

(Access these with, for example:
`help "demos"` -- remember to use
Expand Down
5 changes: 5 additions & 0 deletions M1/assets/sysdisk/help/world.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
The `world` global provides a information
about the world. This includes current
date, time, and weather. Try:

`pprint world`
76 changes: 74 additions & 2 deletions M1/assets/sysdisk/lib/editor.ms
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ pal.cursor = "#CCCCFF"
pal.topBar = "#AAAAAA"
pal.topBarText = "#8888CC"

cutLines = []
linesCutFromLineNum = null

lineLen = function(lineNum)
if lineNum < data.len then return data[lineNum].len
return 0
Expand All @@ -33,7 +36,7 @@ drawTopBar = function()
print " " + _sourceFile
lstr = str(cursorY + 1)
print " " * (screenW - 13 - lstr.len - text.column)
print "^Q: Quit L" + lstr
print "^H: Help L" + lstr
print " " * (screenW - text.column)
end function

Expand Down Expand Up @@ -172,6 +175,66 @@ nextWord = function(dir)
outer.cursorX = x
end function

cutLine = function
if cursorY != linesCutFromLineNum then
outer.cutLines = []
outer.linesCutFromLineNum = cursorY
end if
if cursorY >= data.len then return "End of File"
cutLines.push data[cursorY]
data.remove cursorY
refreshDisplay
if cutLines.len == 1 then return "Cut (1 Line)"
return "Cut (" + cutLines.len + " Lines)"
end function

pasteLines = function
for line in cutLines
data.insert cursorY, line
outer.cursorY = cursorY + 1
end for
scrollCursorIntoView
refreshDisplay
if cutLines.len == 1 then return "Paste (1 Line)"
return "Paste (" + cutLines.len + " Lines)"
end function

showHelp = function
text.color = pal.text; text.backColor = "#4F1CDBFF"
text.clear; text.delimiter = char(13)
text.row = 19; text.column = 0
text.inverse = true
print " "*8 + "Farmtronics Text Editor" + " "*9
text.inverse = false
print "Hold the Control key and press a letter"
print "to perform one of the functions below."
print "Example: "
print " ^Q means hold Contol and press Q."
print
funcs = [
"^A: Go to start of line",
"^E: Go to end of line",
"^U: Page up",
"^D: Page down",
"^K: Cut line(s)",
"^V: Paste line(s)",
"^H: View this help",
"^Q: Quit"]
text.delimiter = ""
for func in funcs
parts = func.split(":")
text.column = 3; text.inverse = true
print parts[0] + " "
text.inverse = false
print parts[1] + char(13)
end for
text.row = 0
print "(Press any key to continue.)"
key.get
text.backColor = color.clear
refreshDisplay
end function

showCommand = function(keyPress, desc)
refreshRow 0
s = keyPress
Expand All @@ -197,18 +260,27 @@ handleControlKey = function(k)
if kcode > 31 then keyPress = "^" + char(kcode)
if anyShift then keyPress = "Shift-" + keyPress

// Want to customize your key bindings? Change
// the code below, and the help in showHelp above.
if keyPress == "^A" then // ctrl-A (start of line)
desc = "LineStart"
outer.cursorX = 0
else if keyPress == "^E" then // ctrl-E (end of line)
desc = "LineEnd"
outer.cursorX = lineLen(cursorY)
else if keyPress == "^H" then // help
showHelp
desc = "Help"
else if keyPress == "^U" then // Page Up
desc = "PageUp"
outer.cursorY = outer.cursorY - screenLines
else if keyPress == "^D" then // Page Down
desc = "PageDown"
outer.cursorY = outer.cursorY + screenLines
outer.cursorY = outer.cursorY + screenLines
else if keyPress == "^K" then // Cut line
desc = cutLine
else if keyPress == "^V" then // Paste lines
desc = pasteLines
else if keyPress == "^Q" then // Escape or Ctrl+X
desc = "Quit"
outer.quitting = true
Expand Down

0 comments on commit 589714f

Please sign in to comment.