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

README should show all levels when entering epic mode #159

Open
olistic opened this issue May 25, 2018 · 8 comments
Open

README should show all levels when entering epic mode #159

olistic opened this issue May 25, 2018 · 8 comments
Labels
good first issue Looking to contribute? Start here! pkg: cli Pertaining to @warriorjs/cli status: claimed Issues that are currently being worked on by someone type: enhancement A potential improvement to something that already exists

Comments

@olistic
Copy link
Owner

olistic commented May 25, 2018

Currently, when entering epic mode the README is frozen in the last level of the tower. When you're trying to fine-tune the score for a level other than the last one, it would be helpful if we had the README for that level available. The proposal is that when entering epic mode, the README is updated with all levels, one following the other.

Example:

# Starbolt - beginner

## Level 1

_You see before yourself a long hallway with stairs at the end. There's nothing in the way._

> **TIP:** Call `warrior.walk()` to walk forward in the Player's `playTurn` method.

### Floor Map

```
╔════════╗
║@      >║
╚════════╝

@ = Starbolt (20 HP)
> = stairs
```

## Level 2

_It's too dark to see anything, but you smell sludge nearby._

> **TIP:** Use `warrior.feel().isEmpty()` to see if there's anything in front of you, and `warrior.attack()` to fight it. Remember, you can only do one action per turn.

### Floor Map

```
╔════════╗
║@   s  >║
╚════════╝

@ = Starbolt (20 HP)
s = Sludge (12 HP)
> = stairs
```

## Level 3

...

## Abilities

### Actions (only one per turn)

- `warrior.attack()`: Attack a unit in the given direction (forward by default) dealing 5 HP of damage.
- `warrior.walk()`: Move one space in the given direction (forward by default).

### Senses

- `warrior.feel()`: Return the adjacent space in the given direction (forward by default).
- `warrior.think()`: Think about your options before choosing an action (`console.log` replacement).

## Next Steps

When you're done editing `Player.js`, run the `warriorjs` command again.
@olistic olistic added pkg: cli Pertaining to @warriorjs/cli type: enhancement A potential improvement to something that already exists labels May 25, 2018
@olistic olistic added the good first issue Looking to contribute? Start here! label Jun 3, 2018
@Supermn54
Copy link

Hello - Is this still open? As a newbie, I'd like to take this on if possible. I've already sifted through the cli package to get a feel for how I'd approach this proposal.

@Supermn54
Copy link

After mapping out all the files/calls, my high level plan would be to add a call that generates an EpicReadme.md file to the async playEpicMode() function. This call would sit before the while loop that plays each level. In addition, I'd have to create a new EpicReadme.md template.

Thoughts?

@olistic
Copy link
Owner Author

olistic commented Jun 12, 2018

Hello @Supermn54, thanks for your interest in the project!

Is this still open? As a newbie, I'd like to take this on if possible.

Sure, I'll mark it as claimed.

After mapping out all the files/calls, my high level plan would be to add a call that generates an EpicReadme.md file to the async playEpicMode() function. This call would sit before the while loop that plays each level. In addition, I'd have to create a new EpicReadme.md template.

If you see, the README is generated when preparing the next level. As you already noticed, this is not enough for the proposed change, we need to generate the README when entering epic mode (to add all the levels to it). However, it's not necessary (nor optimal) to generate it when playing the game. We can generate it when preparing epic mode.

Now, for the template, there's no need to generate another template. Instead of passing a single level to the template, we can pass an array of levels. If not in epic mode, we would just pass a single level inside the array. If in epic mode, we pass all levels. Then, inside the template, we iterate over each level in the array and render the level portion.

If anything is not clear, please let me know!

@Supermn54
Copy link

Thanks @olistic! For some reason, I didn't think the current README template structure supported the requested README outline but now I see how we can simply add loops into each section of the template.

As for updating the prepareEpicMode() function, I was thinking of adding this. generateProfileFiles() and then updating the generateReadmeFile() function with code to create an array of 'data' objects for each level. I'm embarrassed to say that I'm a little stuck in figuring out the false condition for the loop. I'm trying to figure out what would return false if the loop exceeds the number of available levels (without applying a fixed number of levels). Any ideas? If I can get past this, I think I'm ready to start testing and submitting my PR.

@olistic
Copy link
Owner Author

olistic commented Jun 13, 2018

Assuming that you pass a levels array to the template, then you can simply do levels.forEach(level => ...) and render the level partial inside the loop. Take a look at this for an example.

@olistic olistic added the status: claimed Issues that are currently being worked on by someone label Jun 13, 2018
@Supermn54
Copy link

Sorry. I should have been more clear. The issue isn't with the loop in the template. It's with creating the array of levels that are passed to the template. The generateReadmeFile() only passes a single object 'data' to the ejs.render() function. My assumption is that we instead now need to create an array of objects to be passed to the ejs.render() function instead. I'm struggling to figure out the logic to stop the loop from iterating through each level as I create the array. I can give it a fixed value but I imagine you don't want to restrict the number of levels in future towers.

@olistic
Copy link
Owner Author

olistic commented Jun 14, 2018

Ahh, gotcha. For the data object passed to the ejs.render(), we need to replace the level with an array of levels, as you said. And if I understood you correctly, you’re having issues creating that array of level objects. For that, you can use the value of profile.levelNumber, which will be the last level of the profile’s selected tower (and it’s safe to assume that all towers start with level 1). Does that clarify things a bit?

@olistic
Copy link
Owner Author

olistic commented Jun 14, 2018

So basically, when generating the README, we’ll create an array of levels which will have a single element when not in epic mode (the level with the number profile.levelNumber), or the levels from 1 to profile.levelNumber when in epic mode.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Looking to contribute? Start here! pkg: cli Pertaining to @warriorjs/cli status: claimed Issues that are currently being worked on by someone type: enhancement A potential improvement to something that already exists
Projects
None yet
Development

No branches or pull requests

2 participants