Skip to content

Commit 589714f

Browse files
committed
Substantial enhancements to the editor; added world.luck.
1 parent 5c8901f commit 589714f

File tree

4 files changed

+114
-45
lines changed

4 files changed

+114
-45
lines changed

M1/M1API.cs

+33-42
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ public static void Init(Shell shell) {
286286
// Currently mostly the things related to time.
287287
f = Intrinsic.Create("world");
288288
f.code = (context, partialResult) => {
289-
return new Intrinsic.Result(WorldModule());
289+
return new Intrinsic.Result(WorldInfo());
290290
};
291291
}
292292

@@ -1619,69 +1619,60 @@ public static ValMap TextModule() {
16191619

16201620

16211621

1622-
static ValMap worldModule;
1622+
static ValMap worldInfo;
16231623

16241624
/// <summary>
16251625
/// Creates a module for accessing data about the SDV world.
16261626
/// </summary>
16271627
/// <returns>A value map with functions to get information about the world.</returns>
1628-
static ValMap WorldModule() {
1629-
if(worldModule != null) { return worldModule; }
1630-
worldModule = new ValMap();
1631-
worldModule.assignOverride = DisallowAllAssignment;
1628+
static ValMap WorldInfo() {
1629+
if (worldInfo == null) {
1630+
worldInfo = new ValMap();
1631+
worldInfo.assignOverride = DisallowAllAssignment;
1632+
}
16321633

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

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

16491642
// The current day in the in-game season.
1650-
f = Intrinsic.Create("");
1651-
f.code = (context, partialResult) => {
1652-
return new Intrinsic.Result(new ValNumber(SDate.Now().Day));
1653-
};
1654-
worldModule["dayOfSeason"] = f.GetFunc();
1643+
worldInfo["dayOfSeason"] = new ValNumber(SDate.Now().Day);
1644+
1645+
// The number of the in-game day of week (0 = Sunday).
1646+
worldInfo["dayOfWeek"] = new ValNumber((int)SDate.Now().DayOfWeek);
16551647

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

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

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

16771657
// The human-readable representation for the current in-game season.
1678-
f = Intrinsic.Create("");
1679-
f.code = (context, partialResult) => {
1680-
return new Intrinsic.Result(new ValString(SDate.Now().Season));
1658+
worldInfo["seasonName"] = new ValString(SDate.Now().Season);
1659+
1660+
// The current weather
1661+
{
1662+
var loc = (Farm)Game1.getLocationFromName("Farm");
1663+
var weather = Game1.netWorldState.Value.GetWeatherForLocation(loc.GetLocationContext());
1664+
string result = "Sunny";
1665+
if (weather.isLightning) result = "stormy";
1666+
else if (weather.isRaining) result = "raining";
1667+
else if (weather.isSnowing) result = "snowing";
1668+
else if (weather.isDebrisWeather) result = "windy";
1669+
worldInfo["weather"] = new ValString(result);
16811670
};
1682-
worldModule["seasonName"] = f.GetFunc();
16831671

1684-
return worldModule;
1672+
// Daily luck
1673+
worldInfo["luck"] = new ValNumber(Game1.player.DailyLuck);
1674+
1675+
return worldInfo;
16851676
}
16861677

16871678
/// <summary>

M1/assets/sysdisk/help/topics.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
Available topics:
22
files coding demos
33
text input community
4-
farm bot toDo
4+
farm bot world
5+
toDo
56

67
(Access these with, for example:
78
`help "demos"` -- remember to use

M1/assets/sysdisk/help/world.txt

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
The `world` global provides a information
2+
about the world. This includes current
3+
date, time, and weather. Try:
4+
5+
`pprint world`

M1/assets/sysdisk/lib/editor.ms

+74-2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ pal.cursor = "#CCCCFF"
2121
pal.topBar = "#AAAAAA"
2222
pal.topBarText = "#8888CC"
2323

24+
cutLines = []
25+
linesCutFromLineNum = null
26+
2427
lineLen = function(lineNum)
2528
if lineNum < data.len then return data[lineNum].len
2629
return 0
@@ -33,7 +36,7 @@ drawTopBar = function()
3336
print " " + _sourceFile
3437
lstr = str(cursorY + 1)
3538
print " " * (screenW - 13 - lstr.len - text.column)
36-
print "^Q: Quit L" + lstr
39+
print "^H: Help L" + lstr
3740
print " " * (screenW - text.column)
3841
end function
3942

@@ -172,6 +175,66 @@ nextWord = function(dir)
172175
outer.cursorX = x
173176
end function
174177

178+
cutLine = function
179+
if cursorY != linesCutFromLineNum then
180+
outer.cutLines = []
181+
outer.linesCutFromLineNum = cursorY
182+
end if
183+
if cursorY >= data.len then return "End of File"
184+
cutLines.push data[cursorY]
185+
data.remove cursorY
186+
refreshDisplay
187+
if cutLines.len == 1 then return "Cut (1 Line)"
188+
return "Cut (" + cutLines.len + " Lines)"
189+
end function
190+
191+
pasteLines = function
192+
for line in cutLines
193+
data.insert cursorY, line
194+
outer.cursorY = cursorY + 1
195+
end for
196+
scrollCursorIntoView
197+
refreshDisplay
198+
if cutLines.len == 1 then return "Paste (1 Line)"
199+
return "Paste (" + cutLines.len + " Lines)"
200+
end function
201+
202+
showHelp = function
203+
text.color = pal.text; text.backColor = "#4F1CDBFF"
204+
text.clear; text.delimiter = char(13)
205+
text.row = 19; text.column = 0
206+
text.inverse = true
207+
print " "*8 + "Farmtronics Text Editor" + " "*9
208+
text.inverse = false
209+
print "Hold the Control key and press a letter"
210+
print "to perform one of the functions below."
211+
print "Example: "
212+
print " ^Q means hold Contol and press Q."
213+
print
214+
funcs = [
215+
"^A: Go to start of line",
216+
"^E: Go to end of line",
217+
"^U: Page up",
218+
"^D: Page down",
219+
"^K: Cut line(s)",
220+
"^V: Paste line(s)",
221+
"^H: View this help",
222+
"^Q: Quit"]
223+
text.delimiter = ""
224+
for func in funcs
225+
parts = func.split(":")
226+
text.column = 3; text.inverse = true
227+
print parts[0] + " "
228+
text.inverse = false
229+
print parts[1] + char(13)
230+
end for
231+
text.row = 0
232+
print "(Press any key to continue.)"
233+
key.get
234+
text.backColor = color.clear
235+
refreshDisplay
236+
end function
237+
175238
showCommand = function(keyPress, desc)
176239
refreshRow 0
177240
s = keyPress
@@ -197,18 +260,27 @@ handleControlKey = function(k)
197260
if kcode > 31 then keyPress = "^" + char(kcode)
198261
if anyShift then keyPress = "Shift-" + keyPress
199262

263+
// Want to customize your key bindings? Change
264+
// the code below, and the help in showHelp above.
200265
if keyPress == "^A" then // ctrl-A (start of line)
201266
desc = "LineStart"
202267
outer.cursorX = 0
203268
else if keyPress == "^E" then // ctrl-E (end of line)
204269
desc = "LineEnd"
205270
outer.cursorX = lineLen(cursorY)
271+
else if keyPress == "^H" then // help
272+
showHelp
273+
desc = "Help"
206274
else if keyPress == "^U" then // Page Up
207275
desc = "PageUp"
208276
outer.cursorY = outer.cursorY - screenLines
209277
else if keyPress == "^D" then // Page Down
210278
desc = "PageDown"
211-
outer.cursorY = outer.cursorY + screenLines
279+
outer.cursorY = outer.cursorY + screenLines
280+
else if keyPress == "^K" then // Cut line
281+
desc = cutLine
282+
else if keyPress == "^V" then // Paste lines
283+
desc = pasteLines
212284
else if keyPress == "^Q" then // Escape or Ctrl+X
213285
desc = "Quit"
214286
outer.quitting = true

0 commit comments

Comments
 (0)