diff --git a/dev-docs/misc-spriteai-functions-documentation.md b/dev-docs/misc-spriteai-functions-documentation.md index 8554d920..6c5541f9 100644 --- a/dev-docs/misc-spriteai-functions-documentation.md +++ b/dev-docs/misc-spriteai-functions-documentation.md @@ -62,6 +62,108 @@ const spriteWithBorder = await sprite.generateSpriteWithBorder('knight', { r: 25 console.log(spriteWithBorder); ``` +### 6. generateEnvironmentSprites +**Location**: `/spriteAI/index.js` + +Generates environment tilesets based on a description. + +```javascript +async function generateEnvironmentSprites(description, options = {}) +``` + +#### Parameters: +- `description` (string): Description of the environment to generate. +- `options` (object): Configuration options for the tileset generation. + +#### Options: +| Option | Type | Default | Description | +|--------|------|---------|-------------| +| elements | number | 4 | Number of different elements in the tileset | +| size | string | '1024x1024' | Output image size | +| style | string | 'pixel-art' | Art style to use | +| padding | number | 1 | Padding between tiles | +| theme | string | 'fantasy' | Theme of the environment | + +#### Example Usage: +```javascript +const environmentSprites = await generateEnvironmentSprites('a fantasy forest', { + elements: 6, + size: '1024x1024', + style: 'pixel-art', + padding: 2, + theme: 'fantasy', + save: true +}); +console.log(environmentSprites.tileset); +``` + +### 7. generateItemSprites +**Location**: `/spriteAI/index.js` + +Generates item collections based on a description. + +```javascript +async function generateItemSprites(description, options = {}) +``` + +#### Parameters: +- `description` (string): Description of the items to generate. +- `options` (object): Configuration options for the item generation. + +#### Options: +| Option | Type | Default | Description | +|--------|------|---------|-------------| +| itemCount | number | 4 | Number of different items in the collection | +| size | string | '1024x1024' | Output image size | +| style | string | 'pixel-art' | Art style to use | +| padding | number | 1 | Padding between items | +| itemType | string | 'equipment' | Type of items to generate | +| background | string | 'white' | Background color of the items | + +#### Example Usage: +```javascript +const itemSprites = await generateItemSprites('medieval weapons', { + itemCount: 8, + size: '1024x1024', + style: 'pixel-art', + padding: 2, + itemType: 'weapon', + background: 'transparent', + save: true +}); +console.log(itemSprites.itemSheet); +``` + +### 8. fetchAvailableAnimationStates +**Location**: `/spriteAI/index.js` + +Fetches available animation states. + +```javascript +async function fetchAvailableAnimationStates() +``` + +#### Example Usage: +```javascript +const animationStates = await fetchAvailableAnimationStates(); +console.log(animationStates); +``` + +### 9. fetchAvailableSpriteStyles +**Location**: `/spriteAI/index.js` + +Fetches available sprite styles. + +```javascript +async function fetchAvailableSpriteStyles() +``` + +#### Example Usage: +```javascript +const spriteStyles = await fetchAvailableSpriteStyles(); +console.log(spriteStyles); +``` + ## How to Extend 1. **Add New Image Processing Function** diff --git a/spriteAI/README.md b/spriteAI/README.md index e0d0cd2a..f64c3dfd 100644 --- a/spriteAI/README.md +++ b/spriteAI/README.md @@ -69,6 +69,59 @@ removeBackgroundColor(inputPath, outputPath, targetColor, colorThreshold) }); ``` +### Generating Environment Sprites + +To generate environment tilesets, you can use the `generateEnvironmentSprites` function from the `spriteAI/index.js` file. Here’s an example: + +```javascript +import { generateEnvironmentSprites } from './spriteAI/index.js'; + +const description = 'a fantasy forest'; +const options = { + elements: 6, + size: '1024x1024', + style: 'pixel-art', + padding: 2, + theme: 'fantasy', + save: true +}; + +generateEnvironmentSprites(description, options) + .then(result => { + console.log('Environment sprites generated:', result.tileset); + }) + .catch(error => { + console.error('Error generating environment sprites:', error); + }); +``` + +### Generating Item Sprites + +To generate item collections, you can use the `generateItemSprites` function from the `spriteAI/index.js` file. Here’s an example: + +```javascript +import { generateItemSprites } from './spriteAI/index.js'; + +const description = 'medieval weapons'; +const options = { + itemCount: 8, + size: '1024x1024', + style: 'pixel-art', + padding: 2, + itemType: 'weapon', + background: 'transparent', + save: true +}; + +generateItemSprites(description, options) + .then(result => { + console.log('Item sprites generated:', result.itemSheet); + }) + .catch(error => { + console.error('Error generating item sprites:', error); + }); +``` + ## Directory Structure - `index.js`: Main logic for generating spritesheets and removing backgrounds. @@ -83,4 +136,4 @@ Contributions are welcome! Please open an issue or submit a pull request for any ## License -This project is licensed under the MIT License. See the LICENSE file for more details. \ No newline at end of file +This project is licensed under the MIT License. See the LICENSE file for more details. diff --git a/spriteAI/index.js b/spriteAI/index.js index aea59749..8d5aa4ad 100644 --- a/spriteAI/index.js +++ b/spriteAI/index.js @@ -1,4 +1,3 @@ -// filepath: /spriteAI/index.js import OpenAI from "openai"; import axios from "axios"; import sharp from "sharp"; @@ -230,4 +229,4 @@ export const generateItemSprites = async function(description, options = {}) { } } }; -}; \ No newline at end of file +}; diff --git a/tests/sprite.test.js b/tests/sprite.test.js index ffb81f7e..fa140c98 100644 --- a/tests/sprite.test.js +++ b/tests/sprite.test.js @@ -2,6 +2,7 @@ const sprite = require('./index').sprite; const fs = require('fs'); const path = require('path'); const sharp = require('sharp'); +const { generateEnvironmentSprites, generateItemSprites, fetchAvailableAnimationStates, fetchAvailableSpriteStyles } = require('../spriteAI/index'); describe('sprite', () => { describe('generateSprite', () => { @@ -46,4 +47,67 @@ describe('sprite', () => { // Add more test cases as needed }); -}); \ No newline at end of file +}); + +describe('generateEnvironmentSprites', () => { + it('should generate environment sprites with the correct dimensions', async () => { + const description = 'a fantasy forest'; + const options = { + elements: 6, + size: '1024x1024', + style: 'pixel-art', + padding: 2, + theme: 'fantasy', + save: false + }; + const result = await generateEnvironmentSprites(description, options); + + expect(result).toBeDefined(); + expect(result.tileset).toBeDefined(); + expect(result.metadata).toBeDefined(); + expect(result.metadata.elements).toBe(options.elements); + expect(result.metadata.theme).toBe(options.theme); + }); +}); + +describe('generateItemSprites', () => { + it('should generate item sprites with the correct dimensions', async () => { + const description = 'medieval weapons'; + const options = { + itemCount: 8, + size: '1024x1024', + style: 'pixel-art', + padding: 2, + itemType: 'weapon', + background: 'transparent', + save: false + }; + const result = await generateItemSprites(description, options); + + expect(result).toBeDefined(); + expect(result.itemSheet).toBeDefined(); + expect(result.metadata).toBeDefined(); + expect(result.metadata.itemCount).toBe(options.itemCount); + expect(result.metadata.itemType).toBe(options.itemType); + }); +}); + +describe('fetchAvailableAnimationStates', () => { + it('should fetch available animation states', async () => { + const result = await fetchAvailableAnimationStates(); + + expect(result).toBeDefined(); + expect(Array.isArray(result)).toBe(true); + expect(result.length).toBeGreaterThan(0); + }); +}); + +describe('fetchAvailableSpriteStyles', () => { + it('should fetch available sprite styles', async () => { + const result = await fetchAvailableSpriteStyles(); + + expect(result).toBeDefined(); + expect(Array.isArray(result)).toBe(true); + expect(result.length).toBeGreaterThan(0); + }); +});