Compare commits
13 Commits
Author | SHA1 | Date | |
---|---|---|---|
ff530cc8ec | |||
0cd8097beb | |||
4693fbbed3 | |||
53559a91b1 | |||
5d9750b47e | |||
7522050a80 | |||
336bc15690 | |||
1a6589e6b8 | |||
3666b80dca | |||
e32e790ad1 | |||
e863b89e09 | |||
222c7e9f96 | |||
bedc46f901 |
@@ -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
3
.gitignore
vendored
@@ -1,3 +1,4 @@
|
|||||||
/target
|
/target
|
||||||
.vscode
|
.vscode
|
||||||
/output
|
/output
|
||||||
|
*.sav
|
3
Cargo.lock
generated
3
Cargo.lock
generated
@@ -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]]
|
||||||
|
@@ -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 |
@@ -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 => {}
|
||||||
|
@@ -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,
|
||||||
|
81
src/main.rs
81
src/main.rs
@@ -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();
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user