show level count for each chapter
This commit is contained in:
parent
42dfe4fac7
commit
8b62aec760
2 changed files with 22 additions and 61 deletions
48
README.md
48
README.md
|
@ -35,11 +35,8 @@ logic mostly like https://git.crispypin.cc/CrispyPin/marble
|
|||
```
|
||||
- assets/
|
||||
- levels/
|
||||
- 01_intro/
|
||||
- 01_output.json
|
||||
- 02_cat.json
|
||||
- 02_lists/
|
||||
- 02_parse.json
|
||||
- chapter_01.json
|
||||
- chapter_02.json
|
||||
- sandbox.json
|
||||
- user/
|
||||
- solutions/
|
||||
|
@ -52,46 +49,7 @@ logic mostly like https://git.crispypin.cc/CrispyPin/marble
|
|||
- blueprints
|
||||
- blueprint_0.json
|
||||
```
|
||||
## formats
|
||||
### level
|
||||
`00_zeroes.json`
|
||||
```json
|
||||
{
|
||||
"id": "output",
|
||||
"sortorder": 5,
|
||||
"name": "Zeroes",
|
||||
"description": "learn how to output data",
|
||||
"init_board": "<optional, serialized board>",
|
||||
"stages": [{
|
||||
"input": [],
|
||||
"output": [0, 0, 0, 0, 0, 0, 0, 0],
|
||||
}]
|
||||
}
|
||||
```
|
||||
### solution
|
||||
`00_zeroes/solution_0.json`
|
||||
```json
|
||||
{
|
||||
"level_id": "00_zeroes",
|
||||
"solution_id": 0,
|
||||
"name": "unnamed 1",
|
||||
"board": "oo\nP*\n|-",
|
||||
"score": {
|
||||
"cycles": 8,
|
||||
"tiles": 6,
|
||||
"area": 6,
|
||||
}
|
||||
}
|
||||
```
|
||||
### blueprint
|
||||
`blueprints/blueprint_0.json`
|
||||
```json
|
||||
{
|
||||
"id": 0,
|
||||
"name": "zero_printer",
|
||||
"board": "o -B I\n> * < \n"
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
## levels
|
||||
### intro, basic mechanics
|
||||
|
|
35
src/main.rs
35
src/main.rs
|
@ -40,7 +40,7 @@ struct Game {
|
|||
#[derive(Debug)]
|
||||
enum LevelListEntry {
|
||||
Level(Level),
|
||||
ChapterTitle(String),
|
||||
Chapter(String, usize),
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
@ -128,43 +128,46 @@ impl Game {
|
|||
let mouse_pos = d.get_mouse_position();
|
||||
let scroll_delta = d.get_mouse_wheel_move();
|
||||
|
||||
const ENTRY_SPACING: i32 = 65;
|
||||
let fit_on_screen = (d.get_screen_height() / ENTRY_SPACING) as usize;
|
||||
let max_scroll = self.levels.len().saturating_sub(fit_on_screen);
|
||||
if mouse_pos.x < level_list_width as f32 {
|
||||
if scroll_delta < 0. && self.level_scroll < self.levels.len().saturating_sub(5) {
|
||||
if scroll_delta < 0. && self.level_scroll < max_scroll {
|
||||
self.level_scroll += 1;
|
||||
} else if scroll_delta > 0. && self.level_scroll > 0 {
|
||||
}
|
||||
if scroll_delta > 0. && self.level_scroll > 0 {
|
||||
self.level_scroll -= 1;
|
||||
}
|
||||
}
|
||||
|
||||
for (i, level) in self.levels[self.level_scroll..].iter().enumerate() {
|
||||
let level_entry_height = 65;
|
||||
let index = i + self.level_scroll;
|
||||
let y = 10 + i as i32 * level_entry_height;
|
||||
for (row_index, level_index) in (self.level_scroll..self.levels.len()).enumerate() {
|
||||
let level = &mut self.levels[level_index];
|
||||
let y = 10 + row_index as i32 * ENTRY_SPACING;
|
||||
let bounds = Rectangle {
|
||||
x: 5.,
|
||||
y: y as f32 - 5.,
|
||||
width: level_list_width as f32 - 10.,
|
||||
height: level_entry_height as f32 - 5.,
|
||||
height: ENTRY_SPACING as f32 - 5.,
|
||||
};
|
||||
let clicked_this = clicked && bounds.check_collision_point_rec(mouse_pos);
|
||||
match level {
|
||||
LevelListEntry::ChapterTitle(title) => {
|
||||
LevelListEntry::Chapter(title, level_count) => {
|
||||
d.draw_rectangle_rec(bounds, BG_DARK);
|
||||
d.draw_text(title, 10, y, 30, FG_CHAPTER_TITLE);
|
||||
let subtitle = format!("{level_count} levels");
|
||||
d.draw_text(&subtitle, 10, y + 30, 20, Color::WHITE);
|
||||
}
|
||||
LevelListEntry::Level(level) => {
|
||||
if clicked
|
||||
&& bounds.check_collision_point_rec(mouse_pos)
|
||||
&& self.selected_level != index
|
||||
{
|
||||
if clicked_this && self.selected_level != level_index {
|
||||
self.editing_solution_name = false;
|
||||
self.selected_level = index;
|
||||
self.selected_level = level_index;
|
||||
self.selected_solution = 0;
|
||||
// select the last solution of the level, if there is one
|
||||
if let Some(solutions) = self.solutions.get(level.id()) {
|
||||
self.selected_solution = solutions.len().saturating_sub(1);
|
||||
}
|
||||
}
|
||||
d.draw_rectangle_rec(bounds, widget_bg(self.selected_level == index));
|
||||
d.draw_rectangle_rec(bounds, widget_bg(self.selected_level == level_index));
|
||||
|
||||
let mut title_color = Color::WHITE;
|
||||
if let Some(solutions) = self.solutions.get(level.id()) {
|
||||
|
@ -313,7 +316,7 @@ fn get_levels() -> Vec<LevelListEntry> {
|
|||
|
||||
let mut levels = Vec::new();
|
||||
for c in chapters {
|
||||
levels.push(LevelListEntry::ChapterTitle(c.title));
|
||||
levels.push(LevelListEntry::Chapter(c.title, c.levels.len()));
|
||||
levels.extend(c.levels.into_iter().map(LevelListEntry::Level));
|
||||
}
|
||||
levels
|
||||
|
|
Loading…
Reference in a new issue