Skip to content

Commit db7f563

Browse files
committed
Updated startup and help for change from bot to me; added bot checks to all such methods;
fixed some issues with text color, including inverse mode when background is clear.
1 parent f2900da commit db7f563

File tree

11 files changed

+138
-86
lines changed

11 files changed

+138
-86
lines changed

Farmtronics/Bot/ModData.cs

+4-6
Original file line numberDiff line numberDiff line change
@@ -123,12 +123,10 @@ private Dictionary<string, string> GetModData(bool isSaving) {
123123

124124
public ModData(BotObject bot) {
125125
this.bot = bot;
126-
#if DEBUG
127-
this.bot.modData.OnValueAdded += (key, value) => ModEntry.instance.Monitor.Log($"{Name} ModData OnValueAdded: {key}: {value}");
128-
this.bot.modData.OnValueRemoved += (key, value) => ModEntry.instance.Monitor.Log($"{Name} ModData OnValueRemoved: {key}: {value}");
129-
this.bot.modData.OnValueTargetUpdated += (key, oldValue, newValue) => ModEntry.instance.Monitor.Log($"{Name} ModData OnValueUpdated: {key}: {oldValue} -> {newValue}");
130-
this.bot.modData.OnConflictResolve += (key, rejected, accepted) => ModEntry.instance.Monitor.Log($"{Name} ModData OnConflictResolve: {key}: Rejected: {rejected} Accepted: {accepted}");
131-
#endif
126+
//this.bot.modData.OnValueAdded += (key, value) => ModEntry.instance.Monitor.Log($"{Name} ModData OnValueAdded: {key}: {value}");
127+
//this.bot.modData.OnValueRemoved += (key, value) => ModEntry.instance.Monitor.Log($"{Name} ModData OnValueRemoved: {key}: {value}");
128+
//this.bot.modData.OnValueTargetUpdated += (key, oldValue, newValue) => ModEntry.instance.Monitor.Log($"{Name} ModData OnValueUpdated: {key}: {oldValue} -> {newValue}");
129+
//this.bot.modData.OnConflictResolve += (key, rejected, accepted) => ModEntry.instance.Monitor.Log($"{Name} ModData OnConflictResolve: {key}: Rejected: {rejected} Accepted: {accepted}");
132130
this.serializer = SaveGame.GetSerializer(typeof(NetObjectList<Item>));
133131
this.Load(false);
134132
this.Save(false);

Farmtronics/Farmtronics.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<PropertyGroup>
44
<Copyright>Copyright © $([System.DateTime]::UtcNow.Year) Joe Strout ($([System.DateTime]::UtcNow.ToString("s")))</Copyright>
55
<TargetFramework>net5.0</TargetFramework>
6-
<ReleaseVersion>1.0</ReleaseVersion>
6+
<ReleaseVersion>1.3</ReleaseVersion>
77
<ModFolderName>Farmtronics</ModFolderName>
88
<BundleExtraAssemblies>ThirdParty</BundleExtraAssemblies>
99
</PropertyGroup>

Farmtronics/Farmtronics.sln

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Global
2323
SolutionGuid = {1A1D1271-8E80-4A8D-A57B-267C68FE3D68}
2424
EndGlobalSection
2525
GlobalSection(MonoDevelopProperties) = preSolution
26-
version = 1.0
26+
version = 1.3
2727
Policies = $0
2828
$0.DotNetNamingPolicy = $1
2929
$1.DirectoryNamespaceAssociation = PrefixedHierarchical

Farmtronics/M1/Console.cs

+8-3
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,11 @@ class Console : IClickableMenu, IKeyboardSubscriber {
2626

2727
Shell owner;
2828
public TextDisplay display { get; private set; }
29-
public Color backColor;
29+
Color _backColor = Color.DeepSkyBlue;
30+
public Color backColor {
31+
get { return _backColor; }
32+
set { _backColor = value; if (display != null) display.screenColor = value; }
33+
}
3034

3135
bool inInputMode;
3236
RowCol inputStartPos; // where on the screen we started taking input
@@ -61,7 +65,8 @@ public Console(Shell owner)
6165

6266
display = new TextDisplay();
6367
display.onScrolled += NoteScrolled;
64-
display.backColor = new Color(0.31f, 0.11f, 0.86f);
68+
display.backColor = Color.Transparent;
69+
display.screenColor = _backColor;
6570
display.Clear();
6671

6772
var colors = new Color[] { Color.Red, Color.Yellow, Color.Green, Color.Purple };
@@ -319,7 +324,7 @@ public override void update(GameTime time) {
319324
foreach (var kw in keyWatchers) {
320325
kw.Update(time);
321326
if (kw.justPressedOrRepeats) {
322-
ModEntry.instance.Monitor.Log($"KeyWatcher {kw.keyButton} pressed or repeats");
327+
//ModEntry.instance.Monitor.Log($"KeyWatcher {kw.keyButton} pressed or repeats");
323328
HandleKey(kw.keyChar);
324329
}
325330
}

Farmtronics/M1/GUI/TextDisplay.cs

+5-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ class TextDisplay {
1414
public float colSpacing = 16;
1515
public float rowSpacing = 24;
1616
public Color textColor = Color.White;
17-
public Color backColor = Color.DeepSkyBlue;
17+
public Color backColor = Color.Transparent;
18+
public Color screenColor = Color.Black; // (used in special case of inverse text with clear backColor)
1819
public bool inverse;
1920
public float cursorOnTime = 0.7f;
2021
public float cursorOffTime = 0.3f;
@@ -290,6 +291,9 @@ public void Render(SpriteBatch b, Rectangle displayArea) {
290291
for (int row=0; row<rows; row++) {
291292
for (int col=0; col<cols; col++) {
292293
Color c = cells[row, col].inverse ? cells[row,col].backColor : cells[row,col].foreColor;
294+
// Special case: if the text color is clear because of inverse mode, we won't be able to actually see it.
295+
// In this case, explicitly draw the screen color.
296+
if (c.A == 0) c = screenColor;
293297
DrawFontCell(b, cells[row, col].character, c, col, row, displayArea);
294298
}
295299
}

Farmtronics/M1/M1API.cs

+43-3
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,12 @@ static bool DisallowAllAssignment(Value key, Value value) {
307307
throw new RuntimeException("Assignment to protected map");
308308
}
309309

310+
static bool RequireBot(Shell sh, string methodName) {
311+
if (sh.bot != null) return false;
312+
sh.PrintLine($"me.{methodName} is only valid for bots");
313+
return true;
314+
}
315+
310316
static ValMap meModule;
311317
static HashSet<string> botProtectedKeys;
312318
public static ValMap MeModule() {
@@ -330,37 +336,51 @@ public static ValMap MeModule() {
330336
};
331337
meModule["name"] = f.GetFunc();
332338

339+
333340
f = Intrinsic.Create("");
334341
f.code = (context, partialResult) => {
335342
Shell sh = context.interpreter.hostData as Shell;
343+
if (RequireBot(sh, "facing")) return Intrinsic.Result.Null;
336344
return new Intrinsic.Result(new ValNumber(sh.bot.facingDirection));
337345
};
338346
meModule["facing"] = f.GetFunc();
339347

340348
f = Intrinsic.Create("");
341349
f.code = (context, partialResult) => {
342350
Shell sh = context.interpreter.hostData as Shell;
351+
if (RequireBot(sh, "currentToolIndex")) return Intrinsic.Result.Null;
343352
return new Intrinsic.Result(new ValNumber(sh.bot.currentToolIndex));
344353
};
345354
meModule["currentToolIndex"] = f.GetFunc();
346355

347356
f = Intrinsic.Create("");
348357
f.code = (context, partialResult) => {
349358
Shell sh = context.interpreter.hostData as Shell;
359+
if (RequireBot(sh, "energy")) return Intrinsic.Result.Null;
350360
return new Intrinsic.Result(new ValNumber(sh.bot.energy));
351361
};
352362
meModule["energy"] = f.GetFunc();
353363

354364
f = Intrinsic.Create("");
355365
f.code = (context, partialResult) => {
356366
Shell sh = context.interpreter.hostData as Shell;
367+
if (RequireBot(sh, "statusColor")) return Intrinsic.Result.Null;
357368
return new Intrinsic.Result(new ValString(sh.bot.statusColor.ToHexString()));
358369
};
359370
meModule["statusColor"] = f.GetFunc();
360371

361372
f = Intrinsic.Create("");
362373
f.code = (context, partialResult) => {
363374
Shell sh = context.interpreter.hostData as Shell;
375+
if (sh.bot == null) return new Intrinsic.Result(new ValString(sh.console.backColor.ToHexString()));
376+
return new Intrinsic.Result(new ValString(sh.bot.screenColor.ToHexString()));
377+
};
378+
meModule["screenColor"] = f.GetFunc();
379+
380+
f = Intrinsic.Create("");
381+
f.code = (context, partialResult) => {
382+
Shell sh = context.interpreter.hostData as Shell;
383+
if (RequireBot(sh, "forward")) return Intrinsic.Result.Null;
364384
if (partialResult == null) {
365385
// Just starting our move; tell the bot and return partial result
366386
sh.bot.MoveForward();
@@ -376,6 +396,7 @@ public static ValMap MeModule() {
376396
f = Intrinsic.Create("");
377397
f.code = (context, partialResult) => {
378398
Shell sh = context.interpreter.hostData as Shell;
399+
if (RequireBot(sh, "inventory")) return Intrinsic.Result.Null;
379400
ValList result = new ValList();
380401
if (sh.bot.inventory != null) {
381402
foreach (var item in sh.bot.inventory) {
@@ -389,6 +410,7 @@ public static ValMap MeModule() {
389410
f = Intrinsic.Create("");
390411
f.code = (context, partialResult) => {
391412
Shell sh = context.interpreter.hostData as Shell;
413+
if (RequireBot(sh, "left")) return Intrinsic.Result.Null;
392414
sh.bot.Rotate(-1);
393415
return Intrinsic.Result.Null;
394416
};
@@ -397,6 +419,7 @@ public static ValMap MeModule() {
397419
f = Intrinsic.Create("");
398420
f.code = (context, partialResult) => {
399421
Shell sh = context.interpreter.hostData as Shell;
422+
if (RequireBot(sh, "position")) return Intrinsic.Result.Null;
400423
var pos = sh.bot.TileLocation;
401424
var loc = sh.bot.currentLocation;
402425
var result = new ValMap();
@@ -410,6 +433,7 @@ public static ValMap MeModule() {
410433
f = Intrinsic.Create("");
411434
f.code = (context, partialResult) => {
412435
Shell sh = context.interpreter.hostData as Shell;
436+
if (RequireBot(sh, "right")) return Intrinsic.Result.Null;
413437
sh.bot.Rotate(1);
414438
return Intrinsic.Result.Null;
415439
};
@@ -420,6 +444,7 @@ public static ValMap MeModule() {
420444
// For now, we'll just always place as many as possible.
421445
f.code = (context, partialResult) => {
422446
Shell sh = context.interpreter.hostData as Shell;
447+
if (RequireBot(sh, "placeItem")) return Intrinsic.Result.Null;
423448
int itemsPlaced = sh.bot.PlaceItem();
424449
return new Intrinsic.Result(itemsPlaced);
425450
};
@@ -429,6 +454,7 @@ public static ValMap MeModule() {
429454
f.AddParam("slot", 0);
430455
f.code = (context, partialResult) => {
431456
Shell sh = context.interpreter.hostData as Shell;
457+
if (RequireBot(sh, "takeItem")) return Intrinsic.Result.Null;
432458
bool result = sh.bot.TakeItem(context.GetLocalInt("slot"));
433459
return result ? Intrinsic.Result.True : Intrinsic.Result.False;
434460
};
@@ -437,6 +463,7 @@ public static ValMap MeModule() {
437463
f = Intrinsic.Create("");
438464
f.code = (context, partialResult) => {
439465
Shell sh = context.interpreter.hostData as Shell;
466+
if (RequireBot(sh, "useTool")) return Intrinsic.Result.Null;
440467

441468
if (partialResult == null) {
442469
// Just starting our tool use; tell the bot and return partial result
@@ -453,6 +480,7 @@ public static ValMap MeModule() {
453480
f = Intrinsic.Create("");
454481
f.code = (context, partialResult) => {
455482
Shell sh = context.interpreter.hostData as Shell;
483+
if (RequireBot(sh, "harvest")) return Intrinsic.Result.Null;
456484

457485
bool result = sh.bot.Harvest();
458486
return result ? Intrinsic.Result.True : Intrinsic.Result.False;
@@ -477,11 +505,23 @@ public static ValMap MeModule() {
477505
}
478506
return true;
479507
} else if (keyStr == "statusColor") {
480-
Shell.runningInstance.bot.statusColor = value.ToString().ToColor();
481-
if (Context.IsMultiplayer) Shell.runningInstance.bot.data.Update();
508+
var sh = Shell.runningInstance;
509+
if (RequireBot(sh, keyStr)) return true;
510+
sh.bot.statusColor = value.ToString().ToColor();
511+
if (Context.IsMultiplayer) sh.bot.data.Update();
512+
return true;
513+
} else if (keyStr == "screenColor") {
514+
var sh = Shell.runningInstance;
515+
sh.console.backColor = value.ToString().ToColor();
516+
if (sh.bot != null) {
517+
sh.bot.screenColor = value.ToString().ToColor();
518+
if (Context.IsMultiplayer) sh.bot.data.Update();
519+
}
482520
return true;
483521
} else if (keyStr == "currentToolIndex") {
484-
Shell.runningInstance.bot.currentToolIndex = value.IntValue();
522+
var sh = Shell.runningInstance;
523+
if (RequireBot(sh, keyStr)) return true;
524+
sh.bot.currentToolIndex = value.IntValue();
485525
return true;
486526
} else if (botProtectedKeys.Contains(keyStr)) return true;
487527
return false; // allow the assignment

Farmtronics/M1/Shell.cs

+3-4
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ public void Init(long playerID, BotObject botContext=null) {
6868
M1API.Init(this);
6969

7070
var display = console.display;
71-
display.backColor = new Color(0.31f, 0.11f, 0.86f);
7271
display.Clear();
7372

7473
var colors = new Color[] { Color.Red, Color.Yellow, Color.Green, Color.Purple };
@@ -320,9 +319,9 @@ public void AddGlobals() {
320319
string keyStr = key.ToString();
321320
if (keyStr == "_") return false;
322321
//ModEntry.instance.Monitor.Log($"global {key} = {value}");
323-
if (keyStr == "statusColor") { // DEPRECATED: now in bot module
322+
if (keyStr == "statusColor") { // DEPRECATED: now in me module
324323
bot.statusColor = value.ToString().ToColor();
325-
} else if (keyStr == "screenColor") {
324+
} else if (keyStr == "screenColor") { // DEPRECATED: now in me module
326325
bot.screenColor = value.ToString().ToColor();
327326
}
328327
bot.data.Update();
@@ -334,7 +333,7 @@ public void AddGlobals() {
334333
string keyStr = key.ToString();
335334
if (keyStr == "_") return false;
336335
//ModEntry.instance.Monitor.Log($"global {key} = {value}");
337-
if (keyStr == "screenColor") {
336+
if (keyStr == "screenColor") { // DEPRECATED: now in me module
338337
console.backColor = value.ToString().ToColor();
339338
}
340339
return false; // allow the assignment

Farmtronics/assets/sysdisk/help/bot.txt

-35
This file was deleted.
+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
The `me` module provides access to the
2+
machine environment. Most of these work
3+
only on robots; on the Home Computer,
4+
only `me.screenColor`, `me.name`, and
5+
`me.isBot` are functional.
6+
7+
Read-only properties:
8+
`me.isBot`: 1 if robot, 0 if computer
9+
`me.position`: current tile position
10+
`me.facing`: 0=north, 1=east, etc.
11+
`me.energy`: energy left (0-270)
12+
`me.inventory`: list of items carried
13+
`me.here`: same as `me.position.area`
14+
`me.ahead`: info on tile ahead of me
15+
16+
Read/write properties:
17+
`me.name`: robotbot or computer name
18+
`me.screenColor`: screen background color
19+
`me.currentToolIndex`: selected item
20+
`me.statusColor`: color of status light
21+
22+
Methods:
23+
`me.forward`: move forward 1 tile
24+
`me.left`: turn left
25+
`me.right`: turn right
26+
`me.select toolNameOrIndex`: choose item
27+
`me.placeItem`: place item down
28+
`me.takeItem`: take item from chest
29+
`me.harvest`: harvest a crop/item
30+
`me.useTool`: apply current tool
31+
`me.clearAhead`: choose/apply tool
32+
`me.clearAndMove`: clear ahead and move
33+
(optionally specify # of tiles)
34+
35+
Note that each robot must be given a
36+
suitable set of tools for the tasks you
37+
program them to do.

Farmtronics/assets/sysdisk/help/topics.txt

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

77
(Access these with, for example:

0 commit comments

Comments
 (0)