Skip to content

Commit

Permalink
Merged in changes from main
Browse files Browse the repository at this point in the history
  • Loading branch information
ellakestrel committed Apr 25, 2022
2 parents c084111 + fa2cd66 commit 40e072e
Show file tree
Hide file tree
Showing 14 changed files with 50 additions and 48 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,4 @@ Cargo.lock
# End of https://www.toptal.com/developers/gitignore/api/rust,clion+all

playground/
/SDL2.dll
23 changes: 22 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,33 @@
# RadiancePlatform
A simple text-based game framework

# Running
# Installation
Head over to [the releases page](https://github.com/Radiance-Platform/RadiancePlatform/releases/) to grab the latest precompiled build of the platform. Download the version for your operating system, and then open the program in your favorite command line terminal. Games can be loaded using the command-line flag like `--config-path example_game/`. The example game will work with any operating system version.

# Running for Development
First, ensure you have a working Rust installation with cargo. See https://www.rust-lang.org/tools/install

Then, from within the main folder (the one this README is in), run `cargo run -- --config-path example_game/` compile and start the game engine using the provided example game configuration files. Press the escape key to exit.

# Building Releases
Radiance is designed to be run on both Windows and Linux systems. At this time, macOS is not directly supported, but will likely work fine with some customization to these build instructions. Build steps are designed around Ubuntu and will need some slight tweaking to work on other Linux distributions. Directions are based on [this guide](https://stackoverflow.com/questions/31492799/cross-compile-a-rust-application-from-linux-to-windows).

From an Ubuntu Linux installation with Rust and cargo, run the following commands to prepare your environment:
```sh
sudo apt-get install libsdl2-dev mingw-w64 -y
rustup target add x86_64-pc-windows-gnu
rustup toolchain install stable-x86_64-pc-windows-gnu
curl -s https://www.libsdl.org/release/SDL2-devel-2.0.9-mingw.tar.gz | tar xvz -C /tmp
cp -r /tmp/SDL2-2.0.9/x86_64-w64-mingw32/lib/* ~/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-pc-windows-gnu/lib/
cp /tmp/SDL2-2.0.9/x86_64-w64-mingw32/bin/SDL2.dll .
```

Afterwards, run these two commands to build for Windows and Linux respectively. Build files can be found in the `target` folder, under
```sh
cargo build --release --target x86_64-pc-windows-gnu
cargo build --release
```

# Notes / Useful Resources Used
https://doc.rust-lang.org/book/
https://doc.rust-lang.org/rust-by-example/
Expand Down
1 change: 0 additions & 1 deletion src/game/characters/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

use crate::game::characters::interactions::Interactions;
use crate::game::characters::attribute::Attribute;
use crate::game::objects::Object;
Expand Down
10 changes: 4 additions & 6 deletions src/game/config_parsers/characters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ fn get_character_from_data(characters: &mut HashMap<String, Character>, data: Ch
attributes: vec![],
inventory: vec![],
icon: ' ',
interactions: interactions,
interactions,
dialog_id: "".to_string(),
};
character.inventory.resize(data.inventory_size.width as usize, vec![] );
Expand Down Expand Up @@ -76,18 +76,16 @@ fn get_character_from_data(characters: &mut HashMap<String, Character>, data: Ch
let value: f32 = modifier_data.effect_per_point[1..].parse().unwrap();
attack.affected_by.push(interactions::Modifier {
attribute_id: modifier_data.attribute_id,
sign: sign,
value: value,
sign,
value,
});
}
character.interactions.attacks.push(attack);
}
//println!("CHARACTER: {:?}", character);
characters.insert(character.id.clone(), character);
}

// Temporary data structure CharacterData is used for Serde parsing and nothing else.

// Temporary data structure that is used for Serde parsing and nothing else
#[derive(Debug, Serialize, Deserialize)]
pub struct CharacterData {
pub id: String,
Expand Down
4 changes: 1 addition & 3 deletions src/game/config_parsers/game.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,10 @@ pub fn process_config(game_data: &mut GameData, config_path: &Path) -> Result<()

// Convert to YAML
let docs = YamlLoader::load_from_str(&*file_contents).unwrap();

// Multi document support, doc is a yaml::Yaml, need to extract the doc
let doc = &docs[0];

// Debug print
//println!("GAME DOC: {:?}\n", doc);

let game_info_hash = doc.as_hash().unwrap();

for key in game_info_hash.keys() {
Expand Down
2 changes: 0 additions & 2 deletions src/game/config_parsers/maps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ pub struct MapItemData {
pub objects: Vec<MapObject>,
}



#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct MapObject {
Expand Down
7 changes: 3 additions & 4 deletions src/game/config_parsers/mod.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
use std::ffi::OsStr;
use crate::game::maps::{Map, MapInfo};
use walkdir::WalkDir;
use crate::game::config_parsers::maps::MapItemData;
use crate::game::maps::{Map, MapInfo, MapData};
use crate::game::characters::Character;
use crate::game::objects::Object;
use crate::game::maps::MapData;
use crate::game::dialogs::Dialog;
use std::collections::HashMap;
use std::error::Error;
use crate::game::config_parsers::maps::MapItemData;

mod characters;
mod game;
Expand Down Expand Up @@ -106,7 +105,7 @@ impl GameData {
}

// Takes the MapItemData, characters list, and objects list and inserts the characters and objects
// in the right spaces in the game map
// in the right spaces in the game map
fn set_map_grid(&mut self, map_item_data: Vec<MapItemData>, characters: HashMap<String, Character>,
objects: HashMap< String, Object> ) -> Result<(), Box<dyn Error>> {
for map_item in map_item_data {
Expand Down
6 changes: 3 additions & 3 deletions src/game/config_parsers/objects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@ use std::path::Path;
use std::collections::HashMap;
use yaml_rust::YamlLoader;
use yaml_rust::Yaml;
use crate::game::objects::{Object, ObjectState,
ObjectInteraction, ObjectInteractionActivate,
use crate::game::objects::{Object, ObjectState, ObjectInteraction, ObjectInteractionActivate,
ObjectInteractionObjectUse};

// Takes an object config file and loads it into an object, then adds that object to the objects list
// so that it can later be added to the game map.
// so that it can later be added to the game map.
pub fn process_config(objects: &mut HashMap<String, Object>, config_path: &Path) -> Result<(), Box<dyn Error>> {

// Load file contents
let file_contents = fs::read_to_string(config_path)?;

// Convert to YAML
let docs = YamlLoader::load_from_str(&*file_contents).unwrap();

// Multi document support, doc is a yaml::Yaml, need to extract the doc
let doc = &docs[0];

Expand Down
2 changes: 1 addition & 1 deletion src/game/dialogs/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use serde::Deserialize;

// Dialog data structure. Contains a single dialog object consisting of
// some NPC dialog and two dialog options for the player.
// some NPC dialog and two dialog options for the player.

#[derive(Debug, Clone, Deserialize)]
pub struct Dialog {
Expand Down
3 changes: 1 addition & 2 deletions src/game/maps/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ use crate::game::characters::Character;
use crate::game::objects::Object;

// Map data structure. Contains a single map with a grid of spaces.
// Each space can hold either nothing, a character, or
// an object.
// Each space can hold either nothing, a character, or an object.

#[derive(Clone, Debug)]
pub enum MapData {
Expand Down
2 changes: 1 addition & 1 deletion src/game/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::process::exit;
use config_parsers::GameData;
use crate::game::screen::{Screen, VisualState};
use crossterm::{event::{Event, KeyCode}, Result};
use crate::game::screen::{Screen, VisualState};

pub mod characters;
pub mod dialogs;
Expand Down
13 changes: 4 additions & 9 deletions src/game/objects/mod.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
use serde::{Serialize,Deserialize};

// Object data structure. These are items found in the game maps, or given to the player
// via an interaction. These make up the majority of the game's interactivity.

#[derive(Clone, Debug)]
pub struct ObjectState {
pub name: String,
pub value: bool
}


/*#[derive(Clone, Debug)]
pub struct ObjectInteraction {
pub category: ObjectInteractionCategory,
pub values: String
}*/


#[derive(Clone, Debug)]
pub enum ObjectInteraction {
ObjectInteractionActivate(ObjectInteractionActivate),
Expand All @@ -39,7 +34,7 @@ pub struct ObjectInteractionWorld {

}

// TODO: Object's categories should probably be some sort of type rather than arbitrary strings
// TODO: Future Enhancement: Object's categories should probably be some sort of type rather than arbitrary strings
/*pub enum ObjectCategory {
"simple",
"collidable"
Expand Down
22 changes: 9 additions & 13 deletions src/game/screen/mod.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,20 @@
use std::fmt::Debug;
use crate::game::config_parsers::GameData;
use crate::game::GameState;

use std::io::{Error, ErrorKind, stdout};
use std::process::{exit};

use crate::game::config_parsers::GameData;
use crate::game::GameState;
use crate::game::maps::MapData;
use crate::game::characters::Character;
use crate::game::characters::attribute;
use crate::game::objects::{ObjectInteraction, Object};
use crossterm::{
execute,
style::{Print},
ExecutableCommand, Result,
terminal::{SetSize, size},
cursor::{MoveTo}
terminal::{SetSize, size, disable_raw_mode, enable_raw_mode, Clear, ClearType},
cursor::{MoveTo, Hide, Show},
event::{Event, KeyCode},
};
use crossterm::cursor::{Hide, Show};
use crossterm::event::{Event, KeyCode};
use crossterm::terminal::{disable_raw_mode, enable_raw_mode, Clear, ClearType};
use crate::game::maps::MapData;
use crate::game::characters::Character;
use crate::game::characters::attribute;
use super::objects::{ObjectInteraction, Object};

#[derive(Clone, Debug)]
pub enum VisualState {
Expand Down
2 changes: 0 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ struct Args {
}

fn main() {
println!("Hello, Radiance!");

// Make sure we have arguments or compiled-in
// TODO: Some way to compile config files in, might need a custom build script or something
let args = Args::parse();
Expand Down

0 comments on commit 40e072e

Please sign in to comment.