diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..a54b5d8 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,144 @@ +name: 🚀 Release + +on: + workflow_dispatch: + push: + tags: + - "v*" + +defaults: + run: + shell: bash + +jobs: + generate_changelog: + name: 📜 Generate Changelog + runs-on: ubuntu-latest + outputs: + release_body: ${{ steps.git-cliff.outputs.content }} + steps: + - name: ⬇️ Checkout + uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - name: 📠 Calculate Git Cliff Args + id: cliff-args + run: | + if [ "${{ github.event_name }}" = "push" ]; then + echo "args=--latest" >> $GITHUB_OUTPUT + else + echo "args=--unreleased" >> $GITHUB_OUTPUT + fi + + - name: 📜 Generate Changelog + uses: orhun/git-cliff-action@v2 + id: git-cliff + with: + args: -vv --strip all ${{ steps.cliff-args.outputs.args }} + + - name: 📝 Set Job Summary + run: | + echo "${{ steps.git-cliff.outputs.content }}" >> $GITHUB_STEP_SUMMARY + + build_release: + name: 🔨 Build + runs-on: ${{ matrix.config.os }} + continue-on-error: true + outputs: + release_version: ${{ env.RELEASE_VERSION }} + strategy: + fail-fast: false + matrix: + config: + - { os: ubuntu-latest, target: "x86_64-unknown-linux-gnu" } + - { os: ubuntu-latest, target: "aarch64-unknown-linux-gnu" } + - { os: macos-latest, target: "x86_64-apple-darwin" } + - { os: macos-latest, target: "aarch64-apple-darwin" } + - { os: windows-latest, target: "x86_64-pc-windows-msvc" } + + steps: + - name: 📠 Calculate Release Version + run: | + if [ "${{ github.event_name }}" = "workflow_dispatch" -o "${{ github.event_name }}" = "schedule" ]; then + echo "RELEASE_VERSION=nightly-$(date '+%Y-%m-%d')" >> $GITHUB_ENV + else + echo "RELEASE_VERSION=${{ github.ref_name }}" >> $GITHUB_ENV + fi + + - name: ⬇️ Checkout + uses: actions/checkout@v3 + + - name: 🦀 Setup Rust + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + override: true + profile: minimal + target: ${{ matrix.config.target }} + + - name: 🔨 Build + uses: actions-rs/cargo@v1 + with: + command: build + args: --release --locked --target ${{ matrix.config.target }} + use-cross: true + + - name: ⚙️ Prepare artifacts [Windows] + shell: bash + if: matrix.config.os == 'windows-latest' + run: | + release_dir="astratomic-${{ env.RELEASE_VERSION }}" + artifact_path="astratomic-${{ env.RELEASE_VERSION }}-${{ matrix.config.target }}.zip" + echo "ARTIFACT_PATH=$artifact_path" >> $GITHUB_ENV + mkdir $release_dir + cp target/${{ matrix.config.target }}/release/astratomic.exe $release_dir/ + cp -R assets/ $release_dir/ + cp LICENSE $release_dir/ + 7z a -tzip $artifact_path $release_dir/ + + - name: ⚙️ Prepare artifacts [Unix] + shell: bash + if: matrix.config.os != 'windows-latest' + run: | + release_dir="astratomic-${{ env.RELEASE_VERSION }}" + artifact_path="astratomic-${{ env.RELEASE_VERSION }}-${{ matrix.config.target }}.tar.gz" + echo "ARTIFACT_PATH=$artifact_path" >> $GITHUB_ENV + mkdir $release_dir + cp target/${{ matrix.config.target }}/release/astratomic $release_dir/ + cp -R assets $release_dir + cp LICENSE $release_dir + tar -czvf $artifact_path $release_dir/ + + - name: ⏫️ Upload artifacts + uses: actions/upload-artifact@v2 + with: + name: ${{ env.ARTIFACT_PATH }} + path: ${{ env.ARTIFACT_PATH }} + if-no-files-found: error + + publish_release: + name: 🚀 Publish + needs: + - generate_changelog + - build_release + runs-on: ubuntu-latest + + steps: + - name: ⬇️ Download Artifacts + uses: actions/download-artifact@v2 + + - name: 🔒 Generate Checksums + run: for file in astratomic-*/astratomic-*; do openssl dgst -sha256 -r "$file" | awk '{print $1}' > "${file}.sha256"; done + + - name: 🚀 Publish Release + uses: svenstaro/upload-release-action@v2 + with: + release_name: ${{ needs.build_release.outputs.release_version }} + file: astratomic-*/astratomic-* + file_glob: true + overwrite: true + prerelease: ${{ github.event_name != 'push' }} + body: ${{ needs.generate_changelog.outputs.release_body }} + tag: ${{ needs.build_release.outputs.release_version }} + repo_token: ${{ secrets.GITHUB_TOKEN }} diff --git a/src/actors.rs b/src/actors.rs index 75e481f..6367931 100644 --- a/src/actors.rs +++ b/src/actors.rs @@ -1,4 +1,3 @@ -use crate::atom::State; use crate::prelude::*; #[derive(Component, Clone, Copy)] diff --git a/src/chunk.rs b/src/chunk.rs index 0f8734e..1b965f6 100644 --- a/src/chunk.rs +++ b/src/chunk.rs @@ -19,7 +19,7 @@ impl Chunk { Ordering::Less => {} _ => { for atom in &mut atoms { - atom.state = crate::prelude::State::Powder; + atom.state = State::Powder; atom.color = [ (230 + rand::thread_rng().gen_range(-20_i16..20_i16)) as u8, (197 + rand::thread_rng().gen_range(-20_i16..20_i16)) as u8, @@ -50,6 +50,7 @@ impl Chunk { ) } + //This uses the CPU and is not used in-game anymore pub fn update_image_positions(&self, image: &mut Image, positions: &HashSet) { for pos in positions { let pixel_index = (pos.y as usize * CHUNK_LENGHT + pos.x as usize) * 4; diff --git a/src/chunk_group.rs b/src/chunk_group.rs index 6594d3d..9f8d81f 100644 --- a/src/chunk_group.rs +++ b/src/chunk_group.rs @@ -7,7 +7,7 @@ pub struct ChunkGroup<'a> { pub center: &'a mut [Atom; CHUNK_LEN], pub corners: ChunkCorners<'a>, pub sides: ChunkSides<'a>, - // The pos of the center chunk on the chunk manager vec + /// Position of the center chunk. pub center_pos: IVec2, } diff --git a/src/consts.rs b/src/consts.rs index 33f9b56..fd4c3f4 100644 --- a/src/consts.rs +++ b/src/consts.rs @@ -1,3 +1,4 @@ +// Chunk Lenght consts // Chunk lenght MUST be divisible by 4 pub const CHUNK_LENGHT: usize = 64; pub const HALF_CHUNK_LENGHT: usize = CHUNK_LENGHT / 2; @@ -6,12 +7,30 @@ pub const CHUNK_LEN: usize = CHUNK_LENGHT * CHUNK_LENGHT; pub const HALF_CHUNK_LEN: usize = CHUNK_LEN / 2; pub const QUARTER_CHUNK_LEN: usize = CHUNK_LEN / 4; +// Actor consts + pub const UP_WALK_HEIGHT: usize = 3; pub const DOWN_WALK_HEIGHT: usize = 6; + +// Player consts +pub const FUEL_MAX: f32 = 50.; +pub const FUEL_REGEN: f32 = 1.; +pub const FUEL_COMSUMPTON: f32 = 0.48; +pub const JETPACK_FORCE: f32 = 1.5; +pub const JETPACK_MAX: f32 = 3.; + +pub const JUMP_MAG: f32 = 13.; +pub const RUN_SPEED: f32 = 5.; + +pub const TOOL_DISTANCE: f32 = 32.; +pub const TOOL_RANGE: f32 = 12.; + +// Engine consts pub const ATOM_SIZE: usize = 3; -pub const _CAMERA_SPEED: f32 = 10.; pub const GRAVITY: u8 = 1; pub const TERM_VEL: u8 = 10; pub const FRAMES_SLEEP: u8 = 4; pub const CHUNKS_WIDTH: usize = 8; pub const CHUNKS_HEIGHT: usize = 6; + +pub const _CAMERA_SPEED: f32 = 10.; diff --git a/src/main.rs b/src/main.rs index d7949df..9a978a1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -12,9 +12,10 @@ mod geom_tools; mod manager_api; mod player; mod prelude { + pub use crate::atom::State; pub use crate::{ - actors::*, animation::*, atom::State, atom::*, chunk::*, chunk_group::*, chunk_manager::*, - consts::*, debug::*, geom_tools::*, manager_api::*, player::*, + actors::*, animation::*, atom::*, chunk::*, chunk_group::*, chunk_manager::*, consts::*, + debug::*, geom_tools::*, manager_api::*, player::*, }; pub use bevy::math::{ivec2, ivec3, uvec2, uvec3, vec2, vec3}; pub use bevy::prelude::*; diff --git a/src/player.rs b/src/player.rs index 44020e7..f63a596 100644 --- a/src/player.rs +++ b/src/player.rs @@ -23,15 +23,6 @@ pub struct Tool { atoms: Vec, } -// Player consts -const FUEL_MAX: f32 = 50.; -const FUEL_REGEN: f32 = 1.; -const FUEL_COMSUMPTON: f32 = 0.48; -const JUMP_MAG: f32 = 13.; -const JETPACK_FORCE: f32 = 1.5; -const JETPACK_MAX: f32 = 3.; -const RUN_SPEED: f32 = 5.; - pub fn player_setup( mut commands: Commands, asset_server: Res, @@ -39,6 +30,7 @@ pub fn player_setup( mut chunk_manager: Query<&mut ChunkManager>, ) { let mut chunk_manager = chunk_manager.single_mut(); + let player_actor = Actor { height: 17, width: 10, @@ -101,12 +93,8 @@ pub fn update_player( let (mut actor, mut player, mut textatlas_sprite, mut anim_idxs) = player.single_mut(); let (mut tool_transform, tool_gtransform, mut tool_sprite, mut tool) = tool.single_mut(); let (mouse, keys) = input; - let mut chunk_manager = chunk_manager.single_mut(); - let on_ground = on_ground(&chunk_manager, &actor); - let mut just_jumped = false; - // Gravity if actor.vel.y < TERM_VEL as f32 { actor.vel.y += 1.; @@ -117,11 +105,13 @@ pub fn update_player( actor.vel.x = x * RUN_SPEED; // Refuel + let on_ground = on_ground(&chunk_manager, &actor); if on_ground { player.fuel = (player.fuel + FUEL_REGEN).clamp(0., Player::default().fuel); } // Jump and Jetpack + let mut just_jumped = false; if keys.just_pressed(KeyCode::Space) { if on_ground { actor.vel.y -= JUMP_MAG; @@ -179,20 +169,16 @@ pub fn update_player( tool_transform.translation.x = tool_transform.translation.x.abs() * (flip_bool as i8 * 2 - 1) as f32; - const TOOL_DISTANCE: f32 = 32.; - const TOOL_RANGE: f32 = 12.; - + //Tool shooting and sucking atoms let mut center_vec_y_flipped = center_vec; center_vec_y_flipped.y *= -1.; center_vec_y_flipped /= ATOM_SIZE as f32; let tool_slope = Vec2::new(angle.cos(), -angle.sin()); - let tool_front = center_vec_y_flipped + tool_slope * 8.; - let bound_slope = Vec2::new((angle + std::f32::consts::FRAC_PI_2).cos(), -(angle).cos()); + let tool_front = center_vec_y_flipped + tool_slope * 8.; let mut pos_to_update = vec![]; - if mouse.pressed(MouseButton::Right) { let new_tool_front = tool_front + tool_slope * 6.; for i in 0..3 {