Compare commits
4 Commits
4a0257324e
...
bb173b47e3
Author | SHA1 | Date |
---|---|---|
an | bb173b47e3 | |
an | 68bfd417b5 | |
an | 133b80ae38 | |
an | e58f5d8907 |
|
@ -180,7 +180,7 @@ macro_rules! rd_impl {
|
|||
/// argument. The function's result has the `?` operator applied to it,
|
||||
/// unless `OPTS` is `no_try`.
|
||||
/// - `OPT`, if not one of the things listed above, may be `enum TYPE` to apply
|
||||
/// `TryFrom<TYPE>`, or `flag TYPE` to apply a bitfield made by `bitflags!`.
|
||||
/// `TryFrom<TYPE>`, or `flag TYPE` to apply a bitfield made by `c_bitfield!`.
|
||||
/// - `INDEX` is either an integer literal which must be representable as
|
||||
/// `usize`, or a range with the syntax `INDEX; SIZE` denoting the beginning
|
||||
/// and size of the range.
|
||||
|
|
|
@ -0,0 +1,88 @@
|
|||
#![doc(hidden)]
|
||||
|
||||
/// A wrapper for `bitflags!` which adds a `FromStr` implementation.
|
||||
#[macro_export]
|
||||
macro_rules! c_bitfield
|
||||
{
|
||||
(
|
||||
$(#[$outer:meta])*
|
||||
pub struct $t:ident: $ti:ty {
|
||||
$(
|
||||
$(#[$inner:ident $($args:tt)*])*
|
||||
$f:ident = $v:expr
|
||||
),+
|
||||
$(,)?
|
||||
}
|
||||
) => {
|
||||
bitflags! {
|
||||
$(#[$outer])*
|
||||
pub struct $t: $ti {
|
||||
$(
|
||||
$(#[$inner $($args)*])*
|
||||
const $f = 1 << $v;
|
||||
)+
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(unused_qualifications)]
|
||||
impl std::str::FromStr for $t
|
||||
{
|
||||
type Err = $crate::err::ParseFlagError;
|
||||
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err>
|
||||
{
|
||||
let mut flags = $t::empty();
|
||||
|
||||
for s in s.split('|') {
|
||||
match s {
|
||||
$(
|
||||
stringify!($f) => flags.insert($t::$f),
|
||||
)+
|
||||
"(none)" => (),
|
||||
_ => return Err(Self::Err::new(stringify!($t)))
|
||||
}
|
||||
}
|
||||
|
||||
Ok(flags)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test
|
||||
{
|
||||
use crate::err::ParseFlagError;
|
||||
use std::str::FromStr;
|
||||
|
||||
c_bitfield! {
|
||||
pub struct TestFlag: u16 {
|
||||
ZERO = 0,
|
||||
ONE = 1,
|
||||
TWO = 2,
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn c_bitfield()
|
||||
{
|
||||
assert_eq!(TestFlag::from_bits(0), Some(TestFlag::empty()));
|
||||
assert_eq!(TestFlag::from_bits(1), Some(TestFlag::ZERO));
|
||||
assert_eq!(TestFlag::from_bits(2), Some(TestFlag::ONE));
|
||||
assert_eq!(TestFlag::from_bits(4), Some(TestFlag::TWO));
|
||||
assert_eq!(TestFlag::from_bits(8), None);
|
||||
assert_eq!(TestFlag::from_str("(none)"), Ok(TestFlag::empty()));
|
||||
assert_eq!(TestFlag::from_str("ZERO"), Ok(TestFlag::ZERO));
|
||||
assert_eq!(TestFlag::from_str("ONE"), Ok(TestFlag::ONE));
|
||||
assert_eq!(TestFlag::from_str("TWO"), Ok(TestFlag::TWO));
|
||||
assert_eq!(TestFlag::from_str("ZERO|ONE|TWO"), Ok(TestFlag::all()));
|
||||
assert_eq!(TestFlag::from_str("TWO|ZERO|ONE"), Ok(TestFlag::all()));
|
||||
assert_eq!(TestFlag::from_str("ONE|ONE|ONE"), Ok(TestFlag::ONE));
|
||||
assert_eq!(TestFlag::from_str("(none)|(none)"), Ok(TestFlag::empty()));
|
||||
assert_eq!(TestFlag::from_str("(none)|ONE"), Ok(TestFlag::ONE));
|
||||
assert_eq!(TestFlag::from_str("THREE"),
|
||||
Err(ParseFlagError::new("TestFlag")));
|
||||
}
|
||||
}
|
||||
|
||||
// EOF
|
|
@ -3,8 +3,8 @@
|
|||
/// Creates an enumeration and function for converting a representation into the
|
||||
/// enumeration type.
|
||||
///
|
||||
/// The syntax is similar to the `bitflags` macro, but each value has the syntax
|
||||
/// `value = enumeration`. `enum` is used instead of `struct`.
|
||||
/// The syntax is similar to the `c_bitfield` macro, but each value has the
|
||||
/// syntax `value = enumeration`. `enum` is used instead of `struct`.
|
||||
///
|
||||
/// This will generate an `enum $t` as well as implement `TryFrom` on it which
|
||||
/// will return `Result<$t, ReprError>`.
|
||||
|
@ -26,25 +26,31 @@
|
|||
/// assert_eq!(MyEnum::try_from(0), Ok(MyEnum::Zero));
|
||||
/// assert_eq!(MyEnum::try_from(1), Ok(MyEnum::One));
|
||||
/// assert_eq!(MyEnum::try_from(2), Ok(MyEnum::Two));
|
||||
/// assert_eq!(MyEnum::try_from(3), Err(ReprError::new(3)));
|
||||
/// assert_eq!(MyEnum::try_from(4), Err(ReprError::new(4)));
|
||||
/// assert_eq!(MyEnum::try_from(5), Err(ReprError::new(5)));
|
||||
/// assert_eq!(MyEnum::try_from(3), Err(ReprError::new("MyEnum", 3)));
|
||||
/// assert_eq!(MyEnum::try_from(4), Err(ReprError::new("MyEnum", 4)));
|
||||
/// assert_eq!(MyEnum::try_from(5), Err(ReprError::new("MyEnum", 5)));
|
||||
/// ```
|
||||
#[macro_export]
|
||||
macro_rules! c_enum
|
||||
{
|
||||
(
|
||||
$(#[$outer:meta])*
|
||||
$vi:vis enum $t:ident: $ti:ident
|
||||
{
|
||||
$($(#[$vouter:meta])* $en:ident = $va:expr),+ $(,)?
|
||||
$vi:vis enum $t:ident: $ti:ident {
|
||||
$(
|
||||
$(#[$inner:meta])*
|
||||
$en:ident = $va:expr
|
||||
),+
|
||||
$(,)?
|
||||
}
|
||||
) => {
|
||||
$(#[$outer])*
|
||||
#[derive(Copy, Clone, Debug, Eq, Ord, PartialEq, PartialOrd)]
|
||||
#[repr($ti)]
|
||||
$vi enum $t {
|
||||
$($(#[$vouter])* $en = $va,)+
|
||||
$(
|
||||
$(#[$inner])*
|
||||
$en = $va,
|
||||
)+
|
||||
}
|
||||
|
||||
#[allow(unused_qualifications)]
|
||||
|
@ -61,14 +67,30 @@ macro_rules! c_enum
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(unused_qualifications)]
|
||||
impl std::str::FromStr for $t
|
||||
{
|
||||
type Err = $crate::err::ParseEnumError;
|
||||
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err>
|
||||
{
|
||||
match s {
|
||||
$(
|
||||
stringify!($en) => Ok($t::$en),
|
||||
)+
|
||||
_ => Err(Self::Err::new(stringify!($t)))
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test
|
||||
{
|
||||
use crate::err::ReprError;
|
||||
use std::convert::TryFrom;
|
||||
use crate::err::{ParseEnumError, ReprError};
|
||||
use std::{convert::TryFrom, str::FromStr};
|
||||
|
||||
c_enum! {
|
||||
enum TestEnum: u16 {
|
||||
|
@ -79,19 +101,20 @@ mod test
|
|||
}
|
||||
|
||||
#[test]
|
||||
fn c_enum_should_be_ok()
|
||||
fn c_enum()
|
||||
{
|
||||
assert_eq!(TestEnum::try_from(0), Ok(TestEnum::Zero));
|
||||
assert_eq!(TestEnum::try_from(1), Ok(TestEnum::One));
|
||||
assert_eq!(TestEnum::try_from(2), Ok(TestEnum::Two));
|
||||
assert_eq!(TestEnum::try_from(3), Err(ReprError::new(3)));
|
||||
assert_eq!(TestEnum::try_from(4), Err(ReprError::new(4)));
|
||||
assert_eq!(TestEnum::try_from(5), Err(ReprError::new(5)));
|
||||
assert_eq!(TestEnum::try_from(3), Err(ReprError::new("TestEnum", 3)));
|
||||
assert_eq!(TestEnum::try_from(4), Err(ReprError::new("TestEnum", 4)));
|
||||
assert_eq!(TestEnum::try_from(5), Err(ReprError::new("TestEnum", 5)));
|
||||
assert_eq!(TestEnum::from_str("Zero"), Ok(TestEnum::Zero));
|
||||
assert_eq!(TestEnum::from_str("One"), Ok(TestEnum::One));
|
||||
assert_eq!(TestEnum::from_str("Two"), Ok(TestEnum::Two));
|
||||
assert_eq!(TestEnum::from_str("Three"),
|
||||
Err(ParseEnumError::new("TestEnum")));
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic]
|
||||
fn c_enum_should_error() {TestEnum::try_from(3).unwrap();}
|
||||
}
|
||||
|
||||
// EOF
|
||||
|
|
|
@ -53,6 +53,42 @@ macro_rules! backtrace {
|
|||
/// ```
|
||||
pub fn err_msg(msg: &'static str) -> Error {ErrMsg(msg).into()}
|
||||
|
||||
impl ParseEnumError
|
||||
{
|
||||
/// Returns an `Error` with a message for enumeration parsing errata.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// use maraiah::err::ParseEnumError;
|
||||
///
|
||||
/// assert_eq!(format!("{}", ParseEnumError::new("TypeName")),
|
||||
/// "could not parse TypeName");
|
||||
/// ```
|
||||
pub fn new(t: &'static str) -> Self
|
||||
{
|
||||
Self(t)
|
||||
}
|
||||
}
|
||||
|
||||
impl ParseFlagError
|
||||
{
|
||||
/// Returns an `Error` with a message for flag parsing errata.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// use maraiah::err::ParseFlagError;
|
||||
///
|
||||
/// assert_eq!(format!("{}", ParseFlagError::new("TypeName")),
|
||||
/// "could not parse TypeName");
|
||||
/// ```
|
||||
pub fn new(t: &'static str) -> Self
|
||||
{
|
||||
Self(t)
|
||||
}
|
||||
}
|
||||
|
||||
impl ReprError
|
||||
{
|
||||
/// Returns an `Error` with a message for representation errata.
|
||||
|
@ -60,9 +96,9 @@ impl ReprError
|
|||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// use maraiah::err::repr_error;
|
||||
/// use maraiah::err::ReprError;
|
||||
///
|
||||
/// assert_eq!(format!("{}", repr_error("TypeName", 77)),
|
||||
/// assert_eq!(format!("{}", ReprError::new("TypeName", 77)),
|
||||
/// "bad TypeName (77)");
|
||||
/// ```
|
||||
pub fn new<T: Into<i64>>(t: &'static str, n: T) -> Self
|
||||
|
@ -71,8 +107,26 @@ impl ReprError
|
|||
}
|
||||
}
|
||||
|
||||
impl Fail for ReprError {}
|
||||
impl Fail for ErrMsg {}
|
||||
impl Fail for ParseEnumError {}
|
||||
impl Fail for ParseFlagError {}
|
||||
impl Fail for ReprError {}
|
||||
|
||||
impl fmt::Display for ParseEnumError
|
||||
{
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result
|
||||
{
|
||||
write!(f, "could not parse {}", self.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for ParseFlagError
|
||||
{
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result
|
||||
{
|
||||
write!(f, "could not parse {}", self.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for ReprError
|
||||
{
|
||||
|
@ -90,13 +144,21 @@ impl fmt::Display for ErrMsg
|
|||
}
|
||||
}
|
||||
|
||||
/// A representation error for an integer.
|
||||
#[derive(Debug, Eq, Ord, PartialEq, PartialOrd)]
|
||||
pub struct ReprError(&'static str, i64);
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Clone, Debug)]
|
||||
struct ErrMsg(&'static str);
|
||||
|
||||
/// A parser error for an enumeration.
|
||||
#[derive(Clone, Debug, Eq, Ord, PartialEq, PartialOrd)]
|
||||
pub struct ParseEnumError(&'static str);
|
||||
|
||||
/// A parser error for a bit field.
|
||||
#[derive(Clone, Debug, Eq, Ord, PartialEq, PartialOrd)]
|
||||
pub struct ParseFlagError(&'static str);
|
||||
|
||||
/// A representation error for an integer.
|
||||
#[derive(Clone, Debug, Eq, Ord, PartialEq, PartialOrd)]
|
||||
pub struct ReprError(&'static str, i64);
|
||||
|
||||
/// A generic `failure` based `Result` type.
|
||||
pub type ResultS<T> = Result<T, Error>;
|
||||
|
||||
|
|
|
@ -63,16 +63,14 @@
|
|||
#![deny(clippy::use_self)]
|
||||
#![deny(clippy::used_underscore_binding)]
|
||||
|
||||
#[macro_use]
|
||||
mod doc;
|
||||
#[macro_use]
|
||||
pub mod ffi;
|
||||
#[macro_use]
|
||||
pub mod err;
|
||||
#[macro_use]
|
||||
mod cenum;
|
||||
#[macro_use]
|
||||
pub mod bin;
|
||||
#[macro_use] extern crate bitflags;
|
||||
|
||||
#[macro_use] mod cbitfield;
|
||||
#[macro_use] mod cenum;
|
||||
#[macro_use] mod doc;
|
||||
#[macro_use] pub mod err;
|
||||
#[macro_use] pub mod ffi;
|
||||
#[macro_use] pub mod bin;
|
||||
|
||||
pub mod bit;
|
||||
pub mod cksum;
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
//! `SoundRand` type.
|
||||
|
||||
use crate::{err::*, fixed::{Angle, Fixed}};
|
||||
use bitflags::bitflags;
|
||||
|
||||
/// Reads a `bonk` chunk.
|
||||
pub fn read(b: &[u8]) -> ResultS<(SoundRand, usize)>
|
||||
|
@ -41,12 +40,12 @@ pub struct SoundRand {
|
|||
pub pit_dta: Fixed,
|
||||
}
|
||||
|
||||
bitflags! {
|
||||
c_bitfield! {
|
||||
/// Flags for `SoundRand`.
|
||||
#[cfg_attr(feature = "serde_obj", derive(serde::Serialize))]
|
||||
pub struct SoundRandFlags: u16 {
|
||||
const NO_DIRECTION = 1;
|
||||
const _2 = 2;
|
||||
NO_DIRECTION = 0,
|
||||
_2 = 1,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
//! `Damage` type.
|
||||
|
||||
use crate::{err::*, fixed::Fixed};
|
||||
use bitflags::bitflags;
|
||||
|
||||
/// Reads a `Damage` object.
|
||||
pub fn read(b: &[u8]) -> ResultS<Damage>
|
||||
|
@ -30,42 +29,42 @@ pub struct Damage {
|
|||
pub scale: Fixed,
|
||||
}
|
||||
|
||||
bitflags! {
|
||||
c_bitfield! {
|
||||
/// The composite type of damage taken by something.
|
||||
#[cfg_attr(feature = "serde_obj", derive(serde::Serialize))]
|
||||
pub struct DamageTypeFlags: u32 {
|
||||
const EXPLOSION = 1;
|
||||
const ELECTRICAL_STAFF = 1 << 1;
|
||||
const PROJECTILE = 1 << 2;
|
||||
const ABSORBED = 1 << 3;
|
||||
const FLAME = 1 << 4;
|
||||
const HOUND_CLAWS = 1 << 5;
|
||||
const ALIEN_PROJECTILE = 1 << 6;
|
||||
const HULK_SLAP = 1 << 7;
|
||||
const COMPILER_BOLT = 1 << 8;
|
||||
const FUSION_BOLT = 1 << 9;
|
||||
const HUNTER_BOLT = 1 << 10;
|
||||
const FIST = 1 << 11;
|
||||
const TELEPORTER = 1 << 12;
|
||||
const DEFENDER = 1 << 13;
|
||||
const YETI_CLAWS = 1 << 14;
|
||||
const YETI_PROJECTILE = 1 << 15;
|
||||
const CRUSHING = 1 << 16;
|
||||
const LAVA = 1 << 17;
|
||||
const SUFFOCATION = 1 << 18;
|
||||
const GOO = 1 << 19;
|
||||
const ENERGY_DRAIN = 1 << 20;
|
||||
const OXYGEN_DRAIN = 1 << 21;
|
||||
const HUMMER_BOLT = 1 << 22;
|
||||
const SHOTGUN_PROJECTILE = 1 << 23;
|
||||
EXPLOSION = 0,
|
||||
ELECTRICAL_STAFF = 1,
|
||||
PROJECTILE = 2,
|
||||
ABSORBED = 3,
|
||||
FLAME = 4,
|
||||
HOUND_CLAWS = 5,
|
||||
ALIEN_PROJECTILE = 6,
|
||||
HULK_SLAP = 7,
|
||||
COMPILER_BOLT = 8,
|
||||
FUSION_BOLT = 9,
|
||||
HUNTER_BOLT = 10,
|
||||
FIST = 11,
|
||||
TELEPORTER = 12,
|
||||
DEFENDER = 13,
|
||||
YETI_CLAWS = 14,
|
||||
YETI_PROJECTILE = 15,
|
||||
CRUSHING = 16,
|
||||
LAVA = 17,
|
||||
SUFFOCATION = 18,
|
||||
GOO = 19,
|
||||
ENERGY_DRAIN = 20,
|
||||
OXYGEN_DRAIN = 21,
|
||||
HUMMER_BOLT = 22,
|
||||
SHOTGUN_PROJECTILE = 23,
|
||||
}
|
||||
}
|
||||
|
||||
bitflags! {
|
||||
c_bitfield! {
|
||||
/// Flags for `Damage`.
|
||||
#[cfg_attr(feature = "serde_obj", derive(serde::Serialize))]
|
||||
pub struct DamageFlags: u16 {
|
||||
const ALIEN = 1;
|
||||
ALIEN = 0,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
use super::pnts;
|
||||
use crate::{err::*, fixed::Unit};
|
||||
use bitflags::bitflags;
|
||||
|
||||
/// Reads an `EPNT` chunk.
|
||||
pub fn read(b: &[u8]) -> ResultS<(Endpoint, usize)>
|
||||
|
@ -37,13 +36,13 @@ pub struct Endpoint {
|
|||
pub support: u16,
|
||||
}
|
||||
|
||||
bitflags! {
|
||||
c_bitfield! {
|
||||
/// Flags for `Endpoint`.
|
||||
#[cfg_attr(feature = "serde_obj", derive(serde::Serialize))]
|
||||
pub struct EndpointFlags: u16 {
|
||||
const SOLID = 1;
|
||||
const SAME_HEIGHT = 1 << 1;
|
||||
const TRANSPARENT = 1 << 2;
|
||||
SOLID = 0,
|
||||
SAME_HEIGHT = 1,
|
||||
TRANSPARENT = 2,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
//! `Effect` type.
|
||||
|
||||
use crate::{bin::OptU16, err::*, fixed::Fixed};
|
||||
use bitflags::bitflags;
|
||||
|
||||
/// Reads a `FXpx` chunk.
|
||||
pub fn read(b: &[u8]) -> ResultS<(Effect, usize)>
|
||||
|
@ -32,15 +31,15 @@ pub struct Effect {
|
|||
pub delay_snd: OptU16,
|
||||
}
|
||||
|
||||
bitflags! {
|
||||
c_bitfield! {
|
||||
/// Flags for an effect.
|
||||
#[cfg_attr(feature = "serde_obj", derive(serde::Serialize))]
|
||||
pub struct EffectFlags: u16 {
|
||||
const END_ON_LOOP = 1;
|
||||
const END_ON_XFER_LOOP = 1 << 1;
|
||||
const SOUND_ONLY = 1 << 2;
|
||||
const MAKE_TWIN_VISIBLE = 1 << 3;
|
||||
const MEDIA_EFFECT = 1 << 4;
|
||||
END_ON_LOOP = 0,
|
||||
END_ON_XFER_LOOP = 1,
|
||||
SOUND_ONLY = 2,
|
||||
MAKE_TWIN_VISIBLE = 3,
|
||||
MEDIA_EFFECT = 4,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
//! `Line` type.
|
||||
|
||||
use crate::{bin::OptU16, err::*};
|
||||
use bitflags::bitflags;
|
||||
|
||||
/// Reads a `LINS` chunk.
|
||||
pub fn read(b: &[u8]) -> ResultS<(Line, usize)>
|
||||
|
@ -34,16 +33,16 @@ pub struct Line {
|
|||
pub poly_bk: OptU16,
|
||||
}
|
||||
|
||||
bitflags! {
|
||||
c_bitfield! {
|
||||
/// Flags for `Line`.
|
||||
#[cfg_attr(feature = "serde_obj", derive(serde::Serialize))]
|
||||
pub struct LineFlags: u16 {
|
||||
const TRANS_SIDE = 1 << 9;
|
||||
const ELEV_VAR = 1 << 10;
|
||||
const ELEVATION = 1 << 11;
|
||||
const LANDSCAPE = 1 << 12;
|
||||
const TRANSPARENT = 1 << 13;
|
||||
const SOLID = 1 << 14;
|
||||
TRANS_SIDE = 9,
|
||||
ELEV_VAR = 10,
|
||||
ELEVATION = 11,
|
||||
LANDSCAPE = 12,
|
||||
TRANSPARENT = 13,
|
||||
SOLID = 14,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
use super::{ltfn, TICKS_PER_SECOND};
|
||||
use crate::{err::*, fixed::Fixed};
|
||||
use bitflags::bitflags;
|
||||
|
||||
/// Reads a `LITE` chunk.
|
||||
pub fn read(b: &[u8]) -> ResultS<(Light, usize)>
|
||||
|
@ -86,13 +85,13 @@ pub struct Light {
|
|||
pub tag: u16,
|
||||
}
|
||||
|
||||
bitflags! {
|
||||
c_bitfield! {
|
||||
/// Flags for `Light`.
|
||||
#[cfg_attr(feature = "serde_obj", derive(serde::Serialize))]
|
||||
pub struct LightFlags: u16 {
|
||||
const INIT_ACTIVE = 1;
|
||||
const SLAVE_VALUE = 1 << 1;
|
||||
const STATELESS = 1 << 2;
|
||||
INIT_ACTIVE = 0,
|
||||
SLAVE_VALUE = 1,
|
||||
STATELESS = 2,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -5,7 +5,6 @@ use crate::{bin::OptU16,
|
|||
err::*,
|
||||
fixed::{Angle, Fixed, Unit},
|
||||
xfer::TransferMode};
|
||||
use bitflags::bitflags;
|
||||
|
||||
/// Reads a `medi` chunk.
|
||||
pub fn read(b: &[u8]) -> ResultS<(Media, usize)>
|
||||
|
@ -61,11 +60,11 @@ c_enum! {
|
|||
}
|
||||
}
|
||||
|
||||
bitflags! {
|
||||
c_bitfield! {
|
||||
/// Flags for `Media`.
|
||||
#[cfg_attr(feature = "serde_obj", derive(serde::Serialize))]
|
||||
pub struct MediaFlags: u8 {
|
||||
const OBSTRUCT = 1;
|
||||
OBSTRUCT = 0,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
//! `Info` type.
|
||||
|
||||
use crate::{err::*, text::*};
|
||||
use bitflags::bitflags;
|
||||
|
||||
/// Reads a `Minf` chunk.
|
||||
pub fn read(b: &[u8]) -> ResultS<Info>
|
||||
|
@ -81,51 +80,51 @@ pub struct Info {
|
|||
pub level_name: String,
|
||||
}
|
||||
|
||||
bitflags! {
|
||||
c_bitfield! {
|
||||
/// Static environment flags.
|
||||
#[cfg_attr(feature = "serde_obj", derive(serde::Serialize))]
|
||||
pub struct EnvironmentFlags: u16 {
|
||||
const VACUUM = 1;
|
||||
const MAGNETIC = 1 << 1;
|
||||
const REBELLION = 1 << 2;
|
||||
const LOW_GRAV = 1 << 3;
|
||||
const M1_GLUE = 1 << 4;
|
||||
const LAVA_FLOOR = 1 << 5;
|
||||
const REBELLION2 = 1 << 6;
|
||||
const MUSIC = 1 << 7;
|
||||
const TERM_PAUSE = 1 << 8;
|
||||
const M1_MONSTER = 1 << 9;
|
||||
const M1_WEPS = 1 << 10;
|
||||
VACUUM = 0,
|
||||
MAGNETIC = 1,
|
||||
REBELLION = 2,
|
||||
LOW_GRAV = 3,
|
||||
M1_GLUE = 4,
|
||||
LAVA_FLOOR = 5,
|
||||
REBELLION2 = 6,
|
||||
MUSIC = 7,
|
||||
TERM_PAUSE = 8,
|
||||
M1_MONSTER = 9,
|
||||
M1_WEPS = 10,
|
||||
}
|
||||
}
|
||||
|
||||
bitflags! {
|
||||
c_bitfield! {
|
||||
/// Static entry point flags.
|
||||
#[cfg_attr(feature = "serde_obj", derive(serde::Serialize))]
|
||||
pub struct EntryFlags: u32 {
|
||||
const SOLO = 1;
|
||||
const CO_OP = 1 << 1;
|
||||
const CARNAGE = 1 << 2;
|
||||
const KTMWTB = 1 << 3;
|
||||
const KOTH = 1 << 4;
|
||||
const DEFENSE = 1 << 5;
|
||||
const RUGBY = 1 << 6;
|
||||
const CTF = 1 << 7;
|
||||
SOLO = 0,
|
||||
CO_OP = 1,
|
||||
CARNAGE = 2,
|
||||
KTMWTB = 3,
|
||||
KOTH = 4,
|
||||
DEFENSE = 5,
|
||||
RUGBY = 6,
|
||||
CTF = 7,
|
||||
}
|
||||
}
|
||||
|
||||
bitflags! {
|
||||
c_bitfield! {
|
||||
/// Static mission flags.
|
||||
#[cfg_attr(feature = "serde_obj", derive(serde::Serialize))]
|
||||
pub struct MissionFlags: u16 {
|
||||
const EXTERMINATION = 1;
|
||||
const EXPLORATION = 1 << 1;
|
||||
const RETRIEVAL = 1 << 2;
|
||||
const REPAIR = 1 << 3;
|
||||
const RESCUE = 1 << 4;
|
||||
const M1_EXPLORATION = 1 << 5;
|
||||
const M1_RESCUE = 1 << 6;
|
||||
const M1_REPAIR = 1 << 7;
|
||||
EXTERMINATION = 0,
|
||||
EXPLORATION = 1,
|
||||
RETRIEVAL = 2,
|
||||
REPAIR = 3,
|
||||
RESCUE = 4,
|
||||
M1_EXPLORATION = 5,
|
||||
M1_RESCUE = 6,
|
||||
M1_REPAIR = 7,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
//! `Monster` type.
|
||||
|
||||
use crate::{bin::OptU16, err::*, fixed::{Fixed, Unit}};
|
||||
use bitflags::bitflags;
|
||||
|
||||
use super::{attk, damg};
|
||||
|
||||
|
@ -140,61 +139,61 @@ pub struct Monster {
|
|||
pub atk_range: attk::Attack,
|
||||
}
|
||||
|
||||
bitflags! {
|
||||
c_bitfield! {
|
||||
/// Flags for a monster.
|
||||
#[cfg_attr(feature = "serde_obj", derive(serde::Serialize))]
|
||||
pub struct MonsterFlags: u32 {
|
||||
const IGNORE_LOS = 1;
|
||||
const FLYING = 1 << 1;
|
||||
const ALIEN = 1 << 2;
|
||||
const MAJOR = 1 << 3;
|
||||
const MINOR = 1 << 4;
|
||||
const NO_OMIT = 1 << 5;
|
||||
const FLOATS = 1 << 6;
|
||||
const NO_ATTACK = 1 << 7;
|
||||
const SNIPE = 1 << 8;
|
||||
const INVISIBLE = 1 << 9;
|
||||
const SUBTLY_INVISIBLE = 1 << 10;
|
||||
const KAMIKAZE = 1 << 11;
|
||||
const BERSERKER = 1 << 12;
|
||||
const ENLARGED = 1 << 13;
|
||||
const DELAYED_DEATH = 1 << 14;
|
||||
const FIRE_SYMMETRICAL = 1 << 15;
|
||||
const NUCLEAR_DEATH = 1 << 16;
|
||||
const NO_FIRE_BACKWARDS = 1 << 17;
|
||||
const CAN_DIE_IN_FLAMES = 1 << 18;
|
||||
const WAIT_FOR_GOOD_SHOT = 1 << 19;
|
||||
const TINY = 1 << 20;
|
||||
const FAST_ATTACK = 1 << 21;
|
||||
const LIKES_WATER = 1 << 22;
|
||||
const LIKES_SEWAGE = 1 << 23;
|
||||
const LIKES_LAVA = 1 << 24;
|
||||
const LIKES_GOO = 1 << 25;
|
||||
const TELE_UNDER_MEDIA = 1 << 26;
|
||||
const USE_RANDOM_WEAPON = 1 << 27;
|
||||
IGNORE_LOS = 0,
|
||||
FLYING = 1,
|
||||
ALIEN = 2,
|
||||
MAJOR = 3,
|
||||
MINOR = 4,
|
||||
NO_OMIT = 5,
|
||||
FLOATS = 6,
|
||||
NO_ATTACK = 7,
|
||||
SNIPE = 8,
|
||||
INVISIBLE = 9,
|
||||
SUBTLY_INVISIBLE = 10,
|
||||
KAMIKAZE = 11,
|
||||
BERSERKER = 12,
|
||||
ENLARGED = 13,
|
||||
DELAYED_DEATH = 14,
|
||||
FIRE_SYMMETRICAL = 15,
|
||||
NUCLEAR_DEATH = 16,
|
||||
NO_FIRE_BACKWARDS = 17,
|
||||
CAN_DIE_IN_FLAMES = 18,
|
||||
WAIT_FOR_GOOD_SHOT = 19,
|
||||
TINY = 20,
|
||||
FAST_ATTACK = 21,
|
||||
LIKES_WATER = 22,
|
||||
LIKES_SEWAGE = 23,
|
||||
LIKES_LAVA = 24,
|
||||
LIKES_GOO = 25,
|
||||
TELE_UNDER_MEDIA = 26,
|
||||
USE_RANDOM_WEAPON = 27,
|
||||
}
|
||||
}
|
||||
|
||||
bitflags! {
|
||||
c_bitfield! {
|
||||
/// The composite type of a monster.
|
||||
#[cfg_attr(feature = "serde_obj", derive(serde::Serialize))]
|
||||
pub struct MonsterClass: u32 {
|
||||
const PLAYER = 1;
|
||||
const CIVILIAN = 1 << 1;
|
||||
const MADD = 1 << 2;
|
||||
const POSSESSED_HUMMER = 1 << 3;
|
||||
const DEFENDER = 1 << 4;
|
||||
const FIGHTER = 1 << 5;
|
||||
const TROOPER = 1 << 6;
|
||||
const HUNTER = 1 << 7;
|
||||
const ENFORCER = 1 << 8;
|
||||
const JUGGERNAUT = 1 << 9;
|
||||
const HUMMER = 1 << 10;
|
||||
const COMPILER = 1 << 11;
|
||||
const CYBORG = 1 << 12;
|
||||
const ASSIMILATED = 1 << 13;
|
||||
const TICK = 1 << 14;
|
||||
const YETI = 1 << 15;
|
||||
PLAYER = 0,
|
||||
CIVILIAN = 1,
|
||||
MADD = 2,
|
||||
POSSESSED_HUMMER = 3,
|
||||
DEFENDER = 4,
|
||||
FIGHTER = 5,
|
||||
TROOPER = 6,
|
||||
HUNTER = 7,
|
||||
ENFORCER = 8,
|
||||
JUGGERNAUT = 9,
|
||||
HUMMER = 10,
|
||||
COMPILER = 11,
|
||||
CYBORG = 12,
|
||||
ASSIMILATED = 13,
|
||||
TICK = 14,
|
||||
YETI = 15,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
//! `Object` type.
|
||||
|
||||
use crate::{err::*, fixed::{Angle, Unit}};
|
||||
use bitflags::bitflags;
|
||||
|
||||
/// Reads an `OBJS` chunk.
|
||||
pub fn read(b: &[u8]) -> ResultS<(Object, usize)>
|
||||
|
@ -42,16 +41,16 @@ pub struct Object {
|
|||
pub bias: u16,
|
||||
}
|
||||
|
||||
bitflags! {
|
||||
c_bitfield! {
|
||||
/// Flags for `Object`.
|
||||
#[cfg_attr(feature = "serde_obj", derive(serde::Serialize))]
|
||||
pub struct ObjectFlags: u16 {
|
||||
const INVISIBLE = 1;
|
||||
const CEILING = 1 << 1;
|
||||
const BLIND = 1 << 2;
|
||||
const DEAF = 1 << 3;
|
||||
const FLOATING = 1 << 4;
|
||||
const NET_ONLY = 1 << 5;
|
||||
INVISIBLE = 0,
|
||||
CEILING = 1,
|
||||
BLIND = 2,
|
||||
DEAF = 3,
|
||||
FLOATING = 4,
|
||||
NET_ONLY = 5,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
//! `ObjectFreq` type.
|
||||
|
||||
use crate::err::*;
|
||||
use bitflags::bitflags;
|
||||
|
||||
/// Reads a `plac` chunk.
|
||||
pub fn read(b: &[u8]) -> ResultS<(ObjectFreq, usize)>
|
||||
|
@ -32,15 +31,15 @@ pub struct ObjectFreq {
|
|||
pub chance: u16,
|
||||
}
|
||||
|
||||
bitflags! {
|
||||
c_bitfield! {
|
||||
/// Flags for `ObjectFreq`.
|
||||
#[cfg_attr(feature = "serde_obj", derive(serde::Serialize))]
|
||||
pub struct ObjectFreqFlags: u16 {
|
||||
const RANDOM_LOCATION = 1;
|
||||
const _3 = 1 << 3;
|
||||
const _4 = 1 << 4;
|
||||
const _5 = 1 << 5;
|
||||
const _6 = 1 << 6;
|
||||
RANDOM_LOCATION = 0,
|
||||
_3 = 3,
|
||||
_4 = 4,
|
||||
_5 = 5,
|
||||
_6 = 6,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
//! `Platform` type.
|
||||
|
||||
use crate::{err::*, fixed::Unit};
|
||||
use bitflags::bitflags;
|
||||
|
||||
/// Reads a `plat` chunk.
|
||||
pub fn read(b: &[u8]) -> ResultS<(Platform, usize)>
|
||||
|
@ -36,37 +35,37 @@ pub struct Platform {
|
|||
pub tag: u16,
|
||||
}
|
||||
|
||||
bitflags! {
|
||||
c_bitfield! {
|
||||
/// Flags for `Platform`.
|
||||
#[cfg_attr(feature = "serde_obj", derive(serde::Serialize))]
|
||||
pub struct PlatformFlags: u32 {
|
||||
const INIT_ACTIVE = 1;
|
||||
const INIT_EXTENDED = 1 << 1;
|
||||
const STOP_AT_EACH_LEVEL = 1 << 2;
|
||||
const STOP_AT_INIT_LEVEL = 1 << 3;
|
||||
const START_ADJ_ON_STOP = 1 << 4;
|
||||
const EXTENDS_FLOOR_TO_CEIL = 1 << 5;
|
||||
const COMES_FROM_FLOOR = 1 << 6;
|
||||
const COMES_FROM_CEIL = 1 << 7;
|
||||
const CAUSES_DAMAGE = 1 << 8;
|
||||
const NO_ACTIVATE_PARENT = 1 << 9;
|
||||
const ACTIVATES_ONCE = 1 << 10;
|
||||
const ACTIVATES_LIGHT = 1 << 11;
|
||||
const DEACTIVATES_LIGHT = 1 << 12;
|
||||
const PLAYER_CONTROLS = 1 << 13;
|
||||
const MONSTER_CONTROLS = 1 << 14;
|
||||
const REVERSE_ON_OBSTRUCT = 1 << 15;
|
||||
const NO_EXT_DEACTIVATION = 1 << 16;
|
||||
const USE_POLYGON_HEIGHTS = 1 << 17;
|
||||
const DELAYED_ACTIVATION = 1 << 18;
|
||||
const START_ADJ_ON_START = 1 << 19;
|
||||
const STOP_ADJ_ON_START = 1 << 20;
|
||||
const STOP_ADJ_ON_STOP = 1 << 21;
|
||||
const SLOW = 1 << 22;
|
||||
const START_AT_EACH_LEVEL = 1 << 23;
|
||||
const LOCKED = 1 << 24;
|
||||
const SECRET = 1 << 25;
|
||||
const DOOR = 1 << 26;
|
||||
INIT_ACTIVE = 0,
|
||||
INIT_EXTENDED = 1,
|
||||
STOP_AT_EACH_LEVEL = 2,
|
||||
STOP_AT_INIT_LEVEL = 3,
|
||||
START_ADJ_ON_STOP = 4,
|
||||
EXTENDS_FLOOR_TO_CEIL = 5,
|
||||
COMES_FROM_FLOOR = 6,
|
||||
COMES_FROM_CEIL = 7,
|
||||
CAUSES_DAMAGE = 8,
|
||||
NO_ACTIVATE_PARENT = 9,
|
||||
ACTIVATES_ONCE = 10,
|
||||
ACTIVATES_LIGHT = 11,
|
||||
DEACTIVATES_LIGHT = 12,
|
||||
PLAYER_CONTROLS = 13,
|
||||
MONSTER_CONTROLS = 14,
|
||||
REVERSE_ON_OBSTRUCT = 15,
|
||||
NO_EXT_DEACTIVATION = 16,
|
||||
USE_POLYGON_HEIGHTS = 17,
|
||||
DELAYED_ACTIVATION = 18,
|
||||
START_ADJ_ON_START = 19,
|
||||
STOP_ADJ_ON_START = 20,
|
||||
STOP_ADJ_ON_STOP = 21,
|
||||
SLOW = 22,
|
||||
START_AT_EACH_LEVEL = 23,
|
||||
LOCKED = 24,
|
||||
SECRET = 25,
|
||||
DOOR = 26,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
use super::pnts;
|
||||
use crate::{bin::OptU16, err::*, fixed::Unit, xfer::TransferMode};
|
||||
use bitflags::bitflags;
|
||||
|
||||
/// Reads a polygon for either M1 or M2.
|
||||
pub fn read_poly_inter(b: &[u8]) -> ResultS<Polygon>
|
||||
|
@ -180,11 +179,11 @@ pub enum PolygonType {
|
|||
GlueSuper,
|
||||
}
|
||||
|
||||
bitflags! {
|
||||
c_bitfield! {
|
||||
/// Flags for `Polygon`.
|
||||
#[cfg_attr(feature = "serde_obj", derive(serde::Serialize))]
|
||||
pub struct PolygonFlags: u16 {
|
||||
const DETACHED = 1 << 14;
|
||||
DETACHED = 14,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
//! `Projectile` type.
|
||||
|
||||
use crate::{bin::OptU16, err::*, fixed::{Fixed, Unit}};
|
||||
use bitflags::bitflags;
|
||||
|
||||
use super::damg;
|
||||
|
||||
|
@ -58,32 +57,32 @@ pub struct Projectile {
|
|||
pub snd_bounce: OptU16,
|
||||
}
|
||||
|
||||
bitflags! {
|
||||
c_bitfield! {
|
||||
/// Flags for a projectile.
|
||||
#[cfg_attr(feature = "serde_obj", derive(serde::Serialize))]
|
||||
pub struct ProjectileFlags: u32 {
|
||||
const GUIDED = 1;
|
||||
const STOP_ON_LOOP = 1 << 1;
|
||||
const PERSISTENT = 1 << 2;
|
||||
const ALIEN = 1 << 3;
|
||||
const GRAVITY = 1 << 4;
|
||||
const NO_HORZ_ERROR = 1 << 5;
|
||||
const NO_VERT_ERROR = 1 << 6;
|
||||
const TOGGLE_PANELS = 1 << 7;
|
||||
const POS_VERT_ERROR = 1 << 8;
|
||||
const MELEE = 1 << 9;
|
||||
const RIPPER = 1 << 10;
|
||||
const PASS_TRANS_RANDOM = 1 << 11;
|
||||
const PASS_TRANS_MORE = 1 << 12;
|
||||
const DOUBLE_GRAVITY = 1 << 13;
|
||||
const REBOUND_FLOOR = 1 << 14;
|
||||
const THROUGH_MEDIA = 1 << 15;
|
||||
const BECOME_ITEM = 1 << 16;
|
||||
const BLOODY = 1 << 17;
|
||||
const WANDER_HORZ = 1 << 18;
|
||||
const WANDER_VERT = 1 << 19;
|
||||
const USE_LOW_GRAV = 1 << 20;
|
||||
const PASS_MEDIA = 1 << 21;
|
||||
GUIDED = 0,
|
||||
STOP_ON_LOOP = 1,
|
||||
PERSISTENT = 2,
|
||||
ALIEN = 3,
|
||||
GRAVITY = 4,
|
||||
NO_HORZ_ERROR = 5,
|
||||
NO_VERT_ERROR = 6,
|
||||
TOGGLE_PANELS = 7,
|
||||
POS_VERT_ERROR = 8,
|
||||
MELEE = 9,
|
||||
RIPPER = 10,
|
||||
PASS_TRANS_RANDOM = 11,
|
||||
PASS_TRANS_MORE = 12,
|
||||
DOUBLE_GRAVITY = 13,
|
||||
REBOUND_FLOOR = 14,
|
||||
THROUGH_MEDIA = 15,
|
||||
BECOME_ITEM = 16,
|
||||
BLOODY = 17,
|
||||
WANDER_HORZ = 18,
|
||||
WANDER_VERT = 19,
|
||||
USE_LOW_GRAV = 20,
|
||||
PASS_MEDIA = 21,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
use super::stex;
|
||||
use crate::{bin::OptU16, err::*, fixed::Fixed, xfer::TransferMode};
|
||||
use bitflags::bitflags;
|
||||
|
||||
/// Reads a `SIDS` chunk.
|
||||
pub fn read(b: &[u8]) -> ResultS<(Side, usize)>
|
||||
|
@ -55,18 +54,18 @@ pub struct Side {
|
|||
pub shade: Fixed,
|
||||
}
|
||||
|
||||
bitflags! {
|
||||
c_bitfield! {
|
||||
/// Flags for `Side`.
|
||||
#[cfg_attr(feature = "serde_obj", derive(serde::Serialize))]
|
||||
pub struct SideFlags: u8 {
|
||||
const STATUS = 1;
|
||||
const PANEL = 1 << 1;
|
||||
const REPAIR = 1 << 2;
|
||||
const ITEM_USE = 1 << 3;
|
||||
const LIGHTED = 1 << 4;
|
||||
const CAN_DESTROY = 1 << 5;
|
||||
const HIT_ONLY = 1 << 6;
|
||||
const ITEM_OPT = 1 << 7;
|
||||
STATUS = 0,
|
||||
PANEL = 1,
|
||||
REPAIR = 2,
|
||||
ITEM_USE = 3,
|
||||
LIGHTED = 4,
|
||||
CAN_DESTROY = 5,
|
||||
HIT_ONLY = 6,
|
||||
ITEM_OPT = 7,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
//! `Group` type.
|
||||
|
||||
use crate::err::*;
|
||||
use bitflags::bitflags;
|
||||
|
||||
/// Reads an `InterGroup`.
|
||||
pub fn read(b: &[u8]) -> ResultS<(InterGroup, usize)>
|
||||
|
@ -89,14 +88,14 @@ pub enum GroupType {
|
|||
Tag(u16),
|
||||
}
|
||||
|
||||
bitflags! {
|
||||
c_bitfield! {
|
||||
/// Flags for `Group`.
|
||||
#[cfg_attr(feature = "serde_obj", derive(serde::Serialize))]
|
||||
pub struct GroupFlags: u16 {
|
||||
/// Draws the picture on the right.
|
||||
const DRAW_ON_RIGHT = 1;
|
||||
DRAW_ON_RIGHT = 0,
|
||||
/// Draws the picture in the center.
|
||||
const DRAW_CENTER = 1 << 1;
|
||||
DRAW_CENTER = 1,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
//! `Weapon` type.
|
||||
|
||||
use crate::{bin::OptU16, err::*, fixed::Fixed};
|
||||
use bitflags::bitflags;
|
||||
|
||||
use super::trig;
|
||||
|
||||
|
@ -76,21 +75,21 @@ pub struct Weapon {
|
|||
pub wid_idle: Fixed,
|
||||
}
|
||||
|
||||
bitflags! {
|
||||
c_bitfield! {
|
||||
/// Flags for a weapon.
|
||||
#[cfg_attr(feature = "serde_obj", derive(serde::Serialize))]
|
||||
pub struct WeaponFlags: u16 {
|
||||
const AUTOMATIC = 1;
|
||||
const REMOVE_AFTER_USE = 1 << 1;
|
||||
const INSTANT_CASING = 1 << 2;
|
||||
const OVERLOADS = 1 << 3;
|
||||
const RANDOM_AMMO = 1 << 4;
|
||||
const TEMPORARY_POWER = 1 << 5;
|
||||
const RELOAD_ONE_HAND = 1 << 6;
|
||||
const FIRE_OUT_OF_PHASE = 1 << 7;
|
||||
const FIRE_UNDER_MEDIA = 1 << 8;
|
||||
const TRIGGER_SAME_AMMO = 1 << 9;
|
||||
const SECONDARY_FLIP = 1 << 10;
|
||||
AUTOMATIC = 0,
|
||||
REMOVE_AFTER_USE = 1,
|
||||
INSTANT_CASING = 2,
|
||||
OVERLOADS = 3,
|
||||
RANDOM_AMMO = 4,
|
||||
TEMPORARY_POWER = 5,
|
||||
RELOAD_ONE_HAND = 6,
|
||||
FIRE_OUT_OF_PHASE = 7,
|
||||
FIRE_UNDER_MEDIA = 8,
|
||||
TRIGGER_SAME_AMMO = 9,
|
||||
SECONDARY_FLIP = 10,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
use crate::{err::*, image::Image};
|
||||
use super::clut;
|
||||
use bitflags::bitflags;
|
||||
|
||||
/// Reads a `Bitmap`.
|
||||
pub fn read(b: &[u8]) -> ResultS<Bitmap>
|
||||
|
@ -130,10 +129,10 @@ pub struct ImageShp<'a, 'b> {
|
|||
clut: &'b [clut::ColorShp],
|
||||
}
|
||||
|
||||
bitflags! {
|
||||
struct BmpFlags: u16 {
|
||||
const TRANSPARENT = 1 << 14;
|
||||
const COLUMN_MAJOR = 1 << 15;
|
||||
c_bitfield! {
|
||||
pub struct BmpFlags: u16 {
|
||||
TRANSPARENT = 14,
|
||||
COLUMN_MAJOR = 15,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
//! Shapes file frame type.
|
||||
|
||||
use crate::{err::*, fixed::*};
|
||||
use bitflags::bitflags;
|
||||
|
||||
/// Reads a `Frame`.
|
||||
pub fn read(b: &[u8]) -> ResultS<Frame>
|
||||
|
@ -55,16 +54,16 @@ pub struct Frame {
|
|||
pub wrl_y: Unit,
|
||||
}
|
||||
|
||||
bitflags! {
|
||||
c_bitfield! {
|
||||
/// Flags for `Frame`.
|
||||
#[cfg_attr(feature = "serde_obj", derive(serde::Serialize))]
|
||||
pub struct FrameFlags: u16 {
|
||||
/// The player's torso will obscure the player's legs.
|
||||
const OBSCURE = 1 << 13;
|
||||
OBSCURE = 13,
|
||||
/// The bitmap will be flipped on the vertical axis.
|
||||
const FLIP_Y = 1 << 14;
|
||||
FLIP_Y = 14,
|
||||
/// The bitmap will be flipped on the horizontal axis.
|
||||
const FLIP_X = 1 << 15;
|
||||
FLIP_X = 15,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
//! Sounds format definition type.
|
||||
|
||||
use crate::{bin::{u32b, usize_from_u32}, err::*, fixed::*, sound::Sound16};
|
||||
use bitflags::bitflags;
|
||||
|
||||
/// Reads a sound definition.
|
||||
pub fn read(b: &[u8]) -> ResultS<Option<(Vec<usize>, u16, SoundDef)>>
|
||||
|
@ -63,24 +62,24 @@ pub struct SoundDef {
|
|||
pub sounds: Vec<Sound16>,
|
||||
}
|
||||
|
||||
bitflags! {
|
||||
c_bitfield! {
|
||||
/// Flags for `SoundDef`.
|
||||
#[cfg_attr(feature = "serde_obj", derive(serde::Serialize))]
|
||||
pub struct SoundFlags: u16 {
|
||||
/// The sound will not restart when trying to play over itself.
|
||||
const NO_RESTART = 1;
|
||||
NO_RESTART = 0,
|
||||
/// The sound will not switch channels when trying to play over itself.
|
||||
const NO_CHANNEL_SWITCH = 1 << 1;
|
||||
NO_CHANNEL_SWITCH = 1,
|
||||
/// The pitch variance will be halved.
|
||||
const LESS_PITCH_CHANGE = 1 << 2;
|
||||
LESS_PITCH_CHANGE = 2,
|
||||
/// The pitch variance will be nullified.
|
||||
const NO_PITCH_CHANGE = 1 << 3;
|
||||
NO_PITCH_CHANGE = 3,
|
||||
/// The sound will play even when completely obstructed by walls.
|
||||
const NO_OBSTRUCTION = 1 << 4;
|
||||
NO_OBSTRUCTION = 4,
|
||||
/// The sound will play even when completely obstructed by media.
|
||||
const NO_MEDIA_OBSTRUCT = 1 << 5;
|
||||
NO_MEDIA_OBSTRUCT = 5,
|
||||
/// The sound will have special stereo effects.
|
||||
const AMBIENT = 1 << 6;
|
||||
AMBIENT = 6,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -12,9 +12,9 @@ MapModel::~MapModel()
|
|||
dbgPrintFunc();
|
||||
}
|
||||
|
||||
ProjectModel::Type MapModel::type() const
|
||||
ProjectModelType MapModel::type() const
|
||||
{
|
||||
return ProjectModel::Map;
|
||||
return ProjectModelType::Map;
|
||||
}
|
||||
|
||||
bool MapModel::isDirty() const
|
||||
|
|
|
@ -22,7 +22,7 @@ Menu::~Menu()
|
|||
|
||||
void Menu::mapNew()
|
||||
{
|
||||
QScopedPointer proj{new Project(new MapModel)};
|
||||
QScopedPointer proj{new Project(ProjectModelType::Map)};
|
||||
|
||||
addProject(proj.take());
|
||||
}
|
||||
|
@ -40,7 +40,7 @@ void Menu::mapOpen()
|
|||
"All files (*)"));
|
||||
|
||||
if(!fname.isEmpty()) {
|
||||
QScopedPointer proj{new Project(new MapModel)};
|
||||
QScopedPointer proj{new Project(ProjectModelType::Map)};
|
||||
|
||||
if(proj->getModel()->open(fname)) {
|
||||
addProject(proj.take());
|
||||
|
@ -98,7 +98,7 @@ void Menu::openMapProperties()
|
|||
{
|
||||
auto proj = activeProject();
|
||||
|
||||
if(proj && proj->getModel()->type() == ProjectModel::Map) {
|
||||
if(proj && proj->getModel()->type() == ProjectModelType::Map) {
|
||||
MapProps props{proj->getMapModel(), proj};
|
||||
props.exec();
|
||||
}
|
||||
|
@ -111,8 +111,6 @@ void Menu::updateActions()
|
|||
|
||||
actionClose->setEnabled(active);
|
||||
actionMapProps->setEnabled(active);
|
||||
|
||||
dbgPrintFunc();
|
||||
}
|
||||
|
||||
void Menu::closeEvent(QCloseEvent *event)
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
#include "tycho.h"
|
||||
|
||||
Project::Project(ProjectModel *_model, QWidget *parent) :
|
||||
QMdiSubWindow(parent),
|
||||
model(_model)
|
||||
Project::Project(ProjectModelType type) :
|
||||
QMdiSubWindow(),
|
||||
model(nullptr),
|
||||
view(nullptr)
|
||||
{
|
||||
auto widget = new QWidget(this);
|
||||
|
||||
|
@ -11,7 +12,15 @@ Project::Project(ProjectModel *_model, QWidget *parent) :
|
|||
setWidget(widget);
|
||||
setAttribute(Qt::WA_DeleteOnClose);
|
||||
|
||||
switch(type) {
|
||||
case ProjectModelType::Map:
|
||||
model.reset(new MapModel(this));
|
||||
view = new MapView(getMapModel(), this);
|
||||
break;
|
||||
}
|
||||
|
||||
listView->setModel(dynamic_cast<QAbstractItemModel *>(model.get()));
|
||||
verticalLayout->insertWidget(0, view);
|
||||
|
||||
dbgPrintFunc();
|
||||
}
|
||||
|
|
|
@ -31,17 +31,17 @@ class MapView;
|
|||
class Menu;
|
||||
class Project;
|
||||
|
||||
enum class ProjectModelType
|
||||
{
|
||||
Map,
|
||||
};
|
||||
|
||||
class ProjectModel
|
||||
{
|
||||
public:
|
||||
enum Type
|
||||
{
|
||||
Map,
|
||||
};
|
||||
|
||||
virtual ~ProjectModel() {}
|
||||
|
||||
virtual Type type() const = 0;
|
||||
virtual ProjectModelType type() const = 0;
|
||||
|
||||
virtual bool isDirty() const = 0;
|
||||
virtual bool open(QString const &path) = 0;
|
||||
|
@ -57,7 +57,7 @@ public:
|
|||
explicit MapModel(QObject *parent = nullptr);
|
||||
~MapModel() override;
|
||||
|
||||
ProjectModel::Type type() const override;
|
||||
ProjectModelType type() const override;
|
||||
|
||||
bool isDirty() const override;
|
||||
bool open(QString const &path) override;
|
||||
|
@ -126,18 +126,18 @@ class Project final : public QMdiSubWindow, private Ui::Project
|
|||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit Project(ProjectModel *model, QWidget *parent = nullptr);
|
||||
explicit Project(ProjectModelType type);
|
||||
~Project();
|
||||
|
||||
std::shared_ptr<ProjectModel> getModel();
|
||||
std::shared_ptr<MapModel> getMapModel();
|
||||
std::shared_ptr<QAbstractItemModel> getAbstractModel();
|
||||
std::shared_ptr<ProjectModel> getModel();
|
||||
std::shared_ptr<MapModel> getMapModel();
|
||||
|
||||
protected:
|
||||
void closeEvent(QCloseEvent *event) override;
|
||||
|
||||
private:
|
||||
std::shared_ptr<ProjectModel> model;
|
||||
QWidget *view;
|
||||
};
|
||||
|
||||
template<typename... VA>
|
||||
|
|
|
@ -14,9 +14,6 @@
|
|||
<string>Project</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QWidget" name="widget" native="true"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QListView" name="listView">
|
||||
<property name="frameShape">
|
||||
|
|
Loading…
Reference in New Issue