Skip to content

Commit

Permalink
v0.2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
AldaronLau committed Jul 30, 2019
1 parent a1003f2 commit b1d5a38
Show file tree
Hide file tree
Showing 9 changed files with 128 additions and 48 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@
All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
and this project adheres to [Semantic Versioning](https://free.plopgrizzly.com/semver/).

## [Unreleased]
### Added
### Removed
### Changed
### Fixed

## [0.2.1] - 2019-05-13
### Fixed
- L & R triggers on controllers always returning 0.

## [0.2.0] - 2019-05-12
### Added
- Joystick / controller support with API for emulation (not complete yet).
Expand Down
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

[package]
name = "cala"
version = "0.2.0"
version = "0.2.1"
authors = ["Jeron Aldaron Lau <[email protected]>"]
edition = "2018"

Expand All @@ -25,4 +25,4 @@ whoami = "0.5" # user
wavy = "0.1" # audio
stronghold = "0.2" # file
serde = "1.0"
stick = "0.5" # joystick / controller
stick = "0.6" # joystick / controller
51 changes: 51 additions & 0 deletions QUALITY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Quality
To ensure the quality of the crate, we use some helpers:

```bash
# Install tool `cargo fmt`
rustup component add rustfmt

# Install tool `cargo clippy`
rustup component add clippy

## # Install tool `cargo semver`
## rustup toolchain add nightly
## cargo +nightly install semverver

# Install tool `cargo geiger`
cargo install cargo-geiger

# Install tool `cargo outdated`
cargo install cargo-outdated
```

## Commit
First, run these commands:

```
# Mandatory
cargo fmt
cargo clippy
cargo outdated
# Fun
cargo geiger
```

If clippy doesn't print out anything, then do these commands:

```
git add .
git commit
git push
```

## Publish
After a commit meant for publish, do:

```
cargo outdated
# cargo semver
cargo package
```

Only if no warnings or errors are found, do `cargo publish`.
2 changes: 1 addition & 1 deletion examples/controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use cala::*;
fn main() {
let mut app = App::new(());

let layout = cala::ControllerLayout::new().joy(false).abxy(false);
let layout = cala::ControllerLayout::new().joy(false).lrt(false).abxy(false);

loop {
for id in 0..app.controller_update() {
Expand Down
4 changes: 2 additions & 2 deletions examples/monitoring.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
use cala::*;

use std::collections::VecDeque;

fn main() {
let mut app = App::new(());

let mut buffer = VecDeque::new();

loop {
// Record some sound.
app.record(&mut |_whichmic, l, r| {
Expand Down
4 changes: 2 additions & 2 deletions src/audio.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pub use wavy::AudioSample;
pub use wavy::MicrophoneSystem;
pub use wavy::SpeakerSystem;
pub use wavy::SampleRate;
pub use wavy::AudioSample;
pub use wavy::SpeakerSystem;
50 changes: 37 additions & 13 deletions src/controller.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
pub(crate) use stick::Port as ControllerPort;
pub(crate) use stick::Btn;
pub(crate) use stick::Port as ControllerPort;

pub(crate) enum Axis {
JoyXY,
Expand Down Expand Up @@ -65,7 +65,9 @@ impl ControllerLayout {
/// Request an x & y axis for main joystick.
pub fn joy(mut self, optional: bool) -> Self {
// Don't do twice!
if self.joy.is_some() { return self; }
if self.joy.is_some() {
return self;
}

self.joy = Some(optional);
self.axis.push(Axis::JoyXY);
Expand All @@ -75,7 +77,9 @@ impl ControllerLayout {
/// Request an x & y axis for camera (secondary) joystick.
pub fn cam(mut self, optional: bool) -> Self {
// Don't do twice!
if self.cam.is_some() { return self; }
if self.cam.is_some() {
return self;
}

self.cam = Some(optional);
self.axis.push(Axis::CamXY);
Expand All @@ -85,7 +89,9 @@ impl ControllerLayout {
/// Request an x & y axis for camera (secondary) joystick.
pub fn lrt(mut self, optional: bool) -> Self {
// Don't do twice!
if self.lrt.is_some() { return self; }
if self.lrt.is_some() {
return self;
}

self.cam = Some(optional);
self.axis.push(Axis::Lrt);
Expand All @@ -95,7 +101,9 @@ impl ControllerLayout {
/// Request an axis for pitch (stationary throttle).
pub fn pitch(mut self, optional: bool) -> Self {
// Don't do twice!
if self.pitch.is_some() { return self; }
if self.pitch.is_some() {
return self;
}

self.pitch = Some(optional);
self.axis.push(Axis::Pitch);
Expand All @@ -105,7 +113,9 @@ impl ControllerLayout {
/// Request an axis for yaw (stationary throttle).
pub fn yaw(mut self, optional: bool) -> Self {
// Don't do twice!
if self.yaw.is_some() { return self; }
if self.yaw.is_some() {
return self;
}

self.yaw = Some(optional);
self.axis.push(Axis::Yaw);
Expand All @@ -114,7 +124,9 @@ impl ControllerLayout {

/// Request ABXY buttons.
pub fn abxy(mut self, optional: bool) -> Self {
if self.abxy.is_some() { return self; }
if self.abxy.is_some() {
return self;
}

self.abxy = Some(optional);
self.btns.push(Btns::Abxy);
Expand All @@ -123,7 +135,9 @@ impl ControllerLayout {

/// Request arrow buttons.
pub fn arrow(mut self, optional: bool) -> Self {
if self.dpad.is_some() { return self; }
if self.dpad.is_some() {
return self;
}

self.dpad = Some(optional);
self.btns.push(Btns::Dpad);
Expand All @@ -132,7 +146,9 @@ impl ControllerLayout {

/// Request Back button.
pub fn back(mut self, optional: bool) -> Self {
if self.quit.is_some() { return self; }
if self.quit.is_some() {
return self;
}

self.quit = Some(optional);
self.btns.push(Btns::Quit);
Expand All @@ -141,7 +157,9 @@ impl ControllerLayout {

/// Request Menu button.
pub fn menu(mut self, optional: bool) -> Self {
if self.menu.is_some() { return self; }
if self.menu.is_some() {
return self;
}

self.menu = Some(optional);
self.btns.push(Btns::Menu);
Expand All @@ -150,7 +168,9 @@ impl ControllerLayout {

/// Request W & Z buttons.
pub fn wz(mut self, optional: bool) -> Self {
if self.wz.is_some() { return self; }
if self.wz.is_some() {
return self;
}

self.wz = Some(optional);
self.btns.push(Btns::Wz);
Expand All @@ -159,7 +179,9 @@ impl ControllerLayout {

/// Request D & C buttons (Push in joystick).
pub fn dc(mut self, optional: bool) -> Self {
if self.cd.is_some() { return self; }
if self.cd.is_some() {
return self;
}

self.cd = Some(optional);
self.btns.push(Btns::Dc);
Expand All @@ -168,7 +190,9 @@ impl ControllerLayout {

/// Request L & R buttons.
pub fn lrb(mut self, optional: bool) -> Self {
if self.lrb.is_some() { return self; }
if self.lrb.is_some() {
return self;
}

self.lrb = Some(optional);
self.btns.push(Btns::Lr);
Expand Down
41 changes: 21 additions & 20 deletions src/dive.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::user::*;
use crate::audio::*;
use crate::controller::*;
use crate::user::*;

/// The Dive Application Context.
pub struct App<T> {
Expand Down Expand Up @@ -45,14 +45,16 @@ impl<T> App<T> {

/// Fetch a resource.
pub fn fetch<U>(&mut self, res: &str) -> Option<U>
where for<'de> U: serde::Deserialize<'de>
where
for<'de> U: serde::Deserialize<'de>,
{
stronghold::fetch(res)
}

/// Load file `res` from `zip`.
pub fn open(&mut self, zip: &str, res: &str) -> Option<()>
where for<'de> T: serde::Deserialize<'de>
where
for<'de> T: serde::Deserialize<'de>,
{
self.file = stronghold::load(zip, res)?;
Some(())
Expand All @@ -65,7 +67,8 @@ impl<T> App<T> {

/// Save file `res` in `zip` only if `edit()` has been called since last change.
pub fn sync(&mut self, zip: &str, res: &str)
where T: serde::Serialize
where
T: serde::Serialize,
{
if self.changed {
stronghold::save(zip, res, &self.file);
Expand Down Expand Up @@ -103,41 +106,39 @@ impl<T> App<T> {
i_axis += 1;
self.axis[i_axis] = y;
i_axis += 1;
},
}
Axis::CamXY => {
// TODO: Fallback.
let (x, y) = state.cam().unwrap_or((0.0, 0.0));
self.axis[i_axis] = x;
i_axis += 1;
self.axis[i_axis] = y;
i_axis += 1;
},
}
Axis::Lrt => {
// TODO: Fallback.
// let (x, y) = state.lr().unwrap_or((0.0, 0.0));
// TODO: Not supported yet.
let (x, y) = (0.0, 0.0);
let (x, y) = state.lrt().unwrap_or((0.0, 0.0));
self.axis[i_axis] = x;
i_axis += 1;
self.axis[i_axis] = y;
i_axis += 1;
},
}
Axis::Pitch => {
// TODO: Fallback.
let x = state.pitch().unwrap_or(0.0);
self.axis[i_axis] = x;
i_axis += 1;
},
}
Axis::Yaw => {
// let x = state.yaw().unwrap_or(0.0);
// let x = state.yaw().unwrap_or(0.0);
// TODO: Not supported yet.
self.axis[i_axis] = 0.0;
i_axis += 1;
},
}
}
}

for btn in 0..layout.btns.len() {
for btn in 0..layout.btns.len() {
match layout.btns[btn] {
Btns::Abxy => {
self.btns[i_btns] = state.btn(Btn::A).unwrap_or(false);
Expand All @@ -148,7 +149,7 @@ impl<T> App<T> {
i_btns += 1;
self.btns[i_btns] = state.btn(Btn::Y).unwrap_or(false);
i_btns += 1;
},
}
Btns::Dpad => {
self.btns[i_btns] = state.btn(Btn::Up).unwrap_or(false);
i_btns += 1;
Expand All @@ -158,27 +159,27 @@ impl<T> App<T> {
i_btns += 1;
self.btns[i_btns] = state.btn(Btn::Right).unwrap_or(false);
i_btns += 1;
},
}
Btns::Quit => {
self.btns[i_btns] = state.btn(Btn::E).unwrap_or(false);
i_btns += 1;
},
}
Btns::Menu => {
self.btns[i_btns] = state.btn(Btn::F).unwrap_or(false);
i_btns += 1;
},
}
Btns::Wz => {
self.btns[i_btns] = state.btn(Btn::W).unwrap_or(false);
i_btns += 1;
self.btns[i_btns] = state.btn(Btn::Z).unwrap_or(false);
i_btns += 1;
},
}
Btns::Lr => {
self.btns[i_btns] = state.btn(Btn::L).unwrap_or(false);
i_btns += 1;
self.btns[i_btns] = state.btn(Btn::R).unwrap_or(false);
i_btns += 1;
},
}
Btns::Dc => {
self.btns[i_btns] = state.btn(Btn::D).unwrap_or(false);
i_btns += 1;
Expand Down
Loading

0 comments on commit b1d5a38

Please sign in to comment.