Skip to content

Commit

Permalink
Remove some duped code and rename files
Browse files Browse the repository at this point in the history
  • Loading branch information
RolandoDrRobot committed Sep 5, 2024
1 parent 2273989 commit 234ccd5
Show file tree
Hide file tree
Showing 20 changed files with 50 additions and 315 deletions.
228 changes: 0 additions & 228 deletions src/models.cairo
Original file line number Diff line number Diff line change
@@ -1,233 +1,5 @@
use starknet::{ContractAddress, SyscallResultTrait};

#[derive(Serde, Copy, Drop, Introspect)]
pub enum WorldElements {
Crystal,
Draconic,
Shadow,
Light,
Titanium,
}

impl WorldElementsIntoFelt252 of Into<WorldElements, felt252> {
fn into(self: WorldElements) -> felt252 {
match self {
WorldElements::Crystal => 0,
WorldElements::Draconic => 1,
WorldElements::Shadow => 2,
WorldElements::Light => 3,
WorldElements::Titanium => 4,
}
}
}

#[derive(Copy, Drop, Serde)]
#[dojo::model]
pub struct Beast {
#[key]
pub beast_id: u32,
pub beast_name: felt252,
pub beast_type: WorldElements,
pub beast_description: felt252,
pub player_id: u32,
pub hp: u32,
pub current_hp: u32,
pub attack: u32,
pub defense: u32,
pub mt1: u32,
pub mt2: u32,
pub mt3: u32,
pub mt4: u32,
pub level: u32,
pub experience_to_next_level: u64,
}

#[derive(Copy, Drop, Serde)]
#[dojo::model]
pub struct Battle {
#[key]
pub battle_id: u32,
pub player_id: u32,
pub opponent_id: u32,
pub active_beast_player: u32,
pub active_beast_opponent: u32,
pub battle_active: u32,
pub turn: u32,
}

#[derive(Copy, Drop, Serde)]
#[dojo::model]
pub struct Mt {
#[key]
pub mt_id: u32,
pub mt_name: felt252,
pub mt_type: WorldElements,
pub mt_power: u32,
pub mt_accuracy: u32,
}

#[derive(Copy, Drop, Serde)]
#[dojo::model]
struct Player {
#[key]
pub player_id: u32,
pub player_name: felt252,
pub beast_1: u32,
pub beast_2: u32,
pub beast_3: u32,
pub beast_4: u32,
pub potions: u32,
}

#[derive(Copy, Drop, Serde)]
#[dojo::model]
struct Potion {
#[key]
pub potion_id: u32,
pub potion_name: felt252,
pub potion_effect: u32,
}

#[derive(Drop, Copy, Serde)]
#[dojo::model]
struct Position {
#[key]
player: Player,
coordinates: Coordinates,
}

#[derive(Drop, Copy, Serde, Introspect)]
struct Coordinates {
x: u32,
y: u32
}

#[generate_trait]
impl BeastImpl of BeastTrait {
fn exist(self: Beast) -> bool {
self.hp > 0
}
}

#[cfg(test)]
mod tests {
use super::{Battle, Beast, Player, Coordinates, Position, Mt, Potion, BeastTrait, WorldElements};

#[test]
fn test_beast_exist() {
let beast = Beast {
beast_id: 1,
beast_name: 0,
beast_type: WorldElements::Crystal,
beast_description: 0,
player_id: 1,
hp: 100,
current_hp: 100,
attack: 50,
defense: 40,
mt1: 1, // Fire Blast
mt2: 2, // Ember
mt3: 3, // Flame Wheel
mt4: 4, // Fire Punch
level: 5,
experience_to_next_level: 1000,
};
assert(beast.exist(), 'Beast is alive');
assert_eq!(beast.hp, 100, "HP should be initialized to 100");
}

#[test]
fn test_player_initialization() {
let player = Player {
player_id: 1,
player_name: 'Hero',
beast_1: 1,
beast_2: 2,
beast_3: 3,
beast_4: 4,
potions: 5,
};

assert_eq!(player.player_name, 'Hero', "Player name should be 'Hero'");
assert_eq!(player.potions, 5, "Player should have 5 potions");
}

#[test]
fn test_position_initialization() {
let player = Player {
player_id: 1,
player_name: 'Hero',
beast_1: 1,
beast_2: 2,
beast_3: 3,
beast_4: 4,
potions: 5,
};

let coordinates = Coordinates{
x: 10,
y: 10,
};

let position = Position {
player: player,
coordinates: coordinates
};

assert_eq!(position.player.player_id, 1, "Player ID should be 1");
assert_eq!(position.coordinates.x, 10, "Player X coordinate should be 10");
assert_eq!(position.coordinates.y, 10, "Player Y coordinate should be 10");
}

#[test]
fn test_battle_initialization() {
let battle = Battle {
battle_id: 1,
player_id: 1,
opponent_id: 2,
active_beast_player: 1,
active_beast_opponent: 2,
battle_active: 1,
turn: 1,
};

assert_eq!(battle.battle_id, 1, "Battle ID should be 1");
assert_eq!(battle.player_id, 1, "Player ID should be 1");
assert_eq!(battle.opponent_id, 2, "Opponent ID should be 2");
assert_eq!(battle.battle_active, 1, "Battle should be active");
assert_eq!(battle.turn, 1, "Turn should be 1");
}

#[test]
fn test_mt_initialization() {
let mt = Mt {
mt_id: 1,
mt_name: 0, // Assume mt_name is felt252 type
mt_type: WorldElements::Light,
mt_power: 75,
mt_accuracy: 90,
};

assert_eq!(mt.mt_id, 1, "MT ID should be 1");
assert_eq!(mt.mt_power, 75, "MT power should be 75");
assert_eq!(mt.mt_accuracy, 90, "MT accuracy should be 90");
}

#[test]
fn test_potion_initialization() {
let potion = Potion {
potion_id: 1,
potion_name: 0, // Assume potion_name is felt252 type
potion_effect: 50, // Heals 50 HP
};

assert_eq!(potion.potion_id, 1, "Potion ID should be 1");
assert_eq!(potion.potion_effect, 50, "Potion effect should be 50");
}
}



// New Models

// Game Player
Expand Down
Empty file removed src/models/Bag.cairo
Empty file.
Empty file removed src/models/Game.cairo
Empty file.
2 changes: 1 addition & 1 deletion src/models/GamePlayer.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@ impl GamePlayerImpl of GamePlayerTrait {
};
game_player
}
}
}
Empty file removed src/models/Map.cairo
Empty file.
Empty file removed src/models/Mount.cairo
Empty file.
Empty file removed src/models/NPCs.cairo
Empty file.
Empty file removed src/models/Trainer.cairo
Empty file.
5 changes: 1 addition & 4 deletions src/models/battle.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ pub struct Battle {

#[cfg(test)]
mod tests {
use bytebeasts::{
models::{battle::Battle},
};
use bytebeasts::{models::{battle::Battle},};

#[test]
fn test_battle_initialization() {
Expand All @@ -35,5 +33,4 @@ mod tests {
assert_eq!(battle.battle_active, 1, "Battle should be active");
assert_eq!(battle.turn, 1, "Turn should be 1");
}

}
5 changes: 1 addition & 4 deletions src/models/beast.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ impl BeastImpl of BeastTrait {

#[cfg(test)]
mod tests {
use bytebeasts::{
models::{beast::{Beast, BeastTrait}, world_elements::WorldElements},
};
use bytebeasts::{models::{beast::{Beast, BeastTrait}, world_elements::WorldElements},};

#[test]
fn test_beast_exist() {
Expand All @@ -58,5 +56,4 @@ mod tests {
assert(beast.exist(), 'Beast is alive');
assert_eq!(beast.hp, 100, "HP should be initialized to 100");
}

}
2 changes: 1 addition & 1 deletion src/models/coordinates.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
struct Coordinates {
x: u32,
y: u32
}
}
5 changes: 1 addition & 4 deletions src/models/mt.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ pub struct Mt {

#[cfg(test)]
mod tests {
use bytebeasts::{
models::{mt::Mt, world_elements::WorldElements},
};
use bytebeasts::{models::{mt::Mt, world_elements::WorldElements},};

#[test]
fn test_mt_initialization() {
Expand All @@ -31,5 +29,4 @@ mod tests {
assert_eq!(mt.mt_power, 75, "MT power should be 75");
assert_eq!(mt.mt_accuracy, 90, "MT accuracy should be 90");
}

}
25 changes: 11 additions & 14 deletions src/models/npc.cairo
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
use bytebeasts::{
models::{role::Role, coordinates::Coordinates, mission_status::MissionStatus},
};
use bytebeasts::{models::{role::Role, coordinates::Coordinates, mission_status::MissionStatus},};

#[derive(Drop, Serde)]
#[dojo::model]
pub struct NPC {
#[key]
pub npc_id: u32, // Unique identifier for the NPC
pub npc_name: felt252, // Name of the NPC
pub npc_description: felt252, // Description of the NPC
pub npc_role: Role, // Role of the NPC, defined by the Role enum
pub dialogue: ByteArray, // Default dialogue for the NPC
pub is_active: bool, // Whether the NPC is currently active in the game
pub location: Coordinates, // Fixed location of the NPC on the map
pub importance_level: u8, // Level of importance of the NPC in the game
pub mission_status: MissionStatus, // Status of the mission associated with the NPC
pub reward: u16, // Fixed reward given by the NPC
pub npc_id: u32, // Unique identifier for the NPC
pub npc_name: felt252, // Name of the NPC
pub npc_description: felt252, // Description of the NPC
pub npc_role: Role, // Role of the NPC, defined by the Role enum
pub dialogue: ByteArray, // Default dialogue for the NPC
pub is_active: bool, // Whether the NPC is currently active in the game
pub location: Coordinates, // Fixed location of the NPC on the map
pub importance_level: u8, // Level of importance of the NPC in the game
pub mission_status: MissionStatus, // Status of the mission associated with the NPC
pub reward: u16, // Fixed reward given by the NPC
pub experience_points: u16, // Experience points given by the NPC
}

Expand Down Expand Up @@ -73,4 +71,3 @@ mod tests {
assert_eq!(status_completed, 2);
}
}

5 changes: 1 addition & 4 deletions src/models/player.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ struct Player {

#[cfg(test)]
mod tests {
use bytebeasts::{
models::{player::Player},
};
use bytebeasts::{models::{player::Player},};

#[test]
fn test_player_initialization() {
Expand All @@ -32,5 +30,4 @@ mod tests {
assert_eq!(player.player_name, 'Hero', "Player name should be 'Hero'");
assert_eq!(player.potions, 5, "Player should have 5 potions");
}

}
15 changes: 3 additions & 12 deletions src/models/position.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ struct Position {

#[cfg(test)]
mod tests {
use bytebeasts::{
models::{position::Position, coordinates::Coordinates, player::Player},
};
use bytebeasts::{models::{position::Position, coordinates::Coordinates, player::Player},};

#[test]
fn test_position_initialization() {
Expand All @@ -27,19 +25,12 @@ mod tests {
potions: 5,
};

let coordinates = Coordinates{
x: 10,
y: 10,
};
let coordinates = Coordinates { x: 10, y: 10, };

let position = Position {
player: player,
coordinates: coordinates
};
let position = Position { player: player, coordinates: coordinates };

assert_eq!(position.player.player_id, 1, "Player ID should be 1");
assert_eq!(position.coordinates.x, 10, "Player X coordinate should be 10");
assert_eq!(position.coordinates.y, 10, "Player Y coordinate should be 10");
}

}
Loading

0 comments on commit 234ccd5

Please sign in to comment.