Commit Graph

1000 Commits

Author SHA1 Message Date
Karl Ostmo
35c2c2c5af
Handle all pattern match cases in testSolution' (#841)
It was possible to get a runtime failure on the following before:
```
Right gs <- runExceptT $ initGameStateForScenario p Nothing Nothing
```
Should probably also turn on compiler warnings for incomplete matching.
2022-11-06 23:33:25 +00:00
Brent Yorgey
e0a275fb32
Ignore scenario subdirs starting with underscore (#837)
Such subdirectories can be used to e.g. organize `.sw` files, and will be ignored when recursively loading scenarios.

This resolves an issue we noticed while reviewing #835, which uses a subdirectory to hold multiple `.sw` files for a scenario and was generating a lot of spurious warnings.
2022-11-06 20:28:09 +00:00
Karl Ostmo
29594abfa2
Revert "New ranching scenario" (#834)
This reverts commit 146cd4b9a4.
2022-11-05 22:45:10 +00:00
Karl Ostmo
146cd4b9a4 New ranching scenario 2022-11-05 14:43:50 -07:00
Karl Ostmo
0e09d47c1f
Drills by capability (#830)
This PR consists of two commits:
1. Refactor list of capabilities to sets (continuation of #794)
2. Instead of hard-coding drill names, select equipped entities by their `drill` capability

This allows scenario authors to define their own drills.
2022-11-05 21:05:53 +00:00
Brent Yorgey
9d5df80e01
Copy requirements map to robot context when loading a new ProcessedTerm (#827)
Closes #540.

When we typecheck and capability check a new term, resulting in a `ProcessedTerm`, we already know the `Requirement`s for all the `def`s it contains.  This PR simply takes all those definition requirements and adds them to `robotContext . defReqs` just before installing the new `ProcessedTerm` in the CESK machine, so that if we ever encounter the name of any of the definitions inside an argument to `build` or `reprogram`---which we capability check at runtime---we will be able to properly match up names with their requirements.

This is a hack for several reasons:
- We really shouldn't be capability-checking arguments to `build` and `reprogram` at runtime in the first place---ideally we should be able to check everything statically.  But fixing that will require implementing #231 .
- We have to do this in three places in the code: when loading a new term into the base when the player hits Enter at the REPL; when executing `run`; and when running the solution from a scenario in the integration tests.  Ideally, there would be only one place, but I don't have a good idea at the moment how to refactor things properly.
- Technically, the names being defined shouldn't be in scope until after their corresponding `def` runs, so it's incorrect to dump them all into the `defReqs` prior to executing any of the `def`s.
    - However, doing it properly, with each name coming into scope with its requirements right after the `def` runs, is very tricky/annoying to implement for more reasons than I care to write about here (believe me, I tried, and it made my brain hurt).  For starters, we don't really have access to the robot state when stepping the CESK machine.
    - The only scenario where this would be a problem is if (1) there is already a name `x` defined, and then we (2) `run` a `.sw` file containing, first, a `build` command whose argument references `x`, and second, a redefinition of `x`.  In that case the `build` would incorrectly decide that the `x` in the argument to `build` has the requirements of the *second* `x` (the one that will be redefined later) even though the first `x` is the one that should still be in scope.  However, this seems like a very unlikely scenario (who would write a `.sw` file that depends on some specific name already being defined before it is run, but then redefines that same name later?) and I'd *much* rather have that obscure problem than the current very relevant and annoying one.

However, it's a simple hack that solves the issue and will be easy to get rid of later if and when we do something better.  I'm a big believer in doing things the right way, but in this instance I definitely think we should just do the simple thing that mostly works and then continue to make it better in the future.
2022-11-05 17:51:46 +00:00
Karl Ostmo
f117e512c1
Expose REPL history via web interface (#821)
This makes it possible to dump the commands typed into the REPL to a text file, which makes it easier to start writing an external `.sw` script based on experiments written in the REPL.

E.g.

    curl http://localhost:5357/repl/history/full | jq .[] -r

This is related to (and may be a stepping stone towards) #625.
2022-11-04 19:42:27 +00:00
Karl Ostmo
d88fe60a35
Ctrl+C should clear the REPL text (#824)
Currently there's no (obvious?) shortcut to clear the currently typed text in the REPL.

Mapping CTRL+c to this action would be familiar to terminal users.
2022-11-04 19:01:06 +00:00
Karl Ostmo
b5b83fc592
Add a "driving mode" to the REPL (#819)
Ctrl+d in the REPL will toggle into "driving mode".  In this mode, the arrow keys simply submit predefined commands to the REPL:
| Key | REPL input |
| --- | --- |
| ↑ | `move;` |
| ↓ | `turn back;` |
| ← | `turn left;` |
| → | `turn right;` |

This yields a pretty natural driving experience:

<a href="https://asciinema.org/a/pZQ7wexMllA5S3v9VrsrdjtsN" target="_blank"><img src="https://asciinema.org/a/pZQ7wexMllA5S3v9VrsrdjtsN.svg" width="640" /></a>
2022-11-04 18:38:43 +00:00
Karl Ostmo
a8618b6792
use two rows for keyboard commands list (#822)
There are too many keyboard commands to list on one line, so they get cut off even with a very wide terminal.  This PR splits panel-specific commands into a separate row from global commands.

| Version | Screenshot |
| --- | --- |
| Before: | ![Screenshot from 2022-11-04 01-30-49](https://user-images.githubusercontent.com/261693/199928352-5e1c2c15-4ae3-41e1-b8ac-9943dd9d548d.png) |
| After: | ![Screenshot from 2022-11-04 01-30-08](https://user-images.githubusercontent.com/261693/199928331-b797d760-4272-493f-b26c-da9cddc5f8e2.png) |
2022-11-04 09:09:48 +00:00
Brent Yorgey
971317f35a
allow brick-1.4 (#818)
No API changes that affect us but apparently some nice performance improvements.
2022-11-03 10:18:39 +00:00
Brent Yorgey
e378fbf87d
copy parent robot context to child when executing build (#817)
Fixes #394.
2022-11-02 20:26:07 +00:00
Brent Yorgey
ca6a4e14cc
0.2.0.0 release (#809)
CHANGELOG and `.cabal` edit for 0.2.0.0 release.  If anyone wants to slide anything else into this release, speak up!
2022-11-01 17:50:36 +00:00
Karl Ostmo
f240f5ee54
Link to editors folder 2022-11-01 10:29:26 -07:00
Brent Yorgey
e3ab68c3de
update editors syntax with unit type (#814) 2022-11-01 12:24:41 -05:00
Ondřej Šebek
33fb9b23c9
Update editors with void and tweak VSCode coloring (#812) 2022-11-01 17:25:50 +01:00
Ondřej Šebek
703c720a1f
Fix listening logic and ignore messages by self (#810)
- add predicate checking if the message was produced by this robot
- compose the predicates correctly (system robots ignored time)
- closes #763
2022-11-01 16:23:15 +00:00
Brent Yorgey
1d9288104a
set focus to REPL panel when clicking on REPL input (#808)
Ensure that focus changes to the REPL panel also when clicking on the REPL input itself.

Cleaning up a small leftover issue from #801.
2022-10-31 20:06:11 +00:00
Ondřej Šebek
2293f335be
Hide robots for two seconds (#802)
- closes #761
2022-10-31 19:52:34 +00:00
Ondřej Šebek
7185700a1e
Make REPLPanel not blink when it is not selected (#801)
- closes #776
2022-10-31 19:41:36 +00:00
Ondřej Šebek
451e2ed7f2
Generate other wikis (#769)
- generate wiki for:
  - entities
  - recipes (table and added recipe graph image)
  - capabilities (only table)
- properly parse command line argument for `generate cheatsheet`
- closes #344
2022-10-31 17:03:56 +00:00
Brent Yorgey
a4d0d230cd
allow latest versions of dependencies + GHC 9.4 (#752)
Update dependencies + add GHC 9.4 to CI.  Closes #748 .
2022-10-31 02:51:43 +00:00
Ondřej Šebek
69d8fd4015
Fix lodestone test (#806)
Turns out the test was not actually blocked by #540, I just did not investigate it properly.
2022-10-31 02:41:07 +00:00
Karl Ostmo
5f4205e950
Disambiguate choice of base robot (#805)
When none of the robot definitions are assigned explicit coordinates (i.e. all of the robots are specified via the map and palette), this allows scenario authors to determine the "base" robot via the order of definitions as they exist in the scenario file.

A comment detailing the base selection logic has also been added.

closes #790
2022-10-30 05:30:59 +00:00
Karl Ostmo
8c01fc13e2
autocomplete entity names in the repl (#798) 2022-10-29 17:13:24 +00:00
Brent Yorgey
0efc6b5b90
Tutorial tweaks (#800)
A few tweaks and updates to the tutorial goal descriptions to match the latest game features.
2022-10-29 15:19:28 +00:00
Karl Ostmo
a433076586
User-controllable sort criteria (#793)
When the inventory pane is selected (Alt+e), one can use the `;` and `:` keys to cycle sort criteria and sort direction, respectively.
![Screenshot from 2022-10-26 21-52-11](https://user-images.githubusercontent.com/261693/198195262-e0ba6f22-cdda-4a29-bc99-398f721a1ed5.png)

This functionality is implemented in a new module to avoid exacerbating #707.

Note that `entityProperties` may be an unreliable criteria to sort, because it is a list that itself may contain duplicates or items in unpredictable order.  Perhaps this field should be made a `Set` (#794).
2022-10-29 10:55:26 +00:00
Karl Ostmo
5165b576ae
Introduce autoplay flag (#792)
This PR introduces an `--autoplay` flag that causes the solution stored in the `solutions` field of a scenario file (which was selected on the command line via the `--scenario` option) to be automatically run when the game starts, identically to the `--run` option.

The purpose is to:
1. more easily showcase scenarios to the community
2. facilitate a quick a sanity check that the solution text in the yaml file is correct

# Test procedure

    stack run -- --scenario data/scenarios/Tutorials/conditionals.yaml --autoplay

This has the same effect as manually copying the solution stored in `conditionals.yaml` to `myfile.sw`, and then running:

    stack run -- --scenario data/scenarios/Tutorials/conditionals.yaml --run myfile.sw

<a href="https://asciinema.org/a/mGB5VDKhsLLPdrItZWi3qsHUV" target="_blank"><img src="https://asciinema.org/a/mGB5VDKhsLLPdrItZWi3qsHUV.svg" width="640" /></a>
2022-10-28 04:47:18 +00:00
Karl Ostmo
36006154b7
Use Set instead of a list for entity properties, for sortability (#794)
It is possible for list to contain duplicates or items in unpredictable order.
2022-10-28 04:25:10 +00:00
Karl Ostmo
99028f5b64
Elaborate help text for --cheat flag (#791) 2022-10-25 18:31:28 +00:00
Brent Yorgey
c323e0df84
add lambdas to requireinv scenario and change solution to use them (#784)
This is a pretty simple change --- we've already covered lambdas previously in the tutorial so it's annoying not to be able to use them to define things like `x4 = \c. c;c;c;c end`.  But just wanted to make sure there's nothing I'm missing here.
2022-10-25 18:18:36 +00:00
Brent Yorgey
ad096d5000
Better advertise pop-out for entity descriptions (#781)
Closes #764.

- Hint now says `[Ret] pop out` instead of `[Ret] focus`.
- `pop out` is now highlighted whenever the info panel can scroll.
- Add hints to the tutorial about popping out or scrolling entity descriptions.
- All panel-specific keys are now highlighted the same color as the focused panel.
- Added a panel-specific key hint for `f` on the World panel toggling FPS info.
2022-10-24 21:52:40 +00:00
Karl Ostmo
37b0e3fc8a
Preserve seed upon restart (#787)
Part of #549

Before this change, if the Classic scenario was started:

```
stack run -- --scenario data/scenarios/classic.yaml
```
and then "Start over" is selected from the Quit dialog, a new seed was generated.

Now, the previous seed is re-used.
2022-10-24 17:14:34 +00:00
Brent Yorgey
1dc22919ba
tell brick to join lines inside dialogs too (#783)
Closes #780.
2022-10-24 12:02:43 +00:00
Karl Ostmo
13e7dfeb52
Use scenario name as Goal dialog title (#774)
part of #760
2022-10-23 16:39:40 +00:00
Brent Yorgey
e6a39593bd
make inventory sort case-insensitive (#775)
Part of #519.
2022-10-23 11:46:51 +00:00
Karl Ostmo
f480426162
Add a button to the Quit dialog to restart a scenario. (#767)
Closes #549
2022-10-22 15:07:56 -07:00
Ondřej Šebek
696ff4b639
Default invisibity to system robot value (#768)
- closes #726
2022-10-22 22:01:04 +00:00
Karl Ostmo
71403e9393
rerun fourmolu globally (#772)
There was one file that is not currently formatted.
2022-10-22 00:47:53 -07:00
Karl Ostmo
fe21480eba
fix typo: "inhabitants" (#771) 2022-10-21 22:26:08 +00:00
Brent Yorgey
9942c2c3da
Make sure newly built robots consistently face north (#766)
Closes #757 .  As discussed there:

- Default direction for robots whose parents have no direction is now `north`
- Fix the `scan` tutorial `base` to be facing north
- Clarify the text in the `build` tutorial to state that newly built robots face the same direction as their parent, which in the tutorial will always be north.
2022-10-21 10:37:02 +00:00
Brent Yorgey
f54d8339d0
Improve user experience around quitting & moving between tutorial challenges (#754)
- Help modal now says "quit the current scenario" instead of "quit game" for Ctrl-q
- If you select "Keep playing" after completing a challenge scenario, it will now pop up a modal advising you to hit Ctrl-q whenever you're ready to move on.
- Added a note at the beginning of the tutorial reassuring that your progress will be saved and you can pick up where you left off from the menu.
- Improved quit dialog in a couple ways:
    - Now warns that "your progress *on the current scenario* will be lost" (to emphasize that e.g. your progress on the entire tutorial won't be lost).
    - Now says "quit to XXX menu" where XXX is the specific menu you will return to.

Closes #595. Closes #759.
2022-10-21 10:24:02 +00:00
Ondřej Šebek
d0305c4285
Fix backstory loop (#762)
- closes #756
2022-10-19 12:59:22 +00:00
Steven Garcia
758b3d0192
Add void type (#735)
Closes #665 

### todo
- [x] add void to the parser for types
- [x] add two tests
- [ ] mention `void` in the description of an `ADT calculator`
2022-10-19 01:28:37 +00:00
Brent Yorgey
faab7046b9
improved handling of REPL mouse clicks (#750)
- Never clear the `uiWorldCursor`.
    - In practice it seemed annoying and glitchy to understand when it would or wouldn't clear.  After clicking somewhere on the map to see the coordinates I was always afraid I was going to do the wrong thing and cause the cursor display to clear before I could make use of it.
- Pass on mouse clicks to the REPL input form 
    - This means you can click in the middle of the input to move the cursor 
    - Closes #470.
2022-10-18 18:02:31 +00:00
Ondřej Šebek
0efb1c3e6d
Use Node 16 in both VS Code actions (#751) 2022-10-18 19:24:41 +02:00
Ondřej Šebek
b8956689d9
Move TH GitInfo back to Main (#749)
It is probably safer to have Template Haskell GitInfo in Main and not depend on it in Swarm modules.

Depending on how the build system and TH interact we were either recompiling too often or not often enough.
- if the git info was evaluated once and not again after making a commit, then it was not up to date
- if the git info was reevaluated on every commit then we would needlessly recompile dependent modules

I believe it was only the former, but this helps even in that case (any code change recompiles Main).
2022-10-16 22:17:34 +00:00
Valentin Golev
977e0edd68
expose the last evaluated result as it in REPL (#734)
Co-authored-by: Restyled.io <commits@restyled.io>
Co-authored-by: Brent Yorgey <byorgey@gmail.com>
2022-10-16 22:21:36 +02:00
Brent Yorgey
683508f36e
CHANGELOG for 0.1.1 release (#747)
I propose making a 0.1.1.0 release with the Hackage hsnoise fix and the few extra features we've accumulated so far.
2022-10-14 11:09:53 +00:00
Brent Yorgey
58ff215480
upgrade to hsnoise-0.0.3 (#746)
Closes #745.
2022-10-13 20:48:56 +00:00