13 Commits
v0.1.0 ... main

Author SHA1 Message Date
ff530cc8ec re-enable linux build
All checks were successful
build / Create Release (push) Successful in 4s
build / publish (zip, x86_64-pc-windows-msvc, windows-2022, windows-x86_64) (push) Successful in 9m7s
build / publish (tar.gz, x86_64-unknown-linux-gnu, ubuntu-latest, linux-x86_64) (push) Successful in 17m16s
2024-07-13 12:57:50 +02:00
0cd8097beb name that release 2024-07-12 22:01:12 +02:00
4693fbbed3 more name
All checks were successful
build / Create Release (push) Successful in 4s
build / publish (zip, x86_64-pc-windows-msvc, windows-2022, windows-x86_64) (push) Successful in 10m12s
2024-07-12 21:49:08 +02:00
53559a91b1 ref_name 2024-07-12 21:48:43 +02:00
5d9750b47e draft
Some checks failed
build / Create Release (push) Successful in 4s
build / publish (zip, x86_64-pc-windows-msvc, windows-2022, windows-x86_64) (push) Has been cancelled
2024-07-12 21:47:58 +02:00
7522050a80 dump context 2024-07-12 21:46:48 +02:00
336bc15690 change artifact filename
Some checks failed
build / Create Release (push) Successful in 4s
build / publish (zip, x86_64-pc-windows-msvc, windows-2022, windows-x86_64) (push) Failing after 7m54s
build / publish (tar.gz, x86_64-unknown-linux-gnu, ubuntu-latest, linux-x86_64) (push) Failing after 16m55s
2024-07-12 21:23:07 +02:00
1a6589e6b8 cleanup pass 2024-07-12 21:12:17 +02:00
3666b80dca save on exit
Some checks failed
build / Create Release (push) Successful in 5s
build / publish (zip, x86_64-pc-windows-msvc, windows-2022, windows-x86_64) (push) Successful in 7m50s
build / publish (tar.gz, x86_64-unknown-linux-gnu, ubuntu-latest, linux-x86_64) (push) Failing after 13m55s
2024-07-12 21:06:39 +02:00
e32e790ad1 remove scroll log 2024-07-12 16:40:18 +02:00
e863b89e09 no need to store save 2024-07-12 16:39:26 +02:00
222c7e9f96 crude save/load system 2024-07-12 16:33:46 +02:00
bedc46f901 fix camera 2024-07-12 14:49:15 +02:00
9 changed files with 97 additions and 24 deletions

View File

@@ -21,8 +21,8 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITEA_TOKEN }} GITHUB_TOKEN: ${{ secrets.GITEA_TOKEN }}
with: with:
tag_name: ${{ gitea.ref }} tag_name: ${{ gitea.ref }}
release_name: "${{ gitea.event.repository.name }}-${{ gitea.ref }}" release_name: "${{ gitea.event.repository.name }} ${{ gitea.ref_name }}"
draft: false draft: true
prerelease: false prerelease: false
publish: publish:
name: publish name: publish
@@ -42,6 +42,11 @@ jobs:
name: x86_64-unknown-linux-gnu name: x86_64-unknown-linux-gnu
runs-on: ${{ matrix.platform }} runs-on: ${{ matrix.platform }}
steps: steps:
- name: Dump context
run: |
echo "$env:GITEA_CONTEXT"
env:
GITEA_CONTEXT: ${{ toJson(gitea) }}
- name: Checkout code - name: Checkout code
uses: actions/checkout@v4 uses: actions/checkout@v4
- name: Install alsa and udev - name: Install alsa and udev
@@ -69,14 +74,15 @@ jobs:
if: matrix.platform == 'windows-2022' if: matrix.platform == 'windows-2022'
run: | run: |
cp -r -fo assets $env:GITHUB_WORKSPACE/output/ cp -r -fo assets $env:GITHUB_WORKSPACE/output/
Compress-Archive -Force -Path $env:GITHUB_WORKSPACE/output/* -DestinationPath $env:GITHUB_WORKSPACE/${{ gitea.event.repository.name }}_${{ matrix.name }}.${{ matrix.archive }} Compress-Archive -Force -Path $env:GITHUB_WORKSPACE/output/* -DestinationPath $env:GITHUB_WORKSPACE/${{ gitea.event.repository.name }}-${{ gitea.ref_name }}-${{ matrix.name }}.${{ matrix.archive }}
- name: Collect linux/macos artifacts - name: Collect linux/macos artifacts
if: matrix.platform != 'windows-2022' if: matrix.platform != 'windows-2022'
run: | run: |
cp -rf assets ${GITHUB_WORKSPACE}/output/ cp -rf assets ${GITHUB_WORKSPACE}/output/
tar -czvf ${GITHUB_WORKSPACE}/${{ gitea.event.repository.name }}_${{ matrix.name }}.${{ matrix.archive }} -C ${GITHUB_WORKSPACE}/output/ . tar -czvf ${GITHUB_WORKSPACE}/${{ gitea.event.repository.name }}-${{ gitea.ref_name }}-${{ matrix.name }}.${{ matrix.archive }} -C ${GITHUB_WORKSPACE}/output/ .
- name: Upload artifacts - name: Upload artifacts
uses: akkuman/gitea-release-action@v1 uses: akkuman/gitea-release-action@v1
with: with:
allowUpdates: true draft: false
files: "${{ gitea.event.repository.name }}_${{ matrix.name }}.${{ matrix.archive }}" name: "${{ gitea.event.repository.name }} ${{ gitea.ref_name }}"
files: "${{ gitea.event.repository.name }}-${{ gitea.ref_name }}-${{ matrix.name }}.${{ matrix.archive }}"

3
.gitignore vendored
View File

@@ -1,3 +1,4 @@
/target /target
.vscode .vscode
/output /output
*.sav

3
Cargo.lock generated
View File

@@ -2637,7 +2637,7 @@ dependencies = [
[[package]] [[package]]
name = "minesweeper" name = "minesweeper"
version = "0.1.0" version = "0.1.1"
dependencies = [ dependencies = [
"bevy", "bevy",
"bevy_ecs_tilemap", "bevy_ecs_tilemap",
@@ -2646,6 +2646,7 @@ dependencies = [
"noise", "noise",
"rand", "rand",
"rand_chacha", "rand_chacha",
"serde",
] ]
[[package]] [[package]]

View File

@@ -1,6 +1,6 @@
[package] [package]
name = "minesweeper" name = "minesweeper"
version = "0.1.0" version = "0.1.1"
edition = "2021" edition = "2021"
# Enable max optimizations for dependencies, but not for our code: # Enable max optimizations for dependencies, but not for our code:
@@ -31,3 +31,4 @@ imageproc = "0.25.0"
noise = { version = "0.9.0", features = ["images"] } noise = { version = "0.9.0", features = ["images"] }
rand = "0.8.5" rand = "0.8.5"
rand_chacha = "0.3.1" rand_chacha = "0.3.1"
serde = { version = "1.0.204", features = ["derive"] }

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 976 B

View File

@@ -20,7 +20,6 @@ pub fn mouse_zoom(
for mut ortho in query.iter_mut() { for mut ortho in query.iter_mut() {
ortho.scale -= scroll; ortho.scale -= scroll;
ortho.scale = ortho.scale.clamp(0.5, 1.0); ortho.scale = ortho.scale.clamp(0.5, 1.0);
dbg!(ortho.scale);
} }
} }
MouseScrollUnit::Pixel => {} MouseScrollUnit::Pixel => {}

View File

@@ -1,26 +1,27 @@
use bevy::prelude::*; use bevy::prelude::*;
use bevy_ecs_tilemap::prelude::*; use bevy_ecs_tilemap::prelude::*;
use serde::{Deserialize, Serialize};
use super::camera; use super::camera;
pub struct GridPlugin; pub struct GridPlugin;
#[derive(Debug, Component, Reflect)] #[derive(Debug, Component, Reflect, Serialize, Deserialize)]
#[reflect(Component)] #[reflect(Component)]
pub struct Tile { pub struct Tile {
pub x: isize, pub x: isize,
pub y: isize, pub y: isize,
} }
#[derive(Debug, Component, Reflect)] #[derive(Debug, Component, Reflect, Serialize, Deserialize)]
#[reflect(Component)] #[reflect(Component)]
pub struct Flag; pub struct Flag;
#[derive(Debug, Component, Reflect)] #[derive(Debug, Component, Reflect, Serialize, Deserialize)]
#[reflect(Component)] #[reflect(Component)]
pub struct Revealed; pub struct Revealed;
#[derive(Debug, Component, Reflect, Copy, Clone, PartialEq, Eq)] #[derive(Debug, Component, Reflect, Serialize, Deserialize, Copy, Clone, PartialEq, Eq)]
#[reflect(Component)] #[reflect(Component)]
pub enum TileType { pub enum TileType {
Empty, Empty,
@@ -51,7 +52,8 @@ impl From<i32> for TileType {
} }
} }
#[derive(Component)] #[derive(Debug, Component, Reflect, Serialize, Deserialize)]
#[reflect(Component)]
pub struct TileOffset { pub struct TileOffset {
pub translation: Vec3, pub translation: Vec3,
pub x: isize, pub x: isize,

View File

@@ -3,16 +3,18 @@
mod utils; mod utils;
use bevy::prelude::*;
use bevy::window::WindowResolution; use bevy::window::WindowResolution;
use bevy::{prelude::*, window::WindowCloseRequested};
use helpers::grid::{Flag, GridPlugin, Revealed, Tile, TileClickEvent, TileOffset, TileType}; use helpers::grid::{Flag, GridPlugin, Revealed, Tile, TileClickEvent, TileOffset, TileType};
use serde::{Deserialize, Serialize};
mod helpers; mod helpers;
#[derive(Deref, Resource)] #[derive(Deref, Resource)]
pub struct PlayerAlive(bool); pub struct PlayerAlive(bool);
#[derive(Deref, Resource)] #[derive(Deref, Resource, Reflect, Serialize, Deserialize)]
#[reflect(Resource)]
pub struct Score(usize); pub struct Score(usize);
impl FromWorld for PlayerAlive { impl FromWorld for PlayerAlive {
@@ -33,13 +35,15 @@ impl FromWorld for FontHandle {
} }
fn setup_camera(mut commands: Commands) { fn setup_camera(mut commands: Commands) {
// 0x0 = Center
let translation = Vec3 { let translation = Vec3 {
x: -(1280.0 / 2.0), x: -(1280.0 / 2.0),
y: -(720.0 / 2.0), y: -(720.0 / 2.0),
z: 1.0, z: 1.0,
}; };
let offset_x = (translation.x / 16.0) as isize;
let offset_y = (translation.y / 16.0) as isize;
commands.spawn(( commands.spawn((
Camera2dBundle { Camera2dBundle {
projection: OrthographicProjection { projection: OrthographicProjection {
@@ -53,14 +57,14 @@ fn setup_camera(mut commands: Commands) {
..Default::default() ..Default::default()
}, },
transform: Transform { transform: Transform {
translation, translation: (translation % 16.0),
..default() ..default()
}, },
..default() ..default()
}, },
TileOffset { TileOffset {
x: 0, x: offset_x,
y: 0, y: offset_y,
translation, translation,
}, },
)); ));
@@ -235,6 +239,62 @@ fn get_tile(x: isize, y: isize) -> TileType {
surrounding.into() surrounding.into()
} }
fn load_game(mut commands: Commands, asset_server: Res<AssetServer>) {
// "Spawning" a scene bundle creates a new entity and spawns new instances
// of the given scene's entities as children of that entity.
commands.spawn(DynamicSceneBundle {
// Scenes are loaded just like any other asset.
scene: asset_server.load("save.sav"),
..default()
});
}
fn save_on_exit(
world: &World,
type_registry: Res<AppTypeRegistry>,
mut close_request: EventReader<WindowCloseRequested>,
) {
for _ in close_request.read() {
println!("Saving");
let type_registry = type_registry.read();
let dscene = DynamicSceneBuilder::from_world(world)
.deny_all()
.deny_all_resources()
.allow::<Tile>()
.allow::<Flag>()
.allow::<Revealed>()
.allow::<TileType>()
.allow::<Transform>()
.allow::<TileOffset>()
.allow::<OrthographicProjection>()
.allow_resource::<Score>()
.extract_entities(world.iter_entities().filter_map(|entity| {
world.entity(entity.id()).get::<Tile>()?;
Some(entity.id())
}))
// .extract_entities(world.iter_entities().filter_map(|entity| {
// world.entity(entity.id()).get::<TileOffset>()?;
// Some(entity.id())
// }))
.extract_resources()
.build();
let serialized = match dscene.serialize(&type_registry) {
Ok(s) => s,
Err(e) => {
eprintln!("Could not serialize scene: {:?}", e);
return;
}
};
if let Err(e) = std::fs::write("./assets/save.sav", serialized) {
eprintln!("Unable to write save file: {:?}", e);
}
}
}
fn main() { fn main() {
// use imageproc::drawing::Canvas; // use imageproc::drawing::Canvas;
// // prepare an image // // prepare an image
@@ -278,15 +338,18 @@ fn main() {
resolution: WindowResolution::new(1280.0, 720.0), resolution: WindowResolution::new(1280.0, 720.0),
..Default::default() ..Default::default()
}), }),
..default() exit_condition: bevy::window::ExitCondition::OnAllClosed,
close_when_requested: true,
}), }),
// bevy_inspector_egui::quick::WorldInspectorPlugin::new(), // bevy_inspector_egui::quick::WorldInspectorPlugin::new(),
)) ))
.insert_resource(PlayerAlive(true)) .insert_resource(PlayerAlive(true))
.register_type::<Score>()
.register_type::<TileOffset>()
.insert_resource(Score(0)) .insert_resource(Score(0))
.init_resource::<FontHandle>() .init_resource::<FontHandle>()
.add_plugins(GridPlugin) .add_plugins(GridPlugin)
.add_systems(Startup, setup_camera) .add_systems(Startup, (load_game, setup_camera))
.add_systems(Update, tile_clicked) .add_systems(Update, (tile_clicked, save_on_exit))
.run(); .run();
} }