Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Render map preview on scenario selection screen #1515

Merged
merged 8 commits into from
Sep 15, 2023

Conversation

kostmo
Copy link
Member

@kostmo kostmo commented Sep 11, 2023

Closes #353
Also towards #1415

Also adds a new top-level command to render a scenario map to the console.

Most of the work for this feature entailed identifying the subset of GameState that is actually needed for rendering the world, so that the required information can be retrieved from just the Scenario rather than having to instantiate an entire GameState.

Potential follow-ups

  • There is some noticeable lag when using the up/down arrow to navigate to any of the largely "procedurally generated" scenarios, e.g. classic or creative. May want to do caching of some kind. The other "challenge scenarios" render without perceptible delay.
  • The heuristic for choosing the view center could be improved, possibly by defining new "hints" as part of the scenario schema.
  • Rendering to the console could be augmented with color.
  • Could render to other image formats like PNG or SVG
  • account for a user-selected seed in the scenario launch parameters dialog

Demos

Scenario selection preview

image

Command-line map rendering

~/github/swarm$ scripts/play.sh map data/scenarios/Challenges/ice-cream.yaml
              
              
              
              
           OO 
▒▒▒ ▒▒▒▒  OOOO
┌─┐▒┌──┐  MMMM
│B   V6│  \ZZ/
└──────┘   \/ 

and

stack run -- map data/scenarios/Challenges/hackman.yaml
▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
▒••••••••••▒••••••••••▒
▒o▒▒▒•▒▒▒▒•▒•▒▒▒▒•▒▒▒o▒
▒•▒▒▒•▒▒▒▒•▒•▒▒▒▒•▒▒▒•▒
▒•••••••••••••••••••••▒
▒•▒▒▒•▒•▒▒▒▒▒▒▒•▒•▒▒▒•▒
▒•••••▒••••▒••••▒•••••▒
▒▒▒▒▒•▒▒▒▒ ▒ ▒▒▒▒•▒▒▒▒▒
    ▒•▒         ▒•▒    
▒▒▒▒▒•▒ ┌──=──┐ ▒•▒▒▒▒▒
     •  │     │  •     
▒▒▒▒▒•▒ └─────┘ ▒•▒▒▒▒▒
    ▒•▒         ▒•▒    
▒▒▒▒▒•▒ ▒▒▒▒▒▒▒ ▒•▒▒▒▒▒
▒••••••••••▒••••••••••▒
▒•▒▒▒•▒▒▒▒•▒•▒▒▒▒•▒▒▒•▒
▒o••▒•••••••••••••▒••o▒
▒▒▒•▒•▒•▒▒▒▒▒▒▒•▒•▒•▒▒▒
▒•••••▒••••▒••••▒•••••▒
▒•▒▒▒▒▒▒▒▒•▒•▒▒▒▒▒▒▒▒•▒
▒•••••••••••••••••••••▒
▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒

@kostmo kostmo force-pushed the feature/render-map-offline branch 2 times, most recently from d109f9b to 5d13695 Compare September 12, 2023 07:41
@kostmo kostmo force-pushed the feature/render-map-offline branch 2 times, most recently from 923c9e5 to 6fbffcc Compare September 12, 2023 16:58
@kostmo kostmo changed the title [WIP] Render map rectangle to file [WIP] Render map preview on scenario selection screen Sep 12, 2023
@kostmo kostmo force-pushed the feature/render-map-offline branch 6 times, most recently from 9911189 to 4c466dc Compare September 13, 2023 19:53
@kostmo kostmo changed the title [WIP] Render map preview on scenario selection screen Render map preview on scenario selection screen Sep 13, 2023
@kostmo kostmo marked this pull request as ready for review September 13, 2023 19:57
@kostmo kostmo requested review from byorgey and xsebek September 13, 2023 19:57
Copy link
Member

@xsebek xsebek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! 👍 I have a few nitpicks and questions, but overall I like the improvements and the refactoring. 🙂

I can look into terminal color output - there was a library for pretty Doc, but I think it only had basic colors.

@kostmo kostmo force-pushed the feature/render-map-offline branch from 14ea605 to 4fc25c8 Compare September 14, 2023 18:16
@byorgey
Copy link
Member

byorgey commented Sep 14, 2023

When I do stack run -- map data/scenarios/classic.yaml I get no output. Do you know what's going on there?

@kostmo kostmo force-pushed the feature/render-map-offline branch from 4fc25c8 to fbb80b0 Compare September 15, 2023 04:36
@kostmo
Copy link
Member Author

kostmo commented Sep 15, 2023

When I do stack run -- map data/scenarios/classic.yaml I get no output. Do you know what's going on there?

Yep, had a size zero area of the map. Added a default for this case now.

@kostmo kostmo added the merge me Trigger the merge process of the Pull request. label Sep 15, 2023
@mergify mergify bot merged commit a9ded58 into main Sep 15, 2023
@mergify mergify bot deleted the feature/render-map-offline branch September 15, 2023 06:11
@kostmo kostmo added the CHANGELOG Once merged, this PR should be highlighted in the changelog for the next release. label Sep 15, 2023
mergify bot pushed a commit that referenced this pull request Sep 10, 2024
Fixes the lag issue noted in #1515.

# Demo

1. First, launch a toplevel scenario:
    ```
    scripts/play.sh -i data/scenarios/blank.yaml
    ```
2. Then use <kbd>Ctrl</kbd>+<kbd>q</kbd> to quit to the scenario selection menu.
3. Notice when using up-arrow to select the "Classic" and "Creative" scenarios, there is a delay as the preview is computed for the first time.
4. Finally, when subsequently selecting back and forth between the two again, notice that the lag is gone, as the cache is being used.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CHANGELOG Once merged, this PR should be highlighted in the changelog for the next release. merge me Trigger the merge process of the Pull request.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Display world preview under description when selecting a scenario from the New Game menu
3 participants