Skip to content

Add Comprehensive Documentation for SpriteAI Module's Sprite Generation Functions #430

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 89 additions & 0 deletions docs/fetchAvailableSpriteStyles.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
---
title: fetchAvailableSpriteStyles
description: Learn how to retrieve available sprite styles using the fetchAvailableSpriteStyles function.
sidebar_position: 4
---

# fetchAvailableSpriteStyles

## Introduction

The `fetchAvailableSpriteStyles` function is a part of the spriteAI module. It allows developers to retrieve a list of available sprite styles that can be used when generating character sprites. This function is useful for providing users with style options or for validating style inputs before sprite generation.

## Usage

To use the `fetchAvailableSpriteStyles` function, import it from the spriteAI module and call it as an asynchronous function.

```javascript
import { fetchAvailableSpriteStyles } from './path/to/spriteAI';

const styles = await fetchAvailableSpriteStyles();
console.log(styles);
```

## Function Signature

```javascript
async function fetchAvailableSpriteStyles(): Promise<string[]>
```

### Return Value

The function returns a Promise that resolves to an array of strings. Each string represents an available sprite style.

## Example

Here's a complete example of how to use the `fetchAvailableSpriteStyles` function:

```javascript
import { fetchAvailableSpriteStyles } from './path/to/spriteAI';

async function displayAvailableStyles() {
try {
const styles = await fetchAvailableSpriteStyles();
console.log('Available sprite styles:');
styles.forEach((style, index) => {
console.log(`${index + 1}. ${style}`);
});
} catch (error) {
console.error('Error fetching available styles:', error);
}
}

displayAvailableStyles();
```

This example will fetch and display a list of all available sprite styles.

## Available Styles

As of the current implementation, the following styles are available:

- pixel-art
- vector
- 3d
- hand-drawn
- anime

Please note that this list may be updated in future versions of the spriteAI module.

## Use Cases

1. **Style Selection UI**: Use this function to populate a dropdown menu or radio button group, allowing users to select a style for sprite generation.

2. **Input Validation**: Before calling the sprite generation function, you can use the returned array to validate that the user-selected style is valid.

3. **Dynamic Feature Enabling**: Enable or disable certain features in your application based on the available styles.

## Notes

- The function is asynchronous and returns a Promise. Always use `await` or `.then()` when calling it.
- If the function fails to fetch the styles, it will throw an error. Make sure to implement proper error handling in your code.
- The list of available styles may change in future updates. It's recommended to always use this function to get the most up-to-date list rather than hardcoding style options in your application.

## Related Functions

- `generateCharacterSpritesheet`: Uses the styles returned by `fetchAvailableSpriteStyles` to generate character sprites.
- `fetchAvailableAnimationStates`: Retrieves available animation states for sprite generation.

By using `fetchAvailableSpriteStyles` in conjunction with other spriteAI functions, you can create a robust and flexible sprite generation system in your application.
104 changes: 104 additions & 0 deletions docs/generateEnvironmentSprites.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
---
title: Generate Environment Sprites
description: Learn how to generate environment sprites for your game using AI-powered image generation.
---

# Generate Environment Sprites

## Introduction

This tutorial will guide you through the process of generating environment sprites for your game using the `generateEnvironmentSprites` function. This powerful tool leverages AI to create custom environment elements based on your description, making it easy to populate your game world with unique and visually appealing assets.

## Prerequisites

Before you begin, make sure you have:

- Node.js installed on your system
- The `spriteAI` module installed in your project
- An OpenAI API key (for DALL-E 3 image generation)

## Generate Your First Environment Sprite Set

Let's create a set of environment sprites for a fantasy forest setting.

1. Import the necessary function:

```javascript
import { generateEnvironmentSprites } from 'spriteAI';
```

2. Call the function with a description and options:

```javascript
const result = await generateEnvironmentSprites("fantasy forest elements", {
elements: 6,
size: '1024x1024',
style: 'pixel-art',
padding: 2,
theme: 'fantasy',
save: true
});
```

3. The function will return an object containing:
- `original`: URL of the original generated image
- `tileset`: Base64-encoded PNG of the processed tileset
- `metadata`: Information about the generated sprites

4. You can now use the `tileset` in your game or save it for later use.

## Customizing Your Environment Sprites

The `generateEnvironmentSprites` function offers several options to customize your output:

- `elements`: Number of distinct environment pieces (default: 4)
- `size`: Size of the generated image (default: '1024x1024')
- `style`: Art style of the sprites (default: 'pixel-art')
- `padding`: Spacing between elements (default: 1)
- `theme`: Overall theme of the environment (default: 'fantasy')
- `save`: Whether to automatically save the generated image (default: false)

Example with custom options:

```javascript
const result = await generateEnvironmentSprites("sci-fi space station components", {
elements: 8,
size: '2048x2048',
style: 'vector',
theme: 'futuristic',
save: true
});
```

## Working with the Generated Sprites

After generating your environment sprites, you can:

1. Use the base64-encoded `tileset` directly in your game engine.
2. Save the image to your project assets folder (if `save: true` was used).
3. Access individual sprite information using the `metadata` object.

Example of accessing metadata:

```javascript
console.log(result.metadata.elements); // Number of generated elements
console.log(result.metadata.dimensions); // Width and height of the tileset
console.log(result.metadata.tileData); // Information about rows, columns, and total tiles
```

## Best Practices

- Be specific in your descriptions to get the best results.
- Experiment with different styles and themes to find what works best for your game.
- Generate multiple variations and choose the best one for your needs.
- Consider post-processing the sprites for consistency with your game's art style.

## Next Steps

Now that you've generated your environment sprites, you might want to:

- Learn how to [Generate Character Spritesheets](/docs/generateCharacterSpritesheet) for your game.
- Explore [Integrating AI-Generated Assets](/docs/integratingAIAssets) into your game engine.
- Understand more about [AI Art Styles and Prompts](/docs/aiArtStyles) for better results.

By mastering the `generateEnvironmentSprites` function, you'll be able to quickly create diverse and interesting game environments with ease. Happy sprite generating!
137 changes: 137 additions & 0 deletions docs/generateItemSprites.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
---
title: Generate Item Sprites
description: Learn how to use the generateItemSprites function to create sprite sheets for game items.
---

# Generate Item Sprites

## Introduction

The `generateItemSprites` function is a powerful tool for game developers to create customizable sprite sheets for in-game items. This tutorial will guide you through the process of using this function to generate high-quality item sprites for your game.

## Prerequisites

Before you begin, make sure you have:

- Node.js installed on your system
- The SpriteAI library installed in your project
- Basic knowledge of JavaScript and asynchronous programming

## Getting Started

First, let's import the necessary function from the SpriteAI module:

```javascript
import { generateItemSprites } from 'spriteAI';
```

## Using generateItemSprites

The `generateItemSprites` function allows you to create a sprite sheet of items based on a description and various options. Here's the basic syntax:

```javascript
const result = await generateItemSprites(description, options);
```

### Parameters

- `description` (string, required): A text description of the items you want to generate.
- `options` (object, optional): Customization options for the sprite generation.

### Options

You can customize the sprite generation process using the following options:

```javascript
const options = {
itemCount: 4,
size: '1024x1024',
style: 'pixel-art',
padding: 1,
itemType: 'equipment',
background: 'white',
save: true
};
```

- `itemCount`: Number of items to generate (default: 4)
- `size`: Size of the output image (default: '1024x1024')
- `style`: Visual style of the items (default: 'pixel-art')
- `padding`: Padding between items (default: 1)
- `itemType`: Type of items to generate (default: 'equipment')
- `background`: Background color of the sprite sheet (default: 'white')
- `save`: Whether to save the generated image to disk (default: false)

## Example: Generating Equipment Sprites

Let's create a sprite sheet of fantasy equipment items:

```javascript
async function createEquipmentSprites() {
const description = "Fantasy RPG equipment including swords, shields, and potions";
const options = {
itemCount: 6,
style: 'pixel-art',
itemType: 'equipment',
save: true
};

try {
const result = await generateItemSprites(description, options);
console.log("Sprite sheet generated successfully!");
console.log("Original image URL:", result.original);
console.log("Sprite sheet data URL:", result.itemSheet);
console.log("Metadata:", result.metadata);
} catch (error) {
console.error("Error generating sprite sheet:", error);
}
}

createEquipmentSprites();
```

## Understanding the Result

The `generateItemSprites` function returns an object with the following properties:

- `original`: URL of the original generated image
- `itemSheet`: Data URL of the processed sprite sheet
- `metadata`: Object containing information about the generated sprites

```javascript
{
original: "https://example.com/original-image.png",
itemSheet: "data:image/png;base64,iVBORw0KGgo...",
metadata: {
itemCount: 6,
itemType: "equipment",
dimensions: {
width: "1024",
height: "1024"
},
itemData: {
rows: 3,
columns: 2,
totalItems: 6
}
}
}
```

## Saving the Sprite Sheet

If you set `save: true` in the options, the function will automatically save the sprite sheet to your project's `assets` folder. The filename will be based on the description you provided, with spaces replaced by underscores.

## Next Steps

Now that you've learned how to generate item sprites, you might want to explore:

- [Customizing Sprite Styles](/docs/customizing-sprite-styles)
- [Integrating Sprites in Your Game Engine](/docs/integrating-sprites)
- [Advanced Sprite Generation Techniques](/docs/advanced-sprite-generation)

## Conclusion

The `generateItemSprites` function simplifies the process of creating consistent and customizable item sprites for your game. By leveraging AI-powered image generation, you can quickly produce high-quality assets that match your game's style and requirements.

Remember to experiment with different descriptions and options to achieve the best results for your specific game needs. Happy sprite generating!
Loading