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 }}
|
||||
with:
|
||||
tag_name: ${{ gitea.ref }}
|
||||
release_name: "${{ gitea.event.repository.name }}-${{ gitea.ref }}"
|
||||
draft: false
|
||||
release_name: "${{ gitea.event.repository.name }} ${{ gitea.ref_name }}"
|
||||
draft: true
|
||||
prerelease: false
|
||||
publish:
|
||||
name: publish
|
||||
@@ -42,6 +42,11 @@ jobs:
|
||||
name: x86_64-unknown-linux-gnu
|
||||
runs-on: ${{ matrix.platform }}
|
||||
steps:
|
||||
- name: Dump context
|
||||
run: |
|
||||
echo "$env:GITEA_CONTEXT"
|
||||
env:
|
||||
GITEA_CONTEXT: ${{ toJson(gitea) }}
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
- name: Install alsa and udev
|
||||
@@ -69,14 +74,15 @@ jobs:
|
||||
if: matrix.platform == 'windows-2022'
|
||||
run: |
|
||||
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
|
||||
if: matrix.platform != 'windows-2022'
|
||||
run: |
|
||||
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
|
||||
uses: akkuman/gitea-release-action@v1
|
||||
with:
|
||||
allowUpdates: true
|
||||
files: "${{ gitea.event.repository.name }}_${{ matrix.name }}.${{ matrix.archive }}"
|
||||
draft: false
|
||||
name: "${{ gitea.event.repository.name }} ${{ gitea.ref_name }}"
|
||||
files: "${{ gitea.event.repository.name }}-${{ gitea.ref_name }}-${{ matrix.name }}.${{ matrix.archive }}"
|
||||
|
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,3 +1,4 @@
|
||||
/target
|
||||
.vscode
|
||||
/output
|
||||
*.sav
|
3
Cargo.lock
generated
3
Cargo.lock
generated
@@ -2637,7 +2637,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "minesweeper"
|
||||
version = "0.1.0"
|
||||
version = "0.1.1"
|
||||
dependencies = [
|
||||
"bevy",
|
||||
"bevy_ecs_tilemap",
|
||||
@@ -2646,6 +2646,7 @@ dependencies = [
|
||||
"noise",
|
||||
"rand",
|
||||
"rand_chacha",
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "minesweeper"
|
||||
version = "0.1.0"
|
||||
version = "0.1.1"
|
||||
edition = "2021"
|
||||
|
||||
# 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"] }
|
||||
rand = "0.8.5"
|
||||
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() {
|
||||
ortho.scale -= scroll;
|
||||
ortho.scale = ortho.scale.clamp(0.5, 1.0);
|
||||
dbg!(ortho.scale);
|
||||
}
|
||||
}
|
||||
MouseScrollUnit::Pixel => {}
|
||||
|
@@ -1,26 +1,27 @@
|
||||
use bevy::prelude::*;
|
||||
use bevy_ecs_tilemap::prelude::*;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use super::camera;
|
||||
|
||||
pub struct GridPlugin;
|
||||
|
||||
#[derive(Debug, Component, Reflect)]
|
||||
#[derive(Debug, Component, Reflect, Serialize, Deserialize)]
|
||||
#[reflect(Component)]
|
||||
pub struct Tile {
|
||||
pub x: isize,
|
||||
pub y: isize,
|
||||
}
|
||||
|
||||
#[derive(Debug, Component, Reflect)]
|
||||
#[derive(Debug, Component, Reflect, Serialize, Deserialize)]
|
||||
#[reflect(Component)]
|
||||
pub struct Flag;
|
||||
|
||||
#[derive(Debug, Component, Reflect)]
|
||||
#[derive(Debug, Component, Reflect, Serialize, Deserialize)]
|
||||
#[reflect(Component)]
|
||||
pub struct Revealed;
|
||||
|
||||
#[derive(Debug, Component, Reflect, Copy, Clone, PartialEq, Eq)]
|
||||
#[derive(Debug, Component, Reflect, Serialize, Deserialize, Copy, Clone, PartialEq, Eq)]
|
||||
#[reflect(Component)]
|
||||
pub enum TileType {
|
||||
Empty,
|
||||
@@ -51,7 +52,8 @@ impl From<i32> for TileType {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Component)]
|
||||
#[derive(Debug, Component, Reflect, Serialize, Deserialize)]
|
||||
#[reflect(Component)]
|
||||
pub struct TileOffset {
|
||||
pub translation: Vec3,
|
||||
pub x: isize,
|
||||
|
81
src/main.rs
81
src/main.rs
@@ -3,16 +3,18 @@
|
||||
|
||||
mod utils;
|
||||
|
||||
use bevy::prelude::*;
|
||||
use bevy::window::WindowResolution;
|
||||
use bevy::{prelude::*, window::WindowCloseRequested};
|
||||
use helpers::grid::{Flag, GridPlugin, Revealed, Tile, TileClickEvent, TileOffset, TileType};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
mod helpers;
|
||||
|
||||
#[derive(Deref, Resource)]
|
||||
pub struct PlayerAlive(bool);
|
||||
|
||||
#[derive(Deref, Resource)]
|
||||
#[derive(Deref, Resource, Reflect, Serialize, Deserialize)]
|
||||
#[reflect(Resource)]
|
||||
pub struct Score(usize);
|
||||
|
||||
impl FromWorld for PlayerAlive {
|
||||
@@ -33,13 +35,15 @@ impl FromWorld for FontHandle {
|
||||
}
|
||||
|
||||
fn setup_camera(mut commands: Commands) {
|
||||
// 0x0 = Center
|
||||
let translation = Vec3 {
|
||||
x: -(1280.0 / 2.0),
|
||||
y: -(720.0 / 2.0),
|
||||
z: 1.0,
|
||||
};
|
||||
|
||||
let offset_x = (translation.x / 16.0) as isize;
|
||||
let offset_y = (translation.y / 16.0) as isize;
|
||||
|
||||
commands.spawn((
|
||||
Camera2dBundle {
|
||||
projection: OrthographicProjection {
|
||||
@@ -53,14 +57,14 @@ fn setup_camera(mut commands: Commands) {
|
||||
..Default::default()
|
||||
},
|
||||
transform: Transform {
|
||||
translation,
|
||||
translation: (translation % 16.0),
|
||||
..default()
|
||||
},
|
||||
..default()
|
||||
},
|
||||
TileOffset {
|
||||
x: 0,
|
||||
y: 0,
|
||||
x: offset_x,
|
||||
y: offset_y,
|
||||
translation,
|
||||
},
|
||||
));
|
||||
@@ -235,6 +239,62 @@ fn get_tile(x: isize, y: isize) -> TileType {
|
||||
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() {
|
||||
// use imageproc::drawing::Canvas;
|
||||
// // prepare an image
|
||||
@@ -278,15 +338,18 @@ fn main() {
|
||||
resolution: WindowResolution::new(1280.0, 720.0),
|
||||
..Default::default()
|
||||
}),
|
||||
..default()
|
||||
exit_condition: bevy::window::ExitCondition::OnAllClosed,
|
||||
close_when_requested: true,
|
||||
}),
|
||||
// bevy_inspector_egui::quick::WorldInspectorPlugin::new(),
|
||||
))
|
||||
.insert_resource(PlayerAlive(true))
|
||||
.register_type::<Score>()
|
||||
.register_type::<TileOffset>()
|
||||
.insert_resource(Score(0))
|
||||
.init_resource::<FontHandle>()
|
||||
.add_plugins(GridPlugin)
|
||||
.add_systems(Startup, setup_camera)
|
||||
.add_systems(Update, tile_clicked)
|
||||
.add_systems(Startup, (load_game, setup_camera))
|
||||
.add_systems(Update, (tile_clicked, save_on_exit))
|
||||
.run();
|
||||
}
|
||||
|
Reference in New Issue
Block a user