Skip to content

Commit

Permalink
Merge pull request #32 from hyoi/split_crate
Browse files Browse the repository at this point in the history
Split crate
  • Loading branch information
hyoi authored Apr 6, 2024
2 parents e0edaf9 + e31c73b commit db81523
Show file tree
Hide file tree
Showing 56 changed files with 598 additions and 498 deletions.
27 changes: 26 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,28 @@
[workspace]
resolver = "2"
members = [ "tigtag", "macros", "macros_inside" ]
members = [ "crates/tigtag" ]

[workspace.package]
version = "0.13.0"
edition = "2021"

[workspace.dependencies]
#bevy = { git = "https://github.com/bevyengine/bevy" } #Master branch
bevy = "0.13"
once_cell = "1"
rand = "0.8"
chrono = "0.4"

syn = "2"
quote = "1"
proc-macro2 = "1"

tigtag_inside = { path = "crates/tigtag_inside" }
share = { path = "crates/share" }
macros = { path = "crates/macros" }
macros_inside = { path = "crates/macros_inside" }

# WASMの場合にどれか指定する必要がある??
# rand = { version = "0.8.4", features = [ "wasm-bindgen" ] }
# getrandom = { version = "0.2.4", features = [ "js" ] }
# getrandom = { version = "0.2.4", features = [ "wasm-bindgen" ] }
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ Note: Japanese text only.
SEが実装されています。音量要注意っ (≧ω≦;)

## WASM版
[https://hyoi.github.io/tigtag/tigtag/](https://hyoi.github.io/tigtag/tigtag/)
※Rustのworkspaceで作業するとディレクトリの切り方にセンス問われるな‥‥
[https://hyoi.github.io/tigtag/](https://hyoi.github.io/tigtag/)

## 操作方法

Expand Down Expand Up @@ -39,7 +38,7 @@ cargo run -r
※コマンドライン引数に書くディレクトリーは作業環境に合わせてください
```
cargo build -r --target wasm32-unknown-unknown
wasm-bindgen --out-dir .\tigtag\wasm --target web --no-typescript .\target\wasm32-unknown-unknown\release\tigtag.wasm
wasm-bindgen --out-dir .\wasm --target web --no-typescript .\target\wasm32-unknown-unknown\release\tigtag.wasm
```
- WASMのコンパイルには事前にRustのtarget追加とwasm-bindgenのインストールが必要です
- wasm-bindgenを実行するとバージョン違いの警告が出ることがあります。その時はバージョン上げましょう
Expand All @@ -58,7 +57,7 @@ cargo install -f wasm-bindgen-cli
- [Orbitron](https://fonts.google.com/specimen/Orbitron)
- [Reggae One](https://fonts.google.com/specimen/Reggae+One)
- [ドット絵ダウンロードサイト DOTOWN](https://dotown.maeda-design-room.net/)
- Rustだから蟹 <img src="./tigtag/assets/image/sprite/kani_DOTOWN.png" width="22" height="16" style="vertical-align: bottom;">
- Rustだから蟹 <img src="./assets/image/sprite/kani_DOTOWN.png" width="22" height="16" style="vertical-align: bottom;">

## 宿題
- [ ] スマホでプレーできるようにしたい。
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
6 changes: 3 additions & 3 deletions macros/Cargo.toml → crates/macros/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
[package]
name = "macros"
version = "0.1.0"
edition = "2021"
version.workspace = true
edition.workspace = true

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[lib]
proc-macro = true

[dependencies]
macros_inside = { path = "../macros_inside" }
macros_inside.workspace = true
File renamed without changes.
10 changes: 5 additions & 5 deletions macros_inside/Cargo.toml → crates/macros_inside/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
[package]
name = "macros_inside"
version = "0.1.0"
edition = "2021"
version.workspace = true
edition.workspace = true

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
syn = "2.0"
quote = "1.0"
proc-macro2 = "1.0"
syn.workspace = true
quote.workspace = true
proc-macro2.workspace = true
File renamed without changes.
15 changes: 15 additions & 0 deletions crates/share/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[package]
name = "share"
version.workspace = true
edition.workspace = true

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
bevy.workspace = true
once_cell.workspace = true

macros.workspace = true

[features]
sprite_sheet_off = [] # cargo run --features sprite_sheet_off
39 changes: 23 additions & 16 deletions tigtag/src/public/config.rs → crates/share/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use super::*;
////////////////////////////////////////////////////////////////////////////////

//アプリの情報
pub const APP_TITLE: &str = CARGO_TOML_NAME; //アプリタイトル
pub const APP_VER : &str = CARGO_TOML_VER; //アプリのバージョン
pub const APP_TITLE: &str = "TigTag"; //アプリタイトル
pub const APP_VER : &str = CARGO_TOML_VER; //アプリのバージョン

//単位Gridの縦横(Pixel)
const BASE_PIXELS: i32 = 8;
Expand Down Expand Up @@ -87,9 +87,9 @@ pub const CAMERA_POSITION_DEFAULT_2D: Vec3 = Vec3::new
////////////////////////////////////////////////////////////////////////////////

//極座標カメラの設定
pub const CAMERA_ORBIT_INIT_R : f32 = 6.0; //初期値
pub const CAMERA_ORBIT_INIT_THETA: f32 = PI * 0.6; //初期値(ラジアン) 1.0:天頂、0.5:真横、0.0:真下
pub const CAMERA_ORBIT_INIT_PHI : f32 = PI * 1.8; //初期値(ラジアン) 6時方向が0.0で反時計回り
pub const CAMERA_ORBIT_INIT_R : f32 = 6.0; //初期値
pub const CAMERA_ORBIT_INIT_THETA: f32 = PI * 0.6; //初期値(ラジアン) 1.0:天頂、0.5:真横、0.0:真下
pub const CAMERA_ORBIT_INIT_PHI : f32 = TAU * 0.9; //初期値(ラジアン) 6時方向が0.0で反時計回り

pub const CAMERA_ORBIT_MAX_R : f32 = 50.0; //rの最大値
pub const CAMERA_ORBIT_MIN_R : f32 = 1.0; //rの最小値
Expand All @@ -110,24 +110,31 @@ pub const DEPTH_SPRITE_BRICK_WALL : f32 = 400.0; //ゲームの壁スプライ

////////////////////////////////////////////////////////////////////////////////

//assetsのパスのつじつま合わせ
#[cfg( target_arch = "wasm32" )]
macro_rules! ASSETS_PATH { () => ( "" ) }

#[cfg( not( target_arch = "wasm32" ) )]
macro_rules! ASSETS_PATH { () => ( "../../../assets/" ) }

//assets(スプライト)
pub const ASSETS_SPRITE_KANI_DOTOWN: &str = "image/sprite/kani_DOTOWN.png";
pub const ASSETS_SPRITE_BRICK_WALL : &str = "image/sprite/brick_wall.png";
pub const ASSETS_SPRITE_KANI_DOTOWN: &str = concat!( ASSETS_PATH!(), "image/sprite/kani_DOTOWN.png" );
pub const ASSETS_SPRITE_BRICK_WALL : &str = concat!( ASSETS_PATH!(), "image/sprite/brick_wall.png" );

//assets(スプライトシート)
pub const ASSETS_SPRITE_SHEET_PLAYER : &str = "image/sprite_sheet/player.png";
pub const ASSETS_SPRITE_SHEET_CHASER_RED : &str = "image/sprite_sheet/chaser_red.png";
pub const ASSETS_SPRITE_SHEET_CHASER_GREEN: &str = "image/sprite_sheet/chaser_green.png";
pub const ASSETS_SPRITE_SHEET_CHASER_BLUE : &str = "image/sprite_sheet/chaser_blue.png";
pub const ASSETS_SPRITE_SHEET_CHASER_PINK : &str = "image/sprite_sheet/chaser_pink.png";
pub const ASSETS_SPRITE_SHEET_PLAYER : &str = concat!( ASSETS_PATH!(), "image/sprite_sheet/player.png" );
pub const ASSETS_SPRITE_SHEET_CHASER_RED : &str = concat!( ASSETS_PATH!(), "image/sprite_sheet/chaser_red.png" );
pub const ASSETS_SPRITE_SHEET_CHASER_GREEN: &str = concat!( ASSETS_PATH!(), "image/sprite_sheet/chaser_green.png" );
pub const ASSETS_SPRITE_SHEET_CHASER_BLUE : &str = concat!( ASSETS_PATH!(), "image/sprite_sheet/chaser_blue.png" );
pub const ASSETS_SPRITE_SHEET_CHASER_PINK : &str = concat!( ASSETS_PATH!(), "image/sprite_sheet/chaser_pink.png" );

//assets(フォント)
pub const ASSETS_FONT_ORBITRON_BLACK : &str = "font/Orbitron-Black.ttf";
pub const ASSETS_FONT_PRESSSTART2P_REGULAR: &str = "font/PressStart2P-Regular.ttf";
pub const ASSETS_FONT_REGGAEONE_REGULAR : &str = "font/ReggaeOne-Regular.ttf";
pub const ASSETS_FONT_ORBITRON_BLACK : &str = concat!( ASSETS_PATH!(), "font/Orbitron-Black.ttf" );
pub const ASSETS_FONT_PRESSSTART2P_REGULAR: &str = concat!( ASSETS_PATH!(), "font/PressStart2P-Regular.ttf" );
pub const ASSETS_FONT_REGGAEONE_REGULAR : &str = concat!( ASSETS_PATH!(), "font/ReggaeOne-Regular.ttf" );

//assets(サウンド)
pub const ASSETS_SOUND_BEEP: &str = "audio/sound/beep.ogg";
pub const ASSETS_SOUND_BEEP: &str = concat!( ASSETS_PATH!(), "audio/sound/beep.ogg" );

//事前ロード対象
pub const PRELOAD_ASSETS: &[ &str ] =
Expand Down
30 changes: 30 additions & 0 deletions crates/share/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//external crates
use bevy::
{ prelude::*,
window::WindowMode,
ecs::query::QueryFilter,
};
use once_cell::sync::Lazy;

//standard library
use std::
{ ops::Range,
f32::consts::{ PI, TAU },
};

//proc-macro crates
use macros::MyState;

//アプリの設定
mod config;
pub use config::*;

//型定義
mod types;
pub use types::*;

//ユーティリティ
pub mod misc;
pub use misc::constants::*; //定数は名前を公開

//End of code.
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
////////////////////////////////////////////////////////////////////////////////

//アプリの情報
pub const CARGO_TOML_NAME: &str = env!( "CARGO_PKG_NAME" );
pub const CARGO_TOML_VER : &str = env!( "CARGO_PKG_VERSION" );
// pub const CARGO_TOML_NAME: &str = env!( "CARGO_PKG_NAME" ); //shareになってしまう
pub const CARGO_TOML_VER: &str = env!( "CARGO_PKG_VERSION" );

////////////////////////////////////////////////////////////////////////////////

Expand Down
File renamed without changes.
File renamed without changes.
20 changes: 20 additions & 0 deletions tigtag/src/public/types.rs → crates/share/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ impl MyState
{ pub fn is_demoplay( &self ) -> bool { self.is_titledemo() || self.is_demoloop() }
}

//InitAppの後の遷移先を登録するResource
#[derive( Resource )]
pub struct AfterInitApp ( pub MyState );
impl ChangeMyState for AfterInitApp
{ fn state( &self ) -> MyState { self.0 }
}

////////////////////////////////////////////////////////////////////////////////

//操作を受付けるgamepadのIDを保存するResource
Expand Down Expand Up @@ -129,4 +136,17 @@ impl SquarePlane

////////////////////////////////////////////////////////////////////////////////

//隠しノードのComponent
#[derive( Component )] pub struct HiddenNode;

//ヘッダー/フッターのComponent
#[derive( Component )] pub struct UiHeaderLeft; //日時表示
#[derive( Component )] pub struct UiHeaderCenter; //タイトル
#[derive( Component )] pub struct UiHeaderRight; //経過時間表示
#[derive( Component )] pub struct UiFooterLeft; //FPS表示
#[derive( Component )] pub struct UiFooterCenter; //auther
#[derive( Component )] pub struct UiFooterRight; //Powered by

////////////////////////////////////////////////////////////////////////////////

//End of code.
13 changes: 13 additions & 0 deletions crates/tigtag/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[package]
name = "tigtag"
version.workspace = true
edition.workspace = true

[dependencies]
bevy.workspace = true
once_cell.workspace = true
rand.workspace = true
chrono.workspace = true

tigtag_inside.workspace = true
share.workspace = true
File renamed without changes.
20 changes: 1 addition & 19 deletions tigtag/src/init_app.rs → crates/tigtag/src/init_app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,24 +61,6 @@ impl Plugin for Schedule

////////////////////////////////////////////////////////////////////////////////

//InitAppの後の遷移先を登録するResource
#[derive( Resource )]
pub struct AfterInitApp ( pub MyState );
impl ChangeMyState for AfterInitApp
{ fn state( &self ) -> MyState { self.0 }
}

//隠しノードのComponent
#[derive( Component )] pub struct HiddenNode;

//ヘッダー/フッターのComponent
#[derive( Component )] pub struct UiHeaderLeft; //日時表示
#[derive( Component )] pub struct UiHeaderCenter; //タイトル
#[derive( Component )] pub struct UiHeaderRight; //経過時間表示
#[derive( Component )] pub struct UiFooterLeft; //FPS表示
#[derive( Component )] pub struct UiFooterCenter; //auther
#[derive( Component )] pub struct UiFooterRight; //Powered by

//ヘッダー/フッターのテキスト情報
const HEADER_LEFT: &[ MessageSect ] =
&[ ( " Clock ", ASSETS_FONT_ORBITRON_BLACK , PIXELS_PER_GRID * 0.6, Color::TEAL ),
Expand All @@ -100,7 +82,7 @@ const FOOTER_LEFT: &[ MessageSect ] =
];

const FOOTER_CENTER: &[ MessageSect ] =
&[ ( "hyoi 2023 - XXXX", ASSETS_FONT_ORBITRON_BLACK, PIXELS_PER_GRID * 0.6, Color::TEAL ),
&[ ( "hyoi 2021 - 2024", ASSETS_FONT_ORBITRON_BLACK, PIXELS_PER_GRID * 0.6, Color::TEAL ),
];

const FOOTER_RIGHT: &[ MessageSect ] =
Expand Down
File renamed without changes.
27 changes: 4 additions & 23 deletions tigtag/src/main.rs → crates/tigtag/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,44 +2,25 @@
use bevy::
{ prelude::*,
log::LogPlugin,
window::WindowMode,
render::camera::ClearColorConfig,
input::mouse::{ MouseMotion, MouseWheel },
asset::{ LoadState, LoadedUntypedAsset },
diagnostic::{ FrameTimeDiagnosticsPlugin, DiagnosticsStore },
utils::Duration,
ecs::query::QueryFilter,
//=============================================================
sprite::MaterialMesh2dBundle,
utils::{ HashMap, HashSet },
audio::Volume,
input::keyboard::NativeKeyCode,
};
use once_cell::sync::Lazy;
use rand::prelude::*;

//standard library
use std::
{ ops::Range,
f32::consts::{ PI, TAU },
//=========================
ops::{ Add, AddAssign },
cmp::Ordering,
collections::VecDeque,
};
use std::f32::consts::TAU;

//proc-macro crates
use macros::MyState;
//import names from other crates in this package
use share::*;
use tigtag_inside as play_game;

//internal submodules
mod public;
use public::*;

mod debug;

mod load_assets;
mod init_app;
mod play_game;

////////////////////////////////////////////////////////////////////////////////

Expand Down
13 changes: 13 additions & 0 deletions crates/tigtag_inside/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[package]
name = "tigtag_inside"
version.workspace = true
edition.workspace = true

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
bevy.workspace = true
once_cell.workspace = true
rand.workspace = true

share.workspace = true
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const PLACE_HOLDER_DEMO_RECORD: usize = 3; //text.sections[ 3 ]

//フッターのUIを改造する
fn add_sections_to_footerleft
( mut qry_text: Query<&mut Text, With<init_app::UiFooterLeft>>,
( mut qry_text: Query<&mut Text, With<UiFooterLeft>>,
asset_svr: Res<AssetServer>,
)
{ let Ok ( mut text ) = qry_text.get_single_mut() else { return };
Expand All @@ -49,7 +49,7 @@ fn add_sections_to_footerleft

//UIの表示を更新する(demo record)
fn update_demo_record
( mut qry_text: Query<&mut Text, With<init_app::UiFooterLeft>>,
( mut qry_text: Query<&mut Text, With<UiFooterLeft>>,
opt_record: Option<ResMut<Record>>,
)
{ let Ok ( mut text ) = qry_text.get_single_mut() else { return };
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit db81523

Please sign in to comment.