Skip to content

birucan/FishyBusiness

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

2 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

S

๐ŸŽฏ Core Concepts

Sprites vs Resources

  • Sprites: Visual assets (images) that define how things look
  • Resources: Instances of sprites placed in the world with specific positions and properties
  • Relationship: One sprite can be used to create many resources (1:N relationship)

Architecture Overview

Sprite Library โ†’ Resources โ†’ Pages โ†’ Canvas
     โ†“              โ†“         โ†“        โ†“
Visual Assets โ†’ Instances โ†’ Collections โ†’ Rendered View

๐Ÿš€ Getting Started

Prerequisites

  • Node.js (v14 or higher)
  • npm or yarn

Installation

# Clone the repository
git clone <repository-url>
cd sprite-canvas

# Install dependencies
npm install

# Start the development server
npm start

The application will open at http://localhost:3000.

๐Ÿ“ Project Structure

src/
โ”œโ”€โ”€ components/           # Reusable UI components
โ”‚   โ”œโ”€โ”€ Controls/        # Viewport control buttons
โ”‚   โ”œโ”€โ”€ Tabs/           # Page management interface
โ”‚   โ”œโ”€โ”€ Units/          # Resource rendering components
โ”‚   โ””โ”€โ”€ Viewport/       # Main canvas area
โ”œโ”€โ”€ hooks/              # Custom React hooks
โ”‚   โ”œโ”€โ”€ usePages.js     # Page and resource management
โ”‚   โ””โ”€โ”€ useViewport.js  # Canvas navigation and interaction
โ”œโ”€โ”€ data/               # Static data and sprite libraries
โ”‚   โ””โ”€โ”€ spritesLibrary.js
โ”œโ”€โ”€ types/              # Type definitions and factory functions
โ”‚   โ””โ”€โ”€ index.js
โ””โ”€โ”€ pages/              # Main application pages
    โ””โ”€โ”€ CanvasPage.jsx  # Primary application interface

๐ŸŽฎ Usage

Basic Operations

  1. Page Management: Create, switch, rename, and delete pages using the tab interface
  2. Sprite Selection: Choose sprites from the library in the left sidebar
  3. Resource Placement: Double-click on the canvas to place resources
  4. Resource Selection: Single-click resources to view properties
  5. Resource Deletion: Use Delete key or inspector button to remove resources
  6. Canvas Navigation: Mouse wheel to zoom, click-and-drag to pan

Keyboard Shortcuts

  • Delete or Backspace: Remove selected resource
  • Mouse Wheel: Zoom in/out
  • Click + Drag: Pan canvas
  • Double-click: Add resource at cursor position

๐Ÿ”ง Core Components

Hooks

usePages

Manages the page system and resource lifecycle:

  • Page creation, deletion, and switching
  • Resource addition, removal, and updates
  • State persistence across page transitions

useViewport

Handles canvas interaction and navigation:

  • Zoom controls (1x to 16x)
  • Pan/drag functionality
  • Coordinate transformation between world and screen space

Components

FishermanResource

Renders individual resource instances:

  • Displays sprite at world coordinates
  • Handles selection states
  • Shows health bars and visual feedback

Viewport

Main canvas area:

  • Renders all resources for current page
  • Manages interaction events
  • Applies zoom and pan transformations

PageTabs

Page management interface:

  • Tab-based page switching
  • Inline page renaming
  • Resource count indicators

๐Ÿ—๏ธ Extending the Application

Adding New Sprites

// In src/data/spritesLibrary.js
export const SPRITES_LIBRARY = {
  BOAT: createSprite('Boat', '/boat.png'),
  TREE: createSprite('Tree', '/tree.png', 64, 128), // Custom dimensions
  BUILDING: createSprite('Building', '/building.png'),
};

Creating Custom Resource Types

// Custom resource with specialized properties
const customResource = createResource(
  'custom_id',
  'sprite_tree',
  100, 200,
  {
    type: 'vegetation',
    health: 85,
    growth_stage: 'mature',
    seasonal_variant: 'summer'
  }
);

Adding New Resource Properties

Resources support flexible property systems:

const resourceProperties = {
  health: 100,           // Visual health bar
  speed: 1,              // Movement capability
  type: 'default',       // Resource classification
  // Custom properties...
  inventory: [],
  interactions: {},
  animations: {}
};

๐Ÿ“Š Data Flow

User Interaction โ†’ Event Handler โ†’ Hook Action โ†’ State Update โ†’ UI Re-render
      โ†“              โ†“              โ†“            โ†“            โ†“
   Double-click โ†’ handleAddResource โ†’ addResource โ†’ setPages โ†’ Canvas Update

๐Ÿ”„ Legacy Compatibility

The refactoring maintains backward compatibility:

  • FishResource component aliased to FishermanResource
  • createFishResource function aliased to createResource
  • CSS classes maintain legacy versions
  • Hook methods include both new and old naming

๐ŸŽจ Styling

The application uses a dark theme with:

  • Primary Color: #61dafb (cyan blue)
  • Background: #282c34 (dark gray)
  • Surfaces: #1e1e1e and #2a2a2a (darker grays)
  • Pixelated Rendering: Sprites maintain crisp pixel art appearance

๐Ÿš€ Performance Features

  • Efficient Re-renders: React keys and proper dependency management
  • Hardware Acceleration: CSS transforms for viewport operations
  • Event Optimization: Proper event listener cleanup
  • Memory Management: Immutable state updates prevent memory leaks

๐Ÿ”ฎ Future Enhancements

Potential features for expansion:

  • Animation System: Sprite animation sequences
  • Layer Management: Z-index and layer organization
  • Collision Detection: Resource interaction system
  • Import/Export: Save and load canvas configurations
  • Multiplayer: Real-time collaborative editing
  • Plugin System: Extensible functionality architecture

๐Ÿ“ License

This project is available under the MIT License.

๐Ÿค Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests if applicable
  5. Submit a pull request

๐Ÿ“š API Reference

Core Functions

createSprite(name, src, width?, height?)

Creates a sprite definition for the library.

createResource(id, spriteId, x, y, properties?)

Creates a resource instance from a sprite.

createPage(id, name, backgroundColor?)

Creates a new canvas page.

Hook APIs

usePages()

Returns page management state and actions.

useViewport()

Returns viewport state and interaction handlers.

About

fishing web game

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors