Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
tristanpoland authored Jul 26, 2024
1 parent 704a8a8 commit 07fafe9
Showing 1 changed file with 102 additions and 139 deletions.
241 changes: 102 additions & 139 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,176 +1,142 @@
# RecipeSmith

RecipeSmith is a Rust-based module designed by asterisk for use with games that utilize the stars beyond horizon Server Backend as a framework for managing recipes, ingredients, and their interactions within a recipe book. This system integrates with PebbleVault for data storage and retrieval while being capable of communication with other submodules, ensuring modularity and independence. The goal is to enable dynamic recipe management, including creating, storing, retrieving, and crafting recipes based on available ingredients.
RecipeSmith is a Rust-based module designed for managing recipes, ingredients, and crafting systems in games. It provides a flexible framework for creating, storing, retrieving, and crafting recipes based on available ingredients.

## Features

- **Dynamic Recipe Management:** Create, store, retrieve, and craft recipes based on available ingredients.
- **Integration with PebbleVault:** Seamless data storage and retrieval with PebbleVault.
- **Modularity:** Designed to communicate with other submodules independently.
- **Ingredient Interaction:** Detailed tracking and management of ingredients and their quantities.
- **Outcome Prediction:** Automatically determine the outcome of recipes based on input ingredients.
- **Loosely Coupled Architecture:** Ensures components can function independently, enhancing flexibility and scalability.
- **Full Error Logging Functionality:** Comprehensive error logging to facilitate debugging and maintain system integrity.
- **Server Independence:** Operates without dependency on a central server, allowing for distributed and offline use cases.
- **Extendable and Customizable:** Easily extendable to add new features or customize existing ones to fit specific needs.

## How It Works

### Recipe Structure

Recipes are defined in a JSON file containing the name, ingredients, and outcome of each recipe. Here is an example structure:

```json
{
"_comment": "Recipes JSON file containing various recipes and their ingredients.",
"recipes": [
{
"name": "Bread",
"ingredients": [
{"name": "Flour", "quantity": 2},
{"name": "Water", "quantity": 1},
{"name": "Salt", "quantity": 1}
],
"outcome": "Bread"
},
{
"name": "Cake",
"ingredients": [
{"name": "Flour", "quantity": 3},
{"name": "Sugar", "quantity": 2},
{"name": "Egg", "quantity": 1},
{"name": "Milk", "quantity": 1}
],
"outcome": "Cake"
},
{
"name": "Potion",
"ingredients": [
{"name": "Herb", "quantity": 1},
{"name": "Water", "quantity": 1}
],
"outcome": "Health Potion"
},
{
"name": "Stew",
"ingredients": [
{"name": "Meat", "quantity": 2},
{"name": "Potato", "quantity": 3},
{"name": "Carrot", "quantity": 2},
{"name": "Water", "quantity": 2}
],
"outcome": "Stew"
},
{
"name": "Salad",
"ingredients": [
{"name": "Lettuce", "quantity": 2},
{"name": "Tomato", "quantity": 2},
{"name": "Cucumber", "quantity": 1},
{"name": "Olive Oil", "quantity": 1}
],
"outcome": "Salad"
},
{
"name": "Sandwich",
"ingredients": [
{"name": "Bread", "quantity": 2},
{"name": "Ham", "quantity": 1},
{"name": "Cheese", "quantity": 1},
{"name": "Lettuce", "quantity": 1}
],
"outcome": "Sandwich"
}
]
- **Dynamic Recipe Management:** Create, store, retrieve, and craft recipes.
- **Ingredient Interaction:** Detailed tracking and management of ingredients, including quantities and craftability.
- **Crafter System:** Associate recipes with specific crafters or crafting stations.
- **Inventory Management:** Built-in player inventory and storage container systems.
- **Recipe Book:** Centralized storage and indexing of recipes.
- **File Import:** Import recipes from JSON files.
- **Flexible Data Structures:** Support for various game objects like items, crafters, and storage containers.

## Core Structures

### Ingredient

```rust
pub struct Ingredient {
pub name: String,
pub quantity: u32,
pub recipe_craftable: bool,
}
```

### Integration with PebbleVault

RecipeSmith integrates with PebbleVault for data storage and retrieval, ensuring that all recipes and ingredients are securely stored and easily accessible. This integration allows RecipeSmith to operate efficiently within a larger ecosystem, enabling modular and independent submodule communication.
Represents an ingredient with its name, required quantity, and whether it's craftable through recipes.

### Modularity and Independence
### Recipe

RecipeSmith is designed to be modular and independent, capable of interacting with other submodules within the system. This design ensures that RecipeSmith can be easily integrated into various projects, providing a flexible and scalable solution for recipe management.
```rust
pub struct Recipe {
pub name: String,
pub ingredients: Vec<Ingredient>,
pub outcome: String,
pub crafters: Vec<String>,
pub recipe_craftable: bool,
}
```

### Error Logging
Defines a recipe with its name, required ingredients, outcome, associated crafters, and craftability status.

RecipeSmith includes a comprehensive error logging functionality that captures and logs errors to facilitate debugging and maintain system integrity. This feature ensures that any issues can be quickly identified and resolved.
### RecipeBook

### Server Independence
```rust
pub struct RecipeBook {
pub recipes: HashMap<String, Recipe>,
pub crafters: HashMap<Crafter, Vec<String>>,
}
```

RecipeSmith operates without dependency on a central server, allowing for distributed and offline use cases. This feature makes it ideal for applications that require high availability and resilience.
Central structure for managing recipes and their associations with crafters.

### Extendability and Customization
## Key Functionalities

RecipeSmith is easily extendable and customizable, allowing developers to add new features or modify existing ones to fit specific needs. This flexibility makes it suitable for a wide range of applications.
### Adding Recipes

## Getting Started
1. **Clone the Repository:**
```sh
git clone https://github.com/Stars-Beyond/RecipeSmith
```
```rust
impl RecipeBook {
pub fn add_recipe(&mut self, recipe: Recipe) {
// Implementation details...
}
}
```

2. **Navigate to the Project Directory:**
```sh
cd RecipeSmith
```
Add new recipes to the RecipeBook, automatically indexing them by crafter.

3. **Build the Project:**
```sh
cargo build
```
### Crafting

4. **Run the Project:**
```sh
cargo run
```
```rust
impl RecipeBook {
pub fn can_craft(&self, recipe_name: &str, inventory: &HashMap<String, Ingredient>) -> bool {
// Implementation details...
}

## Example Usage in an RPG Game
pub fn craft(&self, recipe_name: &str, inventory: &mut HashMap<String, Ingredient>) -> Option<String> {
// Implementation details...
}
}
```

### Integration into an RPG Game
Check if a recipe can be crafted and perform the crafting operation, updating the inventory.

1. **Define Recipes and Ingredients:**
- Use the JSON structure provided by RecipeSmith to define various recipes and their required ingredients.
### Importing Recipes

2. **Crafting System:**
- Implement a crafting system in your RPG game that interacts with RecipeSmith. Players can collect ingredients and use the crafting system to create new items.
```rust
impl RecipeBook {
pub fn import_recipes_from_file(&mut self, filename: &str) -> Result<(), Box<dyn std::error::Error>> {
// Implementation details...
}
}
```

3. **Storage and Retrieval:**
- Integrate PebbleVault to store and retrieve recipes and ingredients, allowing players to save their progress and access it later.
Import recipes from JSON files, allowing for easy expansion of the recipe database.

4. **Outcome Determination:**
- Use RecipeSmith’s outcome prediction feature to automatically determine the result of combining different ingredients.
## Inventory Management

### Example Workflow
### PlayerInventory

1. **Collect Ingredients:**
- Players gather ingredients during gameplay (e.g., Flour, Water, Salt).
```rust
pub struct PlayerInventory {
pub slots: HashMap<u32, Option<Item>>,
}
```

2. **Open Crafting Menu:**
- Players open the crafting menu where they can see available recipes.
Manages player inventories with methods for adding, removing, and retrieving items.

3. **Select Recipe:**
- Players select a recipe (e.g., Bread) and see the required ingredients.
### StorageContainer

4. **Craft Item:**
- Players combine the required ingredients and craft the item, resulting in the outcome (e.g., Bread).
```rust
pub struct StorageContainer {
pub uuid: Uuid,
pub inventory: PlayerInventory,
}
```

### Example Code Snippet
Represents storage containers in the game world, each with its own inventory.

```rs
use recipesmith::{Recipe, Ingredient};
## Usage Example

```rust
fn main() {
let flour = Ingredient::new("Flour", 2);
let water = Ingredient::new("Water", 1);
let salt = Ingredient::new("Salt", 1);
let mut recipe_book = RecipeBook::new();

// Import recipes
recipe_book.import_recipes_from_file("recipes/recipes.json").unwrap_or_else(|e| {
eprintln!("Error importing recipes: {}", e);
});

let bread_recipe = Recipe::new("Bread", vec![flour, water, salt], "Bread");
// Initialize inventory
let mut inventory: HashMap<String, Ingredient> = HashMap::new();
// Add ingredients to inventory...

let crafted_item = bread_recipe.craft();
println!("Crafted Item: {}", crafted_item);
// Attempt to craft
if recipe_book.can_craft("Bread", &inventory) {
if let Some(item) = recipe_book.craft("Bread", &mut inventory) {
println!("Crafted: {}", item);
}
}
}
```

Expand All @@ -181,6 +147,3 @@ Contributions are welcome! Please feel free to submit a Pull Request.
## License

This project is licensed under the Apache 2.0 License - see the [LICENSE](LICENSE) file for details.


RecipeSmith is a powerful tool for managing and interacting with recipes and ingredients. With its robust features and seamless integration with PebbleVault, it provides a dynamic and flexible solution for any recipe management needs you may have.

0 comments on commit 07fafe9

Please sign in to comment.