Compare commits

...

2 commits

4 changed files with 36 additions and 71 deletions

View file

@ -35,11 +35,8 @@ logic mostly like https://git.crispypin.cc/CrispyPin/marble
``` ```
- assets/ - assets/
- levels/ - levels/
- 01_intro/ - chapter_01.json
- 01_output.json - chapter_02.json
- 02_cat.json
- 02_lists/
- 02_parse.json
- sandbox.json - sandbox.json
- user/ - user/
- solutions/ - solutions/
@ -52,46 +49,7 @@ logic mostly like https://git.crispypin.cc/CrispyPin/marble
- blueprints - blueprints
- blueprint_0.json - 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 ## levels
### intro, basic mechanics ### intro, basic mechanics

BIN
assets/exit.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 152 B

View file

@ -675,23 +675,27 @@ impl Editor {
); );
if self.exit_menu { if self.exit_menu {
if simple_button(d, 5, 5, 75, 30) { if simple_button(d, 4, 4, 32, 32) {
self.exit_menu = false;
}
d.draw_text("cancel", 10, 10, 20, Color::WHITE);
if simple_button(d, 85, 5, 60, 30) {
self.exit_state = ExitState::ExitAndSave; self.exit_state = ExitState::ExitAndSave;
} }
d.draw_text("exit", 90, 10, 20, Color::WHITE); self.tooltip.add(4, 4, 32, 32, "exit");
draw_scaled_texture(d, textures.get("exit"), 4, 4, 2.);
if simple_button(d, 38, 4, 32, 32) {
self.exit_menu = false;
}
draw_scaled_texture(d, textures.get("cancel"), 38, 4, 2.);
self.tooltip.add(38, 4, 32, 32, "cancel");
} else { } else {
if simple_button(d, 5, 5, 75, 30) { if simple_button(d, 4, 4, 32, 32) {
self.exit_menu = true; self.exit_menu = true;
} }
d.draw_text("exit", 10, 10, 20, Color::WHITE); self.tooltip.add(4, 4, 32, 32, "exit");
if simple_button(d, 85, 5, 60, 30) { draw_scaled_texture(d, textures.get("exit"), 4, 4, 2.);
if simple_button(d, 38, 4, 32, 32) {
self.exit_state = ExitState::Save; self.exit_state = ExitState::Save;
} }
d.draw_text("save", 90, 10, 20, Color::WHITE); draw_scaled_texture(d, textures.get("save"), 38, 4, 2.);
self.tooltip.add(38, 4, 32, 32, "save");
} }
if self.sim_state == SimState::Editing { if self.sim_state == SimState::Editing {

View file

@ -40,7 +40,7 @@ struct Game {
#[derive(Debug)] #[derive(Debug)]
enum LevelListEntry { enum LevelListEntry {
Level(Level), Level(Level),
ChapterTitle(String), Chapter(String, usize),
} }
fn main() { fn main() {
@ -128,43 +128,46 @@ impl Game {
let mouse_pos = d.get_mouse_position(); let mouse_pos = d.get_mouse_position();
let scroll_delta = d.get_mouse_wheel_move(); 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 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; 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; self.level_scroll -= 1;
} }
} }
for (i, level) in self.levels[self.level_scroll..].iter().enumerate() { for (row_index, level_index) in (self.level_scroll..self.levels.len()).enumerate() {
let level_entry_height = 65; let level = &mut self.levels[level_index];
let index = i + self.level_scroll; let y = 10 + row_index as i32 * ENTRY_SPACING;
let y = 10 + i as i32 * level_entry_height;
let bounds = Rectangle { let bounds = Rectangle {
x: 5., x: 5.,
y: y as f32 - 5., y: y as f32 - 5.,
width: level_list_width as f32 - 10., 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 { match level {
LevelListEntry::ChapterTitle(title) => { LevelListEntry::Chapter(title, level_count) => {
d.draw_rectangle_rec(bounds, BG_DARK); d.draw_rectangle_rec(bounds, BG_DARK);
d.draw_text(title, 10, y, 30, FG_CHAPTER_TITLE); 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) => { LevelListEntry::Level(level) => {
if clicked if clicked_this && self.selected_level != level_index {
&& bounds.check_collision_point_rec(mouse_pos)
&& self.selected_level != index
{
self.editing_solution_name = false; self.editing_solution_name = false;
self.selected_level = index; self.selected_level = level_index;
self.selected_solution = 0; self.selected_solution = 0;
// select the last solution of the level, if there is one // select the last solution of the level, if there is one
if let Some(solutions) = self.solutions.get(level.id()) { if let Some(solutions) = self.solutions.get(level.id()) {
self.selected_solution = solutions.len().saturating_sub(1); 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; let mut title_color = Color::WHITE;
if let Some(solutions) = self.solutions.get(level.id()) { if let Some(solutions) = self.solutions.get(level.id()) {
@ -313,7 +316,7 @@ fn get_levels() -> Vec<LevelListEntry> {
let mut levels = Vec::new(); let mut levels = Vec::new();
for c in chapters { 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.extend(c.levels.into_iter().map(LevelListEntry::Level));
} }
levels levels