Compare commits
10 Commits
a48987a81b
...
2616e32674
| Author | SHA1 | Date | |
|---|---|---|---|
| 2616e32674 | |||
| 6f15c9e9aa | |||
| 9db175f066 | |||
| 6afc35924c | |||
| babb74b2f7 | |||
| e3191e6827 | |||
| 992e2f703f | |||
| c1fac3a1f3 | |||
| 3b764baf0b | |||
| 1153342f5e |
140
.github/workflows/ci.yaml
vendored
Normal file
140
.github/workflows/ci.yaml
vendored
Normal file
@@ -0,0 +1,140 @@
|
|||||||
|
name: CI
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [main]
|
||||||
|
pull_request:
|
||||||
|
branches: [main]
|
||||||
|
|
||||||
|
concurrency:
|
||||||
|
group: ${{ github.workflow }}-${{ github.ref || github.run_id }}
|
||||||
|
cancel-in-progress: true
|
||||||
|
|
||||||
|
env:
|
||||||
|
# Reduce compile time and cache size.
|
||||||
|
RUSTFLAGS: -Zshare-generics=y -Zthreads=0
|
||||||
|
RUSTDOCFLAGS: -Zshare-generics=y -Zthreads=0
|
||||||
|
# Use the same Rust toolchain across jobs so they can share a cache.
|
||||||
|
toolchain: nightly-2025-04-03
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
# Run Clippy lints.
|
||||||
|
clippy-lints:
|
||||||
|
name: Clippy lints
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
env:
|
||||||
|
RUSTFLAGS: "-Dwarnings"
|
||||||
|
timeout-minutes: 20
|
||||||
|
steps:
|
||||||
|
- name: Checkout repository
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Install Rust toolchain
|
||||||
|
uses: dtolnay/rust-toolchain@master
|
||||||
|
with:
|
||||||
|
toolchain: ${{ env.toolchain }}
|
||||||
|
components: clippy
|
||||||
|
|
||||||
|
- name: Restore Rust cache
|
||||||
|
id: cache
|
||||||
|
uses: Swatinem/rust-cache@v2
|
||||||
|
with:
|
||||||
|
shared-key: ci
|
||||||
|
save-if: ${{ github.ref == 'refs/heads/main' }}
|
||||||
|
|
||||||
|
- name: Install build dependencies
|
||||||
|
if: steps.cache.outputs.cache-hit != 'true'
|
||||||
|
run: sudo apt-get -y update; sudo apt-get -y install --no-install-recommends libasound2-dev libudev-dev libwayland-dev
|
||||||
|
|
||||||
|
- name: Run Clippy lints
|
||||||
|
run: cargo clippy --locked --workspace --all-targets --profile ci --all-features
|
||||||
|
|
||||||
|
# Run Bevy lints.
|
||||||
|
bevy-lints:
|
||||||
|
name: Bevy lints
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
env:
|
||||||
|
RUSTFLAGS: "-Dwarnings"
|
||||||
|
timeout-minutes: 20
|
||||||
|
steps:
|
||||||
|
- name: Checkout repository
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Install Rust toolchain (plus bevy_lint)
|
||||||
|
uses: TheBevyFlock/bevy_cli/bevy_lint@lint-v0.3.0
|
||||||
|
|
||||||
|
- name: Restore Rust cache
|
||||||
|
id: cache
|
||||||
|
uses: Swatinem/rust-cache@v2
|
||||||
|
with:
|
||||||
|
shared-key: ci
|
||||||
|
save-if: false
|
||||||
|
|
||||||
|
- name: Install build dependencies
|
||||||
|
if: steps.cache.outputs.cache-hit != 'true'
|
||||||
|
run: sudo apt-get -y update; sudo apt-get -y install --no-install-recommends libasound2-dev libudev-dev libwayland-dev
|
||||||
|
|
||||||
|
- name: Run Bevy lints
|
||||||
|
run: bevy_lint --locked --workspace --all-targets --profile ci --all-features
|
||||||
|
|
||||||
|
# Run tests.
|
||||||
|
tests:
|
||||||
|
name: Tests
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
timeout-minutes: 40
|
||||||
|
steps:
|
||||||
|
- name: Checkout repository
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Set up environment
|
||||||
|
run: echo "RUSTFLAGS=${RUSTFLAGS:+$RUSTFLAGS }-Zcodegen-backend=cranelift" >> "${GITHUB_ENV}"
|
||||||
|
|
||||||
|
- name: Install Rust toolchain
|
||||||
|
uses: dtolnay/rust-toolchain@master
|
||||||
|
with:
|
||||||
|
toolchain: ${{ env.toolchain }}
|
||||||
|
components: rustc-codegen-cranelift-preview
|
||||||
|
|
||||||
|
- name: Restore Rust cache
|
||||||
|
uses: Swatinem/rust-cache@v2
|
||||||
|
with:
|
||||||
|
shared-key: test
|
||||||
|
cache-directories: ${{ env.LD_LIBRARY_PATH }}
|
||||||
|
save-if: ${{ github.ref == 'refs/heads/main' }}
|
||||||
|
|
||||||
|
- name: Install build dependencies
|
||||||
|
run: sudo apt-get -y update; sudo apt-get -y install --no-install-recommends libasound2-dev libudev-dev libwayland-dev
|
||||||
|
|
||||||
|
- name: Run tests
|
||||||
|
run: cargo test --locked --workspace --all-targets --profile ci --no-fail-fast
|
||||||
|
|
||||||
|
# Check that the web build compiles.
|
||||||
|
# check-web:
|
||||||
|
# name: Check web
|
||||||
|
# runs-on: ubuntu-latest
|
||||||
|
# env:
|
||||||
|
# RUSTFLAGS: -Zshare-generics=y -Zthreads=0 --cfg getrandom_backend="wasm_js"
|
||||||
|
# timeout-minutes: 20
|
||||||
|
# steps:
|
||||||
|
# - name: Checkout repository
|
||||||
|
# uses: actions/checkout@v4
|
||||||
|
|
||||||
|
# - name: Install Rust toolchain
|
||||||
|
# uses: dtolnay/rust-toolchain@master
|
||||||
|
# with:
|
||||||
|
# toolchain: ${{ env.toolchain }}
|
||||||
|
# targets: wasm32-unknown-unknown
|
||||||
|
|
||||||
|
# - name: Restore Rust cache
|
||||||
|
# id: cache
|
||||||
|
# uses: Swatinem/rust-cache@v2
|
||||||
|
# with:
|
||||||
|
# shared-key: web-ci
|
||||||
|
# save-if: ${{ github.ref == 'refs/heads/main' }}
|
||||||
|
|
||||||
|
# - name: Install build dependencies
|
||||||
|
# if: steps.cache.outputs.cache-hit != 'true'
|
||||||
|
# run: sudo apt-get -y update; sudo apt-get -y install --no-install-recommends libasound2-dev libudev-dev libwayland-dev
|
||||||
|
|
||||||
|
# - name: Check web
|
||||||
|
# run: cargo check --config 'profile.web.inherits="dev"' --profile ci --no-default-features --features "dev web" --target wasm32-unknown-unknown
|
||||||
335
.github/workflows/release.yaml
vendored
Normal file
335
.github/workflows/release.yaml
vendored
Normal file
@@ -0,0 +1,335 @@
|
|||||||
|
name: Release
|
||||||
|
|
||||||
|
on:
|
||||||
|
# Trigger this workflow when a tag is pushed in the format `v1.2.3`.
|
||||||
|
push:
|
||||||
|
tags:
|
||||||
|
# Pattern syntax: <https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#filter-pattern-cheat-sheet>.
|
||||||
|
- "v[0-9]+.[0-9]+.[0-9]+*"
|
||||||
|
# Trigger this workflow manually via workflow dispatch.
|
||||||
|
workflow_dispatch:
|
||||||
|
inputs:
|
||||||
|
version:
|
||||||
|
description: "Version number in the format `v1.2.3`"
|
||||||
|
required: true
|
||||||
|
type: string
|
||||||
|
|
||||||
|
concurrency:
|
||||||
|
group: ${{ github.workflow }}-${{ github.ref || github.run_id }}
|
||||||
|
cancel-in-progress: true
|
||||||
|
|
||||||
|
# Configure the release workflow by editing the following values.
|
||||||
|
env:
|
||||||
|
# The base filename of the binary produced by `cargo build`.
|
||||||
|
cargo_build_binary_name: space-game
|
||||||
|
|
||||||
|
# The path to the assets directory.
|
||||||
|
assets_path: assets
|
||||||
|
|
||||||
|
# Whether to build and package a release for a given target platform.
|
||||||
|
build_for_web: false
|
||||||
|
build_for_linux: false
|
||||||
|
build_for_windows: true
|
||||||
|
build_for_macos: false
|
||||||
|
|
||||||
|
# Whether to upload the packages produced by this workflow to a GitHub release.
|
||||||
|
upload_to_github: true
|
||||||
|
|
||||||
|
# The itch.io project to upload to in the format `user-name/project-name`.
|
||||||
|
# There will be no upload to itch.io if this is commented out.
|
||||||
|
# upload_to_itch: amatsugu/space-game
|
||||||
|
|
||||||
|
############
|
||||||
|
# ADVANCED #
|
||||||
|
############
|
||||||
|
|
||||||
|
# The ID of the app produced by this workflow.
|
||||||
|
# Applies to macOS releases.
|
||||||
|
# Must contain only A-Z, a-z, 0-9, hyphen, and period: <https://developer.apple.com/documentation/bundleresources/information_property_list/cfbundleidentifier>.
|
||||||
|
app_id: amatsugu.space-game
|
||||||
|
|
||||||
|
# The base filename of the binary in the package produced by this workflow.
|
||||||
|
# Applies to Windows, macOS, and Linux releases.
|
||||||
|
# Defaults to `cargo_build_binary_name` if commented out.
|
||||||
|
#app_binary_name: bevy_jam_6
|
||||||
|
|
||||||
|
# The name of the `.zip` or `.dmg` file produced by this workflow.
|
||||||
|
# Defaults to `app_binary_name` if commented out.
|
||||||
|
#app_package_name: bevy-new-2d
|
||||||
|
|
||||||
|
# The display name of the app produced by this workflow.
|
||||||
|
# Applies to macOS releases.
|
||||||
|
# Defaults to `app_package_name` if commented out.
|
||||||
|
app_display_name: space-game
|
||||||
|
|
||||||
|
# The short display name of the app produced by this workflow.
|
||||||
|
# Applies to macOS releases.
|
||||||
|
# Must be 15 or fewer characters: <https://developer.apple.com/documentation/bundleresources/information_property_list/cfbundlename>.
|
||||||
|
# Defaults to `app_display_name` if commented out.
|
||||||
|
#app_short_name: Bevy New 2D
|
||||||
|
|
||||||
|
# Before enabling LFS, please take a look at GitHub's documentation for costs and quota limits:
|
||||||
|
# <https://docs.github.com/en/repositories/working-with-files/managing-large-files/about-storage-and-bandwidth-usage>
|
||||||
|
git_lfs: false
|
||||||
|
|
||||||
|
# Enabling this only helps with consecutive releases to the same tag (and takes up cache storage space).
|
||||||
|
# See: <https://github.com/orgs/community/discussions/27059>.
|
||||||
|
use_github_cache: false
|
||||||
|
|
||||||
|
# Reduce compile time.
|
||||||
|
RUSTFLAGS: -Zshare-generics=y -Zthreads=0
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
# Forward some environment variables as outputs of this job.
|
||||||
|
# This is needed because the `env` context can't be used in the `if:` condition of a job:
|
||||||
|
# <https://docs.github.com/en/actions/learn-github-actions/contexts#context-availability>
|
||||||
|
forward-env:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Do nothing
|
||||||
|
run: "true"
|
||||||
|
outputs:
|
||||||
|
upload_to_itch: ${{ env.upload_to_itch }}
|
||||||
|
|
||||||
|
# Determine the version number for this workflow.
|
||||||
|
get-version:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Determine version number
|
||||||
|
id: tag
|
||||||
|
run: echo "tag=${GITHUB_REF#refs/tags/}" >> "${GITHUB_OUTPUT}"
|
||||||
|
outputs:
|
||||||
|
# Use the input from workflow dispatch, or fall back to the git tag.
|
||||||
|
version: ${{ inputs.version || steps.tag.outputs.tag }}
|
||||||
|
|
||||||
|
# Build and package a release for each platform.
|
||||||
|
build:
|
||||||
|
needs:
|
||||||
|
- get-version
|
||||||
|
env:
|
||||||
|
version: ${{ needs.get-version.outputs.version }}
|
||||||
|
# Avoid rate-limiting. See: <https://github.com/cargo-bins/cargo-binstall/issues/2045>.
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
include:
|
||||||
|
- platform: web
|
||||||
|
targets: wasm32-unknown-unknown
|
||||||
|
package_ext: .zip
|
||||||
|
runner: ubuntu-latest
|
||||||
|
|
||||||
|
- platform: linux
|
||||||
|
targets: x86_64-unknown-linux-gnu
|
||||||
|
package_ext: .zip
|
||||||
|
runner: ubuntu-latest
|
||||||
|
|
||||||
|
- platform: windows
|
||||||
|
targets: x86_64-pc-windows-msvc
|
||||||
|
binary_ext: .exe
|
||||||
|
package_ext: .zip
|
||||||
|
runner: windows-latest
|
||||||
|
|
||||||
|
- platform: macos
|
||||||
|
targets: x86_64-apple-darwin aarch64-apple-darwin
|
||||||
|
app_suffix: .app/Contents/MacOS
|
||||||
|
package_ext: .dmg
|
||||||
|
runner: macos-latest
|
||||||
|
runs-on: ${{ matrix.runner }}
|
||||||
|
permissions:
|
||||||
|
# Required to create a GitHub release: <https://docs.github.com/en/rest/releases/releases#create-a-release>.
|
||||||
|
contents: write
|
||||||
|
defaults:
|
||||||
|
run:
|
||||||
|
shell: bash
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Set up environment
|
||||||
|
run: |
|
||||||
|
# Default values:
|
||||||
|
echo "app_binary_name=${app_binary_name:=${{ env.cargo_build_binary_name }}}" >> "${GITHUB_ENV}"
|
||||||
|
echo "app_package_name=${app_package_name:=${app_binary_name}}" >> "${GITHUB_ENV}"
|
||||||
|
echo "app_display_name=${app_display_name:=${app_package_name}}" >> "${GITHUB_ENV}"
|
||||||
|
echo "app_short_name=${app_short_name:=${app_display_name}}" >> "${GITHUB_ENV}"
|
||||||
|
|
||||||
|
# File paths:
|
||||||
|
echo "app=tmp/app/${app_package_name}"'${{ matrix.app_suffix }}' >> "${GITHUB_ENV}"
|
||||||
|
echo "package=${app_package_name}-"'${{ matrix.platform }}${{ matrix.package_ext }}' >> "${GITHUB_ENV}"
|
||||||
|
|
||||||
|
# macOS environment:
|
||||||
|
if [ '${{ matrix.platform }}' = 'macos' ]; then
|
||||||
|
echo 'MACOSX_DEPLOYMENT_TARGET=11.0' >> "${GITHUB_ENV}" # macOS 11.0 Big Sur is the first version to support universal binaries.
|
||||||
|
echo "SDKROOT=$(xcrun --sdk macosx --show-sdk-path)" >> "${GITHUB_ENV}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check if building for this platform is enabled.
|
||||||
|
echo 'is_platform_enabled=${{
|
||||||
|
(matrix.platform == 'web' && env.build_for_web == 'true') ||
|
||||||
|
(matrix.platform == 'linux' && env.build_for_linux == 'true') ||
|
||||||
|
(matrix.platform == 'windows' && env.build_for_windows == 'true') ||
|
||||||
|
(matrix.platform == 'macos' && env.build_for_macos == 'true')
|
||||||
|
}}' >> "${GITHUB_ENV}"
|
||||||
|
|
||||||
|
- name: Checkout repository
|
||||||
|
if: ${{ env.is_platform_enabled == 'true' }}
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
lfs: ${{ env.git_lfs }}
|
||||||
|
|
||||||
|
- name: Install Rust toolchain
|
||||||
|
if: ${{ env.is_platform_enabled == 'true' }}
|
||||||
|
uses: dtolnay/rust-toolchain@nightly
|
||||||
|
with:
|
||||||
|
targets: ${{ matrix.targets }}
|
||||||
|
|
||||||
|
- name: Restore Rust cache
|
||||||
|
if: ${{ env.is_platform_enabled == 'true' && env.use_github_cache == 'true' }}
|
||||||
|
uses: Swatinem/rust-cache@v2
|
||||||
|
with:
|
||||||
|
shared-key: release
|
||||||
|
save-if: ${{ github.ref == 'refs/heads/main' }}
|
||||||
|
|
||||||
|
- name: Install build dependencies (Linux)
|
||||||
|
if: ${{ env.is_platform_enabled == 'true' && matrix.platform == 'linux' }}
|
||||||
|
run: sudo apt-get -y update; sudo apt-get -y install --no-install-recommends libasound2-dev libudev-dev libwayland-dev libxkbcommon-dev
|
||||||
|
|
||||||
|
- name: Prepare output directories
|
||||||
|
if: ${{ env.is_platform_enabled == 'true' }}
|
||||||
|
run: rm -rf tmp; mkdir -p tmp/binary '${{ env.app }}'
|
||||||
|
|
||||||
|
- name: Install cargo-binstall
|
||||||
|
if: ${{ env.is_platform_enabled == 'true' }}
|
||||||
|
uses: cargo-bins/cargo-binstall@main
|
||||||
|
|
||||||
|
- name: Install Bevy CLI
|
||||||
|
if: ${{ env.is_platform_enabled == 'true' }}
|
||||||
|
run: cargo binstall --locked --no-confirm --force --git='https://github.com/TheBevyFlock/bevy_cli' bevy_cli
|
||||||
|
|
||||||
|
- name: Build and add web bundle to app (Web)
|
||||||
|
if: ${{ env.is_platform_enabled == 'true' && matrix.platform == 'web' }}
|
||||||
|
run: |
|
||||||
|
cargo binstall --locked --no-confirm --force wasm-bindgen-cli
|
||||||
|
cargo binstall --locked --no-confirm --force wasm-opt
|
||||||
|
RUSTFLAGS='-Zshare-generics=y -Zthreads=0 --cfg getrandom_backend="wasm_js"' bevy build --locked --release --features='${{ matrix.features }} web' --yes web --bundle
|
||||||
|
mv 'target/bevy_web/web-release/${{ env.cargo_build_binary_name }}' '${{ env.app }}'
|
||||||
|
|
||||||
|
- name: Build and add binaries to app (non-Web)
|
||||||
|
if: ${{ env.is_platform_enabled == 'true' && matrix.platform != 'web' }}
|
||||||
|
run: |
|
||||||
|
for target in ${{ matrix.targets }}; do
|
||||||
|
bevy build --locked --release --target="${target}" --features='${{ matrix.features }}'
|
||||||
|
mv target/"${target}"/release/'${{ env.cargo_build_binary_name }}${{ matrix.binary_ext }}' tmp/binary/"${target}"'${{ matrix.binary_ext }}'
|
||||||
|
done
|
||||||
|
if [ '${{ matrix.platform }}' = 'macos' ]; then
|
||||||
|
lipo tmp/binary/*'${{ matrix.binary_ext }}' -create -output '${{ env.app }}/${{ env.app_binary_name }}${{ matrix.binary_ext }}'
|
||||||
|
else
|
||||||
|
mv tmp/binary/*'${{ matrix.binary_ext }}' '${{ env.app }}/${{ env.app_binary_name }}${{ matrix.binary_ext }}'
|
||||||
|
fi
|
||||||
|
|
||||||
|
- name: Add assets to app (non-Web)
|
||||||
|
if: ${{ env.is_platform_enabled == 'true' && matrix.platform != 'web' }}
|
||||||
|
run: cp -R ./'${{ env.assets_path }}' '${{ env.app }}' || true # Ignore error if assets folder does not exist.
|
||||||
|
|
||||||
|
- name: Add metadata to app (macOS)
|
||||||
|
if: ${{ env.is_platform_enabled == 'true' && matrix.platform == 'macos' }}
|
||||||
|
run: |
|
||||||
|
cat >'${{ env.app }}/../Info.plist' <<EOF
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||||
|
<plist version="1.0">
|
||||||
|
<dict>
|
||||||
|
<key>CFBundleDevelopmentRegion</key>
|
||||||
|
<string>en</string>
|
||||||
|
<key>CFBundleDisplayName</key>
|
||||||
|
<string>${{ env.app_display_name }}</string>
|
||||||
|
<key>CFBundleExecutable</key>
|
||||||
|
<string>${{ env.app_binary_name }}</string>
|
||||||
|
<key>CFBundleIdentifier</key>
|
||||||
|
<string>${{ env.app_id }}</string>
|
||||||
|
<key>CFBundleName</key>
|
||||||
|
<string>${{ env.app_short_name }}</string>
|
||||||
|
<key>CFBundleShortVersionString</key>
|
||||||
|
<string>${{ env.version }}</string>
|
||||||
|
<key>CFBundleVersion</key>
|
||||||
|
<string>${{ env.version }}</string>
|
||||||
|
<key>CFBundleInfoDictionaryVersion</key>
|
||||||
|
<string>6.0</string>
|
||||||
|
<key>CFBundlePackageType</key>
|
||||||
|
<string>APPL</string>
|
||||||
|
<key>CFBundleSupportedPlatforms</key>
|
||||||
|
<array>
|
||||||
|
<string>MacOSX</string>
|
||||||
|
</array>
|
||||||
|
</dict>
|
||||||
|
</plist>
|
||||||
|
EOF
|
||||||
|
|
||||||
|
- name: Package app (non-Windows)
|
||||||
|
if: ${{ env.is_platform_enabled == 'true' && matrix.platform != 'windows' }}
|
||||||
|
working-directory: tmp/app
|
||||||
|
run: |
|
||||||
|
if [ '${{ matrix.platform }}' = 'macos' ]; then
|
||||||
|
ln -s /Applications .
|
||||||
|
hdiutil create -fs HFS+ -volname '${{ env.app_package_name }}' -srcfolder . '${{ env.package }}'
|
||||||
|
else
|
||||||
|
zip --recurse-paths '${{ env.package }}' '${{ env.app_package_name }}'
|
||||||
|
fi
|
||||||
|
|
||||||
|
- name: Package app (Windows)
|
||||||
|
if: ${{ env.is_platform_enabled == 'true' && matrix.platform == 'windows' }}
|
||||||
|
working-directory: tmp/app
|
||||||
|
shell: pwsh
|
||||||
|
run: Compress-Archive -Path '${{ env.app_package_name }}' -DestinationPath '${{ env.package }}'
|
||||||
|
|
||||||
|
- name: Upload package to workflow artifacts
|
||||||
|
if: ${{ env.is_platform_enabled == 'true' }}
|
||||||
|
uses: actions/upload-artifact@v4
|
||||||
|
with:
|
||||||
|
path: tmp/app/${{ env.package }}
|
||||||
|
name: package-${{ matrix.platform }}
|
||||||
|
retention-days: 1
|
||||||
|
|
||||||
|
- name: Upload package to GitHub release
|
||||||
|
if: ${{ env.is_platform_enabled == 'true' && env.upload_to_github == 'true' }}
|
||||||
|
uses: svenstaro/upload-release-action@v2
|
||||||
|
with:
|
||||||
|
repo_token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
file: tmp/app/${{ env.package }}
|
||||||
|
asset_name: ${{ env.package }}
|
||||||
|
release_name: ${{ env.version }}
|
||||||
|
tag: ${{ env.version }}
|
||||||
|
overwrite: true
|
||||||
|
|
||||||
|
# Upload all packages to itch.io.
|
||||||
|
upload-to-itch:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
needs:
|
||||||
|
- forward-env
|
||||||
|
- get-version
|
||||||
|
- build
|
||||||
|
if: ${{ needs.forward-env.outputs.upload_to_itch != '' }}
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Download all packages
|
||||||
|
uses: actions/download-artifact@v4
|
||||||
|
with:
|
||||||
|
pattern: package-*
|
||||||
|
path: tmp
|
||||||
|
|
||||||
|
- name: Install butler
|
||||||
|
run: |
|
||||||
|
curl -L -o butler.zip 'https://broth.itch.zone/butler/linux-amd64/LATEST/archive/default'
|
||||||
|
unzip butler.zip
|
||||||
|
chmod +x butler
|
||||||
|
./butler -V
|
||||||
|
|
||||||
|
- name: Upload all packages to itch.io
|
||||||
|
env:
|
||||||
|
BUTLER_API_KEY: ${{ secrets.BUTLER_CREDENTIALS }}
|
||||||
|
run: |
|
||||||
|
for channel in $(ls tmp); do
|
||||||
|
./butler push \
|
||||||
|
--fix-permissions \
|
||||||
|
--userversion='${{ needs.get-version.outputs.version }}' \
|
||||||
|
tmp/"${channel}"/* \
|
||||||
|
'${{ env.upload_to_itch }}':"${channel#package-}"
|
||||||
|
done
|
||||||
347
.github/workflows/release.yaml.template
vendored
Normal file
347
.github/workflows/release.yaml.template
vendored
Normal file
@@ -0,0 +1,347 @@
|
|||||||
|
name: Release
|
||||||
|
|
||||||
|
on:
|
||||||
|
# Trigger this workflow when a tag is pushed in the format `v1.2.3`.
|
||||||
|
push:
|
||||||
|
tags:
|
||||||
|
# Pattern syntax: <https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#filter-pattern-cheat-sheet>.
|
||||||
|
- "v[0-9]+.[0-9]+.[0-9]+*"
|
||||||
|
# Trigger this workflow manually via workflow dispatch.
|
||||||
|
workflow_dispatch:
|
||||||
|
inputs:
|
||||||
|
version:
|
||||||
|
description: "Version number in the format `v1.2.3`"
|
||||||
|
required: true
|
||||||
|
type: string
|
||||||
|
|
||||||
|
{% raw -%}
|
||||||
|
concurrency:
|
||||||
|
group: ${{ github.workflow }}-${{ github.ref || github.run_id }}
|
||||||
|
cancel-in-progress: true
|
||||||
|
{%- endraw %}
|
||||||
|
|
||||||
|
# Configure the release workflow by editing the following values.
|
||||||
|
env:
|
||||||
|
# The base filename of the binary produced by `cargo build`.
|
||||||
|
cargo_build_binary_name: {{project-name}}
|
||||||
|
|
||||||
|
# The path to the assets directory.
|
||||||
|
assets_path: assets
|
||||||
|
|
||||||
|
# Whether to build and package a release for a given target platform.
|
||||||
|
build_for_web: true
|
||||||
|
build_for_linux: true
|
||||||
|
build_for_windows: true
|
||||||
|
build_for_macos: true
|
||||||
|
|
||||||
|
# Whether to upload the packages produced by this workflow to a GitHub release.
|
||||||
|
upload_to_github: true
|
||||||
|
|
||||||
|
# The itch.io project to upload to in the format `user-name/project-name`.
|
||||||
|
# There will be no upload to itch.io if this is commented out.
|
||||||
|
{%- if itch_username != "" %}
|
||||||
|
{%- if itch_project != "" %}
|
||||||
|
upload_to_itch: {{itch_username}}/{{itch_project}}
|
||||||
|
{%- else %}
|
||||||
|
upload_to_itch: {{itch_username}}/{{project-name}}
|
||||||
|
{%- endif %}
|
||||||
|
{%- else %}
|
||||||
|
#upload_to_itch: your-itch-username/{{project-name}}
|
||||||
|
{%- endif %}
|
||||||
|
|
||||||
|
############
|
||||||
|
# ADVANCED #
|
||||||
|
############
|
||||||
|
|
||||||
|
# The ID of the app produced by this workflow.
|
||||||
|
# Applies to macOS releases.
|
||||||
|
# Must contain only A-Z, a-z, 0-9, hyphen, and period: <https://developer.apple.com/documentation/bundleresources/information_property_list/cfbundleidentifier>.
|
||||||
|
app_id: {{itch_username | kebab_case}}.{{project-name | kebab_case}}
|
||||||
|
|
||||||
|
# The base filename of the binary in the package produced by this workflow.
|
||||||
|
# Applies to Windows, macOS, and Linux releases.
|
||||||
|
# Defaults to `cargo_build_binary_name` if commented out.
|
||||||
|
#app_binary_name: {{project-name}}
|
||||||
|
|
||||||
|
# The name of the `.zip` or `.dmg` file produced by this workflow.
|
||||||
|
# Defaults to `app_binary_name` if commented out.
|
||||||
|
#app_package_name: {{project-name | kebab_case}}
|
||||||
|
|
||||||
|
# The display name of the app produced by this workflow.
|
||||||
|
# Applies to macOS releases.
|
||||||
|
# Defaults to `app_package_name` if commented out.
|
||||||
|
#app_display_name: {{project-name | title_case}}
|
||||||
|
|
||||||
|
# The short display name of the app produced by this workflow.
|
||||||
|
# Applies to macOS releases.
|
||||||
|
# Must be 15 or fewer characters: <https://developer.apple.com/documentation/bundleresources/information_property_list/cfbundlename>.
|
||||||
|
# Defaults to `app_display_name` if commented out.
|
||||||
|
#app_short_name: {{project-name | title_case | truncate: 15, "…"}}
|
||||||
|
|
||||||
|
# Before enabling LFS, please take a look at GitHub's documentation for costs and quota limits:
|
||||||
|
# <https://docs.github.com/en/repositories/working-with-files/managing-large-files/about-storage-and-bandwidth-usage>
|
||||||
|
git_lfs: false
|
||||||
|
|
||||||
|
# Enabling this only helps with consecutive releases to the same tag (and takes up cache storage space).
|
||||||
|
# See: <https://github.com/orgs/community/discussions/27059>.
|
||||||
|
use_github_cache: false
|
||||||
|
|
||||||
|
# Reduce compile time.
|
||||||
|
RUSTFLAGS: -Dwarnings -Zshare-generics=y -Zthreads=0
|
||||||
|
|
||||||
|
{% raw -%}
|
||||||
|
jobs:
|
||||||
|
# Forward some environment variables as outputs of this job.
|
||||||
|
# This is needed because the `env` context can't be used in the `if:` condition of a job:
|
||||||
|
# <https://docs.github.com/en/actions/learn-github-actions/contexts#context-availability>
|
||||||
|
forward-env:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Do nothing
|
||||||
|
run: "true"
|
||||||
|
outputs:
|
||||||
|
upload_to_itch: ${{ env.upload_to_itch }}
|
||||||
|
|
||||||
|
# Determine the version number for this workflow.
|
||||||
|
get-version:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Determine version number
|
||||||
|
id: tag
|
||||||
|
run: echo "tag=${GITHUB_REF#refs/tags/}" >> "${GITHUB_OUTPUT}"
|
||||||
|
outputs:
|
||||||
|
# Use the input from workflow dispatch, or fall back to the git tag.
|
||||||
|
version: ${{ inputs.version || steps.tag.outputs.tag }}
|
||||||
|
|
||||||
|
# Build and package a release for each platform.
|
||||||
|
build:
|
||||||
|
needs:
|
||||||
|
- get-version
|
||||||
|
env:
|
||||||
|
version: ${{ needs.get-version.outputs.version }}
|
||||||
|
# Avoid rate-limiting. See: <https://github.com/cargo-bins/cargo-binstall/issues/2045>.
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
include:
|
||||||
|
- platform: web
|
||||||
|
targets: wasm32-unknown-unknown
|
||||||
|
package_ext: .zip
|
||||||
|
runner: ubuntu-latest
|
||||||
|
|
||||||
|
- platform: linux
|
||||||
|
targets: x86_64-unknown-linux-gnu
|
||||||
|
package_ext: .zip
|
||||||
|
runner: ubuntu-latest
|
||||||
|
|
||||||
|
- platform: windows
|
||||||
|
targets: x86_64-pc-windows-msvc
|
||||||
|
binary_ext: .exe
|
||||||
|
package_ext: .zip
|
||||||
|
runner: windows-latest
|
||||||
|
|
||||||
|
- platform: macos
|
||||||
|
targets: x86_64-apple-darwin aarch64-apple-darwin
|
||||||
|
app_suffix: .app/Contents/MacOS
|
||||||
|
package_ext: .dmg
|
||||||
|
runner: macos-latest
|
||||||
|
runs-on: ${{ matrix.runner }}
|
||||||
|
permissions:
|
||||||
|
# Required to create a GitHub release: <https://docs.github.com/en/rest/releases/releases#create-a-release>.
|
||||||
|
contents: write
|
||||||
|
defaults:
|
||||||
|
run:
|
||||||
|
shell: bash
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Set up environment
|
||||||
|
run: |
|
||||||
|
# Default values:
|
||||||
|
echo "app_binary_name=${app_binary_name:=${{ env.cargo_build_binary_name }}}" >> "${GITHUB_ENV}"
|
||||||
|
echo "app_package_name=${app_package_name:=${app_binary_name}}" >> "${GITHUB_ENV}"
|
||||||
|
echo "app_display_name=${app_display_name:=${app_package_name}}" >> "${GITHUB_ENV}"
|
||||||
|
echo "app_short_name=${app_short_name:=${app_display_name}}" >> "${GITHUB_ENV}"
|
||||||
|
|
||||||
|
# File paths:
|
||||||
|
echo "app=tmp/app/${app_package_name}"'${{ matrix.app_suffix }}' >> "${GITHUB_ENV}"
|
||||||
|
echo "package=${app_package_name}-"'${{ matrix.platform }}${{ matrix.package_ext }}' >> "${GITHUB_ENV}"
|
||||||
|
|
||||||
|
# macOS environment:
|
||||||
|
if [ '${{ matrix.platform }}' = 'macos' ]; then
|
||||||
|
echo 'MACOSX_DEPLOYMENT_TARGET=11.0' >> "${GITHUB_ENV}" # macOS 11.0 Big Sur is the first version to support universal binaries.
|
||||||
|
echo "SDKROOT=$(xcrun --sdk macosx --show-sdk-path)" >> "${GITHUB_ENV}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check if building for this platform is enabled.
|
||||||
|
echo 'is_platform_enabled=${{
|
||||||
|
(matrix.platform == 'web' && env.build_for_web == 'true') ||
|
||||||
|
(matrix.platform == 'linux' && env.build_for_linux == 'true') ||
|
||||||
|
(matrix.platform == 'windows' && env.build_for_windows == 'true') ||
|
||||||
|
(matrix.platform == 'macos' && env.build_for_macos == 'true')
|
||||||
|
}}' >> "${GITHUB_ENV}"
|
||||||
|
|
||||||
|
- name: Checkout repository
|
||||||
|
if: ${{ env.is_platform_enabled == 'true' }}
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
lfs: ${{ env.git_lfs }}
|
||||||
|
|
||||||
|
- name: Install Rust toolchain
|
||||||
|
if: ${{ env.is_platform_enabled == 'true' }}
|
||||||
|
uses: dtolnay/rust-toolchain@nightly
|
||||||
|
with:
|
||||||
|
targets: ${{ matrix.targets }}
|
||||||
|
|
||||||
|
- name: Restore Rust cache
|
||||||
|
if: ${{ env.is_platform_enabled == 'true' && env.use_github_cache == 'true' }}
|
||||||
|
uses: Swatinem/rust-cache@v2
|
||||||
|
with:
|
||||||
|
shared-key: release
|
||||||
|
save-if: ${{ github.ref == 'refs/heads/main' }}
|
||||||
|
|
||||||
|
- name: Install build dependencies (Linux)
|
||||||
|
if: ${{ env.is_platform_enabled == 'true' && matrix.platform == 'linux' }}
|
||||||
|
run: sudo apt-get update; sudo apt-get install --no-install-recommends libasound2-dev libudev-dev libwayland-dev libxkbcommon-dev
|
||||||
|
|
||||||
|
- name: Prepare output directories
|
||||||
|
if: ${{ env.is_platform_enabled == 'true' }}
|
||||||
|
run: rm -rf tmp; mkdir -p tmp/binary '${{ env.app }}'
|
||||||
|
|
||||||
|
- name: Install cargo-binstall
|
||||||
|
if: ${{ env.is_platform_enabled == 'true' }}
|
||||||
|
uses: cargo-bins/cargo-binstall@main
|
||||||
|
|
||||||
|
- name: Install Bevy CLI
|
||||||
|
if: ${{ env.is_platform_enabled == 'true' }}
|
||||||
|
run: cargo binstall --locked --no-confirm --force --git='https://github.com/TheBevyFlock/bevy_cli' bevy_cli
|
||||||
|
|
||||||
|
- name: Build and add web bundle to app (Web)
|
||||||
|
if: ${{ env.is_platform_enabled == 'true' && matrix.platform == 'web' }}
|
||||||
|
run: |
|
||||||
|
cargo binstall --locked --no-confirm --force wasm-bindgen-cli
|
||||||
|
cargo binstall --locked --no-confirm --force wasm-opt
|
||||||
|
bevy build --locked --release --features='${{ matrix.features }}' --yes web --bundle
|
||||||
|
mv 'target/bevy_web/web-release/${{ env.cargo_build_binary_name }}' '${{ env.app }}'
|
||||||
|
|
||||||
|
- name: Build and add binaries to app (non-Web)
|
||||||
|
if: ${{ env.is_platform_enabled == 'true' && matrix.platform != 'web' }}
|
||||||
|
run: |
|
||||||
|
for target in ${{ matrix.targets }}; do
|
||||||
|
bevy build --locked --release --target="${target}" --features='${{ matrix.features }}'
|
||||||
|
mv target/"${target}"/release/'${{ env.cargo_build_binary_name }}${{ matrix.binary_ext }}' tmp/binary/"${target}"'${{ matrix.binary_ext }}'
|
||||||
|
done
|
||||||
|
if [ '${{ matrix.platform }}' = 'macos' ]; then
|
||||||
|
lipo tmp/binary/*'${{ matrix.binary_ext }}' -create -output '${{ env.app }}/${{ env.app_binary_name }}${{ matrix.binary_ext }}'
|
||||||
|
else
|
||||||
|
mv tmp/binary/*'${{ matrix.binary_ext }}' '${{ env.app }}/${{ env.app_binary_name }}${{ matrix.binary_ext }}'
|
||||||
|
fi
|
||||||
|
|
||||||
|
- name: Add assets to app (non-Web)
|
||||||
|
if: ${{ env.is_platform_enabled == 'true' && matrix.platform != 'web' }}
|
||||||
|
run: cp -R ./'${{ env.assets_path }}' '${{ env.app }}' || true # Ignore error if assets folder does not exist.
|
||||||
|
|
||||||
|
- name: Add metadata to app (macOS)
|
||||||
|
if: ${{ env.is_platform_enabled == 'true' && matrix.platform == 'macos' }}
|
||||||
|
run: |
|
||||||
|
cat >'${{ env.app }}/../Info.plist' <<EOF
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||||
|
<plist version="1.0">
|
||||||
|
<dict>
|
||||||
|
<key>CFBundleDevelopmentRegion</key>
|
||||||
|
<string>en</string>
|
||||||
|
<key>CFBundleDisplayName</key>
|
||||||
|
<string>${{ env.app_display_name }}</string>
|
||||||
|
<key>CFBundleExecutable</key>
|
||||||
|
<string>${{ env.app_binary_name }}</string>
|
||||||
|
<key>CFBundleIdentifier</key>
|
||||||
|
<string>${{ env.app_id }}</string>
|
||||||
|
<key>CFBundleName</key>
|
||||||
|
<string>${{ env.app_short_name }}</string>
|
||||||
|
<key>CFBundleShortVersionString</key>
|
||||||
|
<string>${{ env.version }}</string>
|
||||||
|
<key>CFBundleVersion</key>
|
||||||
|
<string>${{ env.version }}</string>
|
||||||
|
<key>CFBundleInfoDictionaryVersion</key>
|
||||||
|
<string>6.0</string>
|
||||||
|
<key>CFBundlePackageType</key>
|
||||||
|
<string>APPL</string>
|
||||||
|
<key>CFBundleSupportedPlatforms</key>
|
||||||
|
<array>
|
||||||
|
<string>MacOSX</string>
|
||||||
|
</array>
|
||||||
|
</dict>
|
||||||
|
</plist>
|
||||||
|
EOF
|
||||||
|
|
||||||
|
- name: Package app (non-Windows)
|
||||||
|
if: ${{ env.is_platform_enabled == 'true' && matrix.platform != 'windows' }}
|
||||||
|
working-directory: tmp/app
|
||||||
|
run: |
|
||||||
|
if [ '${{ matrix.platform }}' = 'macos' ]; then
|
||||||
|
ln -s /Applications .
|
||||||
|
hdiutil create -fs HFS+ -volname '${{ env.app_package_name }}' -srcfolder . '${{ env.package }}'
|
||||||
|
else
|
||||||
|
zip --recurse-paths '${{ env.package }}' '${{ env.app_package_name }}'
|
||||||
|
fi
|
||||||
|
|
||||||
|
- name: Package app (Windows)
|
||||||
|
if: ${{ env.is_platform_enabled == 'true' && matrix.platform == 'windows' }}
|
||||||
|
working-directory: tmp/app
|
||||||
|
shell: pwsh
|
||||||
|
run: Compress-Archive -Path '${{ env.app_package_name }}' -DestinationPath '${{ env.package }}'
|
||||||
|
|
||||||
|
- name: Upload package to workflow artifacts
|
||||||
|
if: ${{ env.is_platform_enabled == 'true' }}
|
||||||
|
uses: actions/upload-artifact@v4
|
||||||
|
with:
|
||||||
|
path: tmp/app/${{ env.package }}
|
||||||
|
name: package-${{ matrix.platform }}
|
||||||
|
retention-days: 1
|
||||||
|
|
||||||
|
- name: Upload package to GitHub release
|
||||||
|
if: ${{ env.is_platform_enabled == 'true' && env.upload_to_github == 'true' }}
|
||||||
|
uses: svenstaro/upload-release-action@v2
|
||||||
|
with:
|
||||||
|
repo_token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
file: tmp/app/${{ env.package }}
|
||||||
|
asset_name: ${{ env.package }}
|
||||||
|
release_name: ${{ env.version }}
|
||||||
|
tag: ${{ env.version }}
|
||||||
|
overwrite: true
|
||||||
|
|
||||||
|
# Upload all packages to itch.io.
|
||||||
|
upload-to-itch:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
needs:
|
||||||
|
- forward-env
|
||||||
|
- get-version
|
||||||
|
- build
|
||||||
|
if: ${{ needs.forward-env.outputs.upload_to_itch != '' }}
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Download all packages
|
||||||
|
uses: actions/download-artifact@v4
|
||||||
|
with:
|
||||||
|
pattern: package-*
|
||||||
|
path: tmp
|
||||||
|
|
||||||
|
- name: Install butler
|
||||||
|
run: |
|
||||||
|
curl -L -o butler.zip 'https://broth.itch.zone/butler/linux-amd64/LATEST/archive/default'
|
||||||
|
unzip butler.zip
|
||||||
|
chmod +x butler
|
||||||
|
./butler -V
|
||||||
|
|
||||||
|
- name: Upload all packages to itch.io
|
||||||
|
env:
|
||||||
|
BUTLER_API_KEY: ${{ secrets.BUTLER_CREDENTIALS }}
|
||||||
|
run: |
|
||||||
|
for channel in $(ls tmp); do
|
||||||
|
./butler push \
|
||||||
|
--fix-permissions \
|
||||||
|
--userversion='${{ needs.get-version.outputs.version }}' \
|
||||||
|
tmp/"${channel}"/* \
|
||||||
|
'${{ env.upload_to_itch }}':"${channel#package-}"
|
||||||
|
done
|
||||||
|
{%- endraw %}
|
||||||
873
Cargo.lock
generated
873
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
40
Cargo.toml
40
Cargo.toml
@@ -1,38 +1,6 @@
|
|||||||
[package]
|
[workspace]
|
||||||
name = "space-game"
|
resolver = "2"
|
||||||
version = "0.1.0"
|
members = [ "engine/prefabs","game/main"]
|
||||||
edition = "2024"
|
|
||||||
|
|
||||||
[dependencies]
|
|
||||||
# avian3d = { version = "0.3.0", features = [] }
|
|
||||||
bevy = { version = "0.16.1", features = [] }
|
|
||||||
# bevy_rapier3d = { version = "0.29.0", features = ["simd-stable", "parallel"] }
|
|
||||||
bevy-inspector-egui = "0.31.0"
|
|
||||||
bevy_asset_loader = "0.23.0"
|
|
||||||
bevy_rapier3d = "0.30.0"
|
|
||||||
|
|
||||||
[features]
|
|
||||||
default = ["dev"]
|
|
||||||
dev = [
|
|
||||||
"bevy/bevy_dev_tools",
|
|
||||||
"bevy/bevy_ui_debug",
|
|
||||||
"bevy/track_location",
|
|
||||||
"bevy/file_watcher",
|
|
||||||
"bevy/embedded_watcher",
|
|
||||||
"dev-viz"
|
|
||||||
]
|
|
||||||
dev-viz = []
|
|
||||||
dev-phys = []
|
|
||||||
|
|
||||||
[lints.clippy]
|
|
||||||
# Bevy supplies arguments to systems via dependency injection, so it's natural for systems to
|
|
||||||
# request more than 7 arguments, which would undesirably trigger this lint.
|
|
||||||
too_many_arguments = "allow"
|
|
||||||
# Queries may access many components, which would undesirably trigger this lint.
|
|
||||||
type_complexity = "allow"
|
|
||||||
# Make sure macros use their standard braces, such as `[]` for `bevy_ecs::children!`.
|
|
||||||
nonstandard_macro_braces = "warn"
|
|
||||||
needless_return = "allow"
|
|
||||||
|
|
||||||
# Enable a small amount of optimization in debug mode
|
# Enable a small amount of optimization in debug mode
|
||||||
[profile.dev]
|
[profile.dev]
|
||||||
@@ -55,4 +23,4 @@ debug = "line-tables-only"
|
|||||||
codegen-units = 4
|
codegen-units = 4
|
||||||
|
|
||||||
[profile.ci.package."*"]
|
[profile.ci.package."*"]
|
||||||
opt-level = 0
|
opt-level = 0
|
||||||
23
engine/prefabs/Cargo.toml
Normal file
23
engine/prefabs/Cargo.toml
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
[package]
|
||||||
|
name = "prefabs"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2024"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
bevy = "0.16.1"
|
||||||
|
serde = "1.0.219"
|
||||||
|
typetag = "0.2.20"
|
||||||
|
|
||||||
|
[dev-dependencies]
|
||||||
|
ron = "0.10.1"
|
||||||
|
|
||||||
|
|
||||||
|
[lints.clippy]
|
||||||
|
# Bevy supplies arguments to systems via dependency injection, so it's natural for systems to
|
||||||
|
# request more than 7 arguments, which would undesirably trigger this lint.
|
||||||
|
too_many_arguments = "allow"
|
||||||
|
# Queries may access many components, which would undesirably trigger this lint.
|
||||||
|
type_complexity = "allow"
|
||||||
|
# Make sure macros use their standard braces, such as `[]` for `bevy_ecs::children!`.
|
||||||
|
nonstandard_macro_braces = "warn"
|
||||||
|
needless_return = "allow"
|
||||||
17
engine/prefabs/src/builders.rs
Normal file
17
engine/prefabs/src/builders.rs
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
use bevy::prelude::*;
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
use crate::prefab::ComponentBuilder;
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize, Clone)]
|
||||||
|
pub struct PrefabMesh {
|
||||||
|
pub glb_path: String,
|
||||||
|
pub mesh_path: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[typetag::serde]
|
||||||
|
impl ComponentBuilder for PrefabMesh {
|
||||||
|
fn build(&self, _entity: &mut EntityCommands, asset_server: &AssetServer) {
|
||||||
|
let glb: Handle<Scene> = asset_server.load(&self.glb_path);
|
||||||
|
}
|
||||||
|
}
|
||||||
4
engine/prefabs/src/components.rs
Normal file
4
engine/prefabs/src/components.rs
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
use bevy::prelude::*;
|
||||||
|
|
||||||
|
#[derive(Component)]
|
||||||
|
pub struct PrefabId(pub Entity);
|
||||||
17
engine/prefabs/src/lib.rs
Normal file
17
engine/prefabs/src/lib.rs
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
use bevy::prelude::*;
|
||||||
|
|
||||||
|
pub mod builders;
|
||||||
|
pub mod components;
|
||||||
|
pub mod prefab;
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests;
|
||||||
|
|
||||||
|
pub struct PrefabPlugin;
|
||||||
|
|
||||||
|
impl Plugin for PrefabPlugin {
|
||||||
|
fn build(&self, app: &mut bevy::app::App) {
|
||||||
|
app.add_systems(Last, prefab_watcher);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn prefab_watcher() {}
|
||||||
32
engine/prefabs/src/prefab.rs
Normal file
32
engine/prefabs/src/prefab.rs
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
use bevy::{ecs::entity_disabling::Disabled, prelude::*};
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
use crate::builders::PrefabMesh;
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize, Default)]
|
||||||
|
pub struct PrefabAsset {
|
||||||
|
pub components: Vec<Box<dyn ComponentBuilder>>,
|
||||||
|
pub children: Vec<PrefabAsset>,
|
||||||
|
pub mesh: Option<PrefabMesh>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl PrefabAsset {
|
||||||
|
pub fn build_prefab(&self, commands: &mut Commands, asset_server: &AssetServer) -> Entity {
|
||||||
|
let children: Vec<_> = self
|
||||||
|
.children
|
||||||
|
.iter()
|
||||||
|
.map(|c| c.build_prefab(commands, asset_server))
|
||||||
|
.collect();
|
||||||
|
let mut entity = commands.spawn(Disabled);
|
||||||
|
entity.add_children(&children[..]);
|
||||||
|
for builder in &self.components {
|
||||||
|
builder.build(&mut entity, asset_server);
|
||||||
|
}
|
||||||
|
return entity.id();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[typetag::serde(tag = "type")]
|
||||||
|
pub trait ComponentBuilder: Send {
|
||||||
|
fn build(&self, entity: &mut EntityCommands, asset_server: &AssetServer);
|
||||||
|
}
|
||||||
53
engine/prefabs/src/tests.rs
Normal file
53
engine/prefabs/src/tests.rs
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
use bevy::prelude::*;
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
use crate::prefab::{ComponentBuilder, PrefabAsset};
|
||||||
|
|
||||||
|
#[derive(Component, Serialize, Deserialize, Clone)]
|
||||||
|
struct Name {
|
||||||
|
pub name: String,
|
||||||
|
}
|
||||||
|
#[typetag::serde]
|
||||||
|
impl ComponentBuilder for Name {
|
||||||
|
fn build(&self, _entity: &mut EntityCommands, _: &AssetServer) {
|
||||||
|
assert_eq!(self.name, "Test".to_string(), "Name");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Component, Serialize, Deserialize, Clone)]
|
||||||
|
struct Position {
|
||||||
|
pub pos: Vec3,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[typetag::serde]
|
||||||
|
impl ComponentBuilder for Position {
|
||||||
|
fn build(&self, _entity: &mut EntityCommands, _: &AssetServer) {
|
||||||
|
assert_eq!(self.pos, Vec3::X, "Position");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn round_trip_test() {
|
||||||
|
let prefab = PrefabAsset {
|
||||||
|
components: vec![
|
||||||
|
Box::new(Position { pos: Vec3::X }),
|
||||||
|
Box::new(Name {
|
||||||
|
name: "Test".to_string(),
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
..default()
|
||||||
|
};
|
||||||
|
|
||||||
|
let serialized = ron::to_string(&prefab);
|
||||||
|
assert!(serialized.is_ok(), "Failed to serialzied");
|
||||||
|
|
||||||
|
let deserialize = ron::from_str::<PrefabAsset>(&serialized.unwrap());
|
||||||
|
assert!(deserialize.is_ok(), "Failed to deserialize");
|
||||||
|
|
||||||
|
let loaded_asset = deserialize.unwrap();
|
||||||
|
assert_eq!(
|
||||||
|
loaded_asset.components.len(),
|
||||||
|
prefab.components.len(),
|
||||||
|
"Prefab's components count do not match"
|
||||||
|
);
|
||||||
|
}
|
||||||
6408
game/main/Cargo.lock
generated
Normal file
6408
game/main/Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
59
game/main/Cargo.toml
Normal file
59
game/main/Cargo.toml
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
[package]
|
||||||
|
name = "space-game"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2024"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
# avian3d = { version = "0.3.0", features = [] }
|
||||||
|
bevy = { version = "0.16.1", features = [] }
|
||||||
|
# bevy_rapier3d = { version = "0.29.0", features = ["simd-stable", "parallel"] }
|
||||||
|
bevy-inspector-egui = "0.31.0"
|
||||||
|
bevy_asset_loader = "0.23.0"
|
||||||
|
bevy_rapier3d = "0.30.0"
|
||||||
|
prefabs = { path = "../../engine/prefabs" }
|
||||||
|
|
||||||
|
[features]
|
||||||
|
default = ["dev"]
|
||||||
|
dev = [
|
||||||
|
"bevy/bevy_dev_tools",
|
||||||
|
"bevy/bevy_ui_debug",
|
||||||
|
"bevy/track_location",
|
||||||
|
"bevy/file_watcher",
|
||||||
|
"bevy/embedded_watcher",
|
||||||
|
"dev-viz"
|
||||||
|
]
|
||||||
|
dev-viz = []
|
||||||
|
dev-phys = []
|
||||||
|
|
||||||
|
[lints.clippy]
|
||||||
|
# Bevy supplies arguments to systems via dependency injection, so it's natural for systems to
|
||||||
|
# request more than 7 arguments, which would undesirably trigger this lint.
|
||||||
|
too_many_arguments = "allow"
|
||||||
|
# Queries may access many components, which would undesirably trigger this lint.
|
||||||
|
type_complexity = "allow"
|
||||||
|
# Make sure macros use their standard braces, such as `[]` for `bevy_ecs::children!`.
|
||||||
|
nonstandard_macro_braces = "warn"
|
||||||
|
needless_return = "allow"
|
||||||
|
|
||||||
|
# Enable a small amount of optimization in debug mode
|
||||||
|
[profile.dev]
|
||||||
|
opt-level = 1
|
||||||
|
|
||||||
|
# Enable high optimizations for dependencies (incl. Bevy), but not for our code:
|
||||||
|
[profile.dev.package."*"]
|
||||||
|
opt-level = 3
|
||||||
|
|
||||||
|
[profile.release]
|
||||||
|
codegen-units = 1
|
||||||
|
lto = "thin"
|
||||||
|
|
||||||
|
|
||||||
|
# Optimize for build time in CI.
|
||||||
|
[profile.ci]
|
||||||
|
inherits = "dev"
|
||||||
|
opt-level = 0
|
||||||
|
debug = "line-tables-only"
|
||||||
|
codegen-units = 4
|
||||||
|
|
||||||
|
[profile.ci.package."*"]
|
||||||
|
opt-level = 0
|
||||||
Binary file not shown.
Binary file not shown.
@@ -1,6 +1,7 @@
|
|||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
#[cfg(feature = "dev")]
|
#[cfg(feature = "dev")]
|
||||||
use bevy::window::PrimaryWindow;
|
use bevy::window::PrimaryWindow;
|
||||||
|
use bevy_rapier3d::plugin::PhysicsSet;
|
||||||
|
|
||||||
use crate::{components::camera::*, states::play::PlaySystems};
|
use crate::{components::camera::*, states::play::PlaySystems};
|
||||||
|
|
||||||
@@ -9,7 +10,11 @@ pub struct CameraPlugin;
|
|||||||
impl Plugin for CameraPlugin {
|
impl Plugin for CameraPlugin {
|
||||||
fn build(&self, app: &mut App) {
|
fn build(&self, app: &mut App) {
|
||||||
app.add_systems(Update, camera_pitch.in_set(PlaySystems));
|
app.add_systems(Update, camera_pitch.in_set(PlaySystems));
|
||||||
app.add_systems(Update, camera_attachment.in_set(PlaySystems));
|
app.add_systems(
|
||||||
|
PostUpdate,
|
||||||
|
//Update after physics moves entities
|
||||||
|
camera_attachment.in_set(PlaySystems).after(PhysicsSet::Writeback),
|
||||||
|
);
|
||||||
#[cfg(feature = "dev")]
|
#[cfg(feature = "dev")]
|
||||||
app.add_systems(Update, camera_toggle.in_set(PlaySystems));
|
app.add_systems(Update, camera_toggle.in_set(PlaySystems));
|
||||||
}
|
}
|
||||||
@@ -1,22 +1,16 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
components::{
|
components::{
|
||||||
camera::{CameraAttachment, CameraMode, CameraPitch, FollowCam, MainCamera},
|
camera::{CameraAttachment, CameraMode, CameraPitch, MainCamera},
|
||||||
player::PlayerDrag,
|
player::PlayerDrag,
|
||||||
tags::{Player, Ship},
|
tags::Player,
|
||||||
},
|
},
|
||||||
plugins::{state_management::StateManagementPlugin, *},
|
plugins::{state_management::StateManagementPlugin, *},
|
||||||
states::{
|
states::play::PlayStartupSystems,
|
||||||
game::*,
|
|
||||||
input::{InputState, PlayerState},
|
|
||||||
menu::MenuState,
|
|
||||||
play::PlayStartupSystems,
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
use bevy::{
|
use bevy::{
|
||||||
prelude::*,
|
prelude::*,
|
||||||
window::{CursorGrabMode, PrimaryWindow},
|
window::{CursorGrabMode, PrimaryWindow},
|
||||||
};
|
};
|
||||||
use bevy_asset_loader::prelude::*;
|
|
||||||
use bevy_rapier3d::prelude::*;
|
use bevy_rapier3d::prelude::*;
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
@@ -29,7 +23,7 @@ impl Plugin for GamePlugin {
|
|||||||
CameraPlugin,
|
CameraPlugin,
|
||||||
StateManagementPlugin,
|
StateManagementPlugin,
|
||||||
MainMenuPlugin,
|
MainMenuPlugin,
|
||||||
// ShipPlugin,
|
ShipPlugin,
|
||||||
TypesPlugin,
|
TypesPlugin,
|
||||||
PlayerPlugin,
|
PlayerPlugin,
|
||||||
));
|
));
|
||||||
@@ -38,7 +32,7 @@ impl Plugin for GamePlugin {
|
|||||||
#[cfg(feature = "dev-phys")]
|
#[cfg(feature = "dev-phys")]
|
||||||
RapierDebugRenderPlugin::default(),
|
RapierDebugRenderPlugin::default(),
|
||||||
));
|
));
|
||||||
app.add_systems(Update, (setup_scene, spawn_ship).chain().in_set(PlayStartupSystems));
|
app.add_systems(Update, (setup_scene).chain().in_set(PlayStartupSystems));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -64,7 +58,14 @@ fn setup_scene(
|
|||||||
PlayerDrag(0.5),
|
PlayerDrag(0.5),
|
||||||
Collider::capsule_y(0.5, 0.5),
|
Collider::capsule_y(0.5, 0.5),
|
||||||
RigidBody::KinematicPositionBased,
|
RigidBody::KinematicPositionBased,
|
||||||
KinematicCharacterController::default(),
|
KinematicCharacterController {
|
||||||
|
autostep: Some(CharacterAutostep {
|
||||||
|
include_dynamic_bodies: true,
|
||||||
|
max_height: CharacterLength::Absolute(0.25),
|
||||||
|
..default()
|
||||||
|
}),
|
||||||
|
..default()
|
||||||
|
},
|
||||||
Mesh3d(meshes.add(Capsule3d::new(0.5, 1.0))),
|
Mesh3d(meshes.add(Capsule3d::new(0.5, 1.0))),
|
||||||
MeshMaterial3d(materials.add(Color::linear_rgb(1.0, 0.0, 0.2))),
|
MeshMaterial3d(materials.add(Color::linear_rgb(1.0, 0.0, 0.2))),
|
||||||
Transform::from_translation(Vec3::new(0.0, 10.0, 10.0)),
|
Transform::from_translation(Vec3::new(0.0, 10.0, 10.0)),
|
||||||
@@ -103,6 +104,7 @@ fn setup_scene(
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
fn spawn_ship(
|
fn spawn_ship(
|
||||||
mut commands: Commands,
|
mut commands: Commands,
|
||||||
mut meshes: ResMut<Assets<Mesh>>,
|
mut meshes: ResMut<Assets<Mesh>>,
|
||||||
@@ -116,7 +118,7 @@ fn spawn_ship(
|
|||||||
Mesh3d(meshes.add(Cuboid::new(3.0, 0.1, 6.0))),
|
Mesh3d(meshes.add(Cuboid::new(3.0, 0.1, 6.0))),
|
||||||
MeshMaterial3d(material.clone()),
|
MeshMaterial3d(material.clone()),
|
||||||
Name::new("Ship"),
|
Name::new("Ship"),
|
||||||
Ship,
|
// Ship,
|
||||||
Velocity::zero(),
|
Velocity::zero(),
|
||||||
Damping::default(),
|
Damping::default(),
|
||||||
Transform::from_xyz(0.0, 1.0, 0.0),
|
Transform::from_xyz(0.0, 1.0, 0.0),
|
||||||
@@ -15,6 +15,8 @@ pub use follow_cam::*;
|
|||||||
pub use game::*;
|
pub use game::*;
|
||||||
pub use main_menu::*;
|
pub use main_menu::*;
|
||||||
pub use player::*;
|
pub use player::*;
|
||||||
|
#[allow(unused_imports)]
|
||||||
pub use ship::*;
|
pub use ship::*;
|
||||||
|
#[allow(unused_imports)]
|
||||||
pub use ship_cam::*;
|
pub use ship_cam::*;
|
||||||
pub use types::*;
|
pub use types::*;
|
||||||
@@ -9,7 +9,7 @@ use crate::{
|
|||||||
player::{GravityDirection, JumpSpeed, MoveSpeed, PlayerDrag, PlayerForce, PlayerMotion, PlayerVelocity},
|
player::{GravityDirection, JumpSpeed, MoveSpeed, PlayerDrag, PlayerForce, PlayerMotion, PlayerVelocity},
|
||||||
tags::Player,
|
tags::Player,
|
||||||
},
|
},
|
||||||
states::{input::PlayerInputSystems, play::PlaySystems},
|
states::{input::InputWorldSystems, play::PlaySystems},
|
||||||
utils::{input::get_mouse_delta, rotation::get_alignment_rotation_preserve_twist},
|
utils::{input::get_mouse_delta, rotation::get_alignment_rotation_preserve_twist},
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -17,7 +17,7 @@ pub struct PlayerPlugin;
|
|||||||
|
|
||||||
impl Plugin for PlayerPlugin {
|
impl Plugin for PlayerPlugin {
|
||||||
fn build(&self, app: &mut App) {
|
fn build(&self, app: &mut App) {
|
||||||
app.add_systems(PreUpdate, (keyboard_input, player_look).in_set(PlayerInputSystems));
|
app.add_systems(PreUpdate, (keyboard_input, player_look).in_set(InputWorldSystems));
|
||||||
app.add_systems(
|
app.add_systems(
|
||||||
Update,
|
Update,
|
||||||
(apply_gravity, apply_forces, apply_motion, apply_drag)
|
(apply_gravity, apply_forces, apply_motion, apply_drag)
|
||||||
@@ -1,18 +1,50 @@
|
|||||||
use bevy::{input::mouse::MouseMotion, prelude::*};
|
use bevy::{input::mouse::MouseMotion, prelude::*};
|
||||||
use bevy_rapier3d::prelude::*;
|
use bevy_rapier3d::prelude::*;
|
||||||
|
|
||||||
use crate::{components::tags::Ship, states::play::PlaySystems, utils::input::get_mouse_delta};
|
use crate::{
|
||||||
|
components::tags::Ship,
|
||||||
|
states::play::{PlayStartupSystems, PlaySystems},
|
||||||
|
utils::input::get_mouse_delta,
|
||||||
|
};
|
||||||
|
|
||||||
pub struct ShipPlugin;
|
pub struct ShipPlugin;
|
||||||
|
|
||||||
impl Plugin for ShipPlugin {
|
impl Plugin for ShipPlugin {
|
||||||
fn build(&self, app: &mut App) {
|
fn build(&self, app: &mut App) {
|
||||||
|
app.add_systems(Update, spawn_ship.in_set(PlayStartupSystems));
|
||||||
|
|
||||||
app.add_systems(Update, ship_controls.in_set(PlaySystems));
|
app.add_systems(Update, ship_controls.in_set(PlaySystems));
|
||||||
#[cfg(feature = "dev-viz")]
|
#[cfg(feature = "dev-viz")]
|
||||||
app.add_systems(Update, ship_debug.in_set(PlaySystems));
|
app.add_systems(Update, ship_debug.in_set(PlaySystems));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Resource, Debug, Reflect)]
|
||||||
|
struct ShipMesh(Handle<Scene>);
|
||||||
|
|
||||||
|
fn spawn_ship(mut commads: Commands, assets: Res<AssetServer>) {
|
||||||
|
let scene = assets.load(GltfAssetLabel::Scene(0).from_asset("models/Ship.glb"));
|
||||||
|
|
||||||
|
commads.insert_resource(ShipMesh(scene.clone()));
|
||||||
|
|
||||||
|
commads.spawn((
|
||||||
|
SceneRoot(scene),
|
||||||
|
Transform::from_xyz(0.0, 3.0, 0.0),
|
||||||
|
RigidBody::KinematicVelocityBased,
|
||||||
|
GravityScale(0.0),
|
||||||
|
children![
|
||||||
|
(
|
||||||
|
Transform::from_xyz(-2.0, -2.7, 0.0),
|
||||||
|
Collider::round_cuboid(6.0, 0.1, 3.0, 0.05)
|
||||||
|
),
|
||||||
|
(
|
||||||
|
Transform::from_xyz(-2.0, 2.8, 0.0),
|
||||||
|
Collider::round_cuboid(6.0, 0.1, 3.0, 0.05)
|
||||||
|
)
|
||||||
|
],
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
fn ship_controls(
|
fn ship_controls(
|
||||||
ship_query: Single<(&Transform, &mut Velocity, &mut Damping), With<Ship>>,
|
ship_query: Single<(&Transform, &mut Velocity, &mut Damping), With<Ship>>,
|
||||||
key: Res<ButtonInput<KeyCode>>,
|
key: Res<ButtonInput<KeyCode>>,
|
||||||
@@ -3,7 +3,7 @@ use bevy::prelude::*;
|
|||||||
pub struct ShipCamPlugin;
|
pub struct ShipCamPlugin;
|
||||||
|
|
||||||
impl Plugin for ShipCamPlugin {
|
impl Plugin for ShipCamPlugin {
|
||||||
fn build(&self, app: &mut App) {
|
fn build(&self, _app: &mut App) {
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -5,11 +5,16 @@ use crate::{
|
|||||||
configure_sets,
|
configure_sets,
|
||||||
states::{
|
states::{
|
||||||
game::{GameState, InGameSystems, MenuSystems},
|
game::{GameState, InGameSystems, MenuSystems},
|
||||||
input::{InputState, PlayerInputSystems, PlayerState},
|
input::{
|
||||||
|
InputDetachedSystems, InputMenuSystems, InputState, InputWorldSystems, PlayerFreeFloatingSystems,
|
||||||
|
PlayerOnFootSystems, PlayerPilotingSystems, PlayerState,
|
||||||
|
},
|
||||||
menu::{
|
menu::{
|
||||||
MainMenuSystems, MenuCleanupSystems, MenuStartupSystems, MenuState, OptionsMenuSystems, SavesMenuSystems,
|
MainMenuSystems, MenuCleanupSystems, MenuStartupSystems, MenuState, OptionsMenuSystems, SavesMenuSystems,
|
||||||
},
|
},
|
||||||
play::{PausedSystems, PlayCleanupSystems, PlayStartupSystems, PlayState, PlaySystems},
|
play::{
|
||||||
|
PausedSystems, PlayAssetFinalizeSystems, PlayCleanupSystems, PlayStartupSystems, PlayState, PlaySystems,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -25,7 +30,7 @@ impl Plugin for StateManagementPlugin {
|
|||||||
|
|
||||||
//Loading
|
//Loading
|
||||||
app.add_loading_state(LoadingState::new(MenuState::Loading).continue_to_state(MenuState::Startup))
|
app.add_loading_state(LoadingState::new(MenuState::Loading).continue_to_state(MenuState::Startup))
|
||||||
.add_loading_state(LoadingState::new(PlayState::Loading).continue_to_state(PlayState::Startup));
|
.add_loading_state(LoadingState::new(PlayState::Loading).continue_to_state(PlayState::AssetFinalize));
|
||||||
|
|
||||||
//Game
|
//Game
|
||||||
configure_sets!(app, MenuSystems.run_if(in_state(GameState::MainMenu)));
|
configure_sets!(app, MenuSystems.run_if(in_state(GameState::MainMenu)));
|
||||||
@@ -55,6 +60,12 @@ impl Plugin for StateManagementPlugin {
|
|||||||
configure_sets!(app, MenuCleanupSystems.run_if(in_state(MenuState::Cleanup)));
|
configure_sets!(app, MenuCleanupSystems.run_if(in_state(MenuState::Cleanup)));
|
||||||
|
|
||||||
//Play
|
//Play
|
||||||
|
configure_sets!(
|
||||||
|
app,
|
||||||
|
PlayAssetFinalizeSystems
|
||||||
|
.run_if(in_state(PlayState::AssetFinalize))
|
||||||
|
.in_set(InGameSystems)
|
||||||
|
);
|
||||||
configure_sets!(
|
configure_sets!(
|
||||||
app,
|
app,
|
||||||
PlayStartupSystems
|
PlayStartupSystems
|
||||||
@@ -74,21 +85,59 @@ impl Plugin for StateManagementPlugin {
|
|||||||
//Input
|
//Input
|
||||||
configure_sets!(
|
configure_sets!(
|
||||||
app,
|
app,
|
||||||
PlayerInputSystems
|
InputWorldSystems
|
||||||
.run_if(in_state(InputState::World))
|
.run_if(in_state(InputState::World))
|
||||||
.in_set(PlaySystems)
|
.in_set(PlaySystems)
|
||||||
);
|
);
|
||||||
|
configure_sets!(
|
||||||
|
app,
|
||||||
|
InputMenuSystems.run_if(in_state(InputState::Menu)).in_set(PlaySystems)
|
||||||
|
);
|
||||||
|
configure_sets!(
|
||||||
|
app,
|
||||||
|
InputDetachedSystems
|
||||||
|
.run_if(in_state(InputState::Detached))
|
||||||
|
.in_set(PlaySystems)
|
||||||
|
);
|
||||||
|
|
||||||
|
//Player
|
||||||
|
configure_sets!(
|
||||||
|
app,
|
||||||
|
PlayerOnFootSystems
|
||||||
|
.run_if(in_state(PlayerState::OnFoot))
|
||||||
|
.in_set(PlaySystems)
|
||||||
|
);
|
||||||
|
configure_sets!(
|
||||||
|
app,
|
||||||
|
PlayerFreeFloatingSystems
|
||||||
|
.run_if(in_state(PlayerState::FreeFloating))
|
||||||
|
.in_set(PlaySystems)
|
||||||
|
);
|
||||||
|
configure_sets!(
|
||||||
|
app,
|
||||||
|
PlayerPilotingSystems
|
||||||
|
.run_if(in_state(PlayerState::Piloting))
|
||||||
|
.in_set(PlaySystems)
|
||||||
|
);
|
||||||
|
|
||||||
//State Transitions
|
//State Transitions
|
||||||
|
app.add_systems(Update, game_asset_finalize.in_set(PlayAssetFinalizeSystems));
|
||||||
app.add_systems(Update, game_startup.in_set(PlayStartupSystems));
|
app.add_systems(Update, game_startup.in_set(PlayStartupSystems));
|
||||||
app.add_systems(Update, game_cleanup.in_set(PlayCleanupSystems));
|
app.add_systems(Update, game_cleanup.in_set(PlayCleanupSystems));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn game_asset_finalize(mut next: ResMut<NextState<PlayState>>) {
|
||||||
|
next.set(PlayState::Startup);
|
||||||
|
info_once!("Moving to PlayState:{:?}", PlayState::Startup);
|
||||||
|
}
|
||||||
|
|
||||||
fn game_startup(mut next: ResMut<NextState<PlayState>>) {
|
fn game_startup(mut next: ResMut<NextState<PlayState>>) {
|
||||||
next.set(PlayState::Playing);
|
next.set(PlayState::Playing);
|
||||||
|
info_once!("Moving to PlayState:{:?}", PlayState::Playing);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn game_cleanup(mut next: ResMut<NextState<PlayState>>) {
|
fn game_cleanup(mut next: ResMut<NextState<PlayState>>) {
|
||||||
next.set(PlayState::Idle);
|
next.set(PlayState::Idle);
|
||||||
|
info_once!("Moving to PlayState:{:?}", PlayState::Idle);
|
||||||
}
|
}
|
||||||
35
game/main/src/states/input.rs
Normal file
35
game/main/src/states/input.rs
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
use bevy::prelude::*;
|
||||||
|
|
||||||
|
#[derive(States, Debug, Default, Clone, PartialEq, Eq, Hash)]
|
||||||
|
pub enum InputState {
|
||||||
|
#[default]
|
||||||
|
World,
|
||||||
|
Menu,
|
||||||
|
Detached,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(SystemSet, Debug, Clone, PartialEq, Eq, Hash)]
|
||||||
|
pub struct InputWorldSystems;
|
||||||
|
|
||||||
|
#[derive(SystemSet, Debug, Clone, PartialEq, Eq, Hash)]
|
||||||
|
pub struct InputMenuSystems;
|
||||||
|
|
||||||
|
#[derive(SystemSet, Debug, Clone, PartialEq, Eq, Hash)]
|
||||||
|
pub struct InputDetachedSystems;
|
||||||
|
|
||||||
|
#[derive(States, Debug, Default, Clone, PartialEq, Eq, Hash)]
|
||||||
|
pub enum PlayerState {
|
||||||
|
#[default]
|
||||||
|
OnFoot,
|
||||||
|
FreeFloating,
|
||||||
|
Piloting,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(SystemSet, Debug, Clone, PartialEq, Eq, Hash)]
|
||||||
|
pub struct PlayerOnFootSystems;
|
||||||
|
|
||||||
|
#[derive(SystemSet, Debug, Clone, PartialEq, Eq, Hash)]
|
||||||
|
pub struct PlayerFreeFloatingSystems;
|
||||||
|
|
||||||
|
#[derive(SystemSet, Debug, Clone, PartialEq, Eq, Hash)]
|
||||||
|
pub struct PlayerPilotingSystems;
|
||||||
@@ -2,8 +2,8 @@ use bevy::prelude::*;
|
|||||||
|
|
||||||
#[derive(States, Debug, Reflect, Default, Clone, Copy, PartialEq, Eq, Hash)]
|
#[derive(States, Debug, Reflect, Default, Clone, Copy, PartialEq, Eq, Hash)]
|
||||||
pub enum MenuState {
|
pub enum MenuState {
|
||||||
#[default]
|
|
||||||
Idle,
|
Idle,
|
||||||
|
#[default]
|
||||||
Loading,
|
Loading,
|
||||||
AssetFinalize,
|
AssetFinalize,
|
||||||
Startup,
|
Startup,
|
||||||
@@ -12,6 +12,9 @@ pub enum PlayState {
|
|||||||
Cleanup,
|
Cleanup,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(SystemSet, Debug, Clone, PartialEq, Eq, Hash)]
|
||||||
|
pub struct PlayAssetFinalizeSystems;
|
||||||
|
|
||||||
#[derive(SystemSet, Debug, Clone, PartialEq, Eq, Hash)]
|
#[derive(SystemSet, Debug, Clone, PartialEq, Eq, Hash)]
|
||||||
pub struct PlayStartupSystems;
|
pub struct PlayStartupSystems;
|
||||||
|
|
||||||
@@ -2,6 +2,7 @@ use std::f32::consts::PI;
|
|||||||
|
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
pub fn get_alignment_rotation(cur_dir: Dir3, target_dir: Vec3) -> Quat {
|
pub fn get_alignment_rotation(cur_dir: Dir3, target_dir: Vec3) -> Quat {
|
||||||
let tgt = target_dir.normalize();
|
let tgt = target_dir.normalize();
|
||||||
let axis = cur_dir.cross(tgt);
|
let axis = cur_dir.cross(tgt);
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
use bevy::prelude::*;
|
|
||||||
|
|
||||||
#[derive(States, Debug, Default, Clone, PartialEq, Eq, Hash)]
|
|
||||||
pub enum InputState {
|
|
||||||
#[default]
|
|
||||||
World,
|
|
||||||
Menu,
|
|
||||||
Detached,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(SystemSet, Debug, Clone, PartialEq, Eq, Hash)]
|
|
||||||
pub struct PlayerInputSystems;
|
|
||||||
|
|
||||||
#[derive(States, Debug, Default, Clone, PartialEq, Eq, Hash)]
|
|
||||||
pub enum PlayerState {
|
|
||||||
#[default]
|
|
||||||
OnFoot,
|
|
||||||
FreeFloating,
|
|
||||||
Piloting,
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user