Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

9 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 

Repository files navigation

EcoJSON to EcoCalc TypeScript Converter

This project provides a C# Polyglot Notebook (.dib) for converting raw Eco game recipe JSON data into TypeScript files compatible with the EcoCraftingTool (EcoCalc) web application.

It automates data synchronization between a running Eco server (via API or local JSON export) and the EcoCalc project’s TypeScript data models.


🧩 Overview

EcoCalc uses TypeScript source files (recipes.ts, items.ts, skills.ts, crafting-tables.ts, etc.) to represent all game data.
This notebook reads the original Eco recipes JSON, either from the server's API, and generates updated .ts files that EcoCalc can immediately use.


⚙️ Features

  • Fetch live data directly from an Eco server API (/api/v1/plugins/EcoPriceCalculator/recipes)
  • Deserialize and cleanse the JSON for compatibility with EcoCalc structures
  • Automatically split multi-skill crafting tables into profession-specific versions
    (e.g. Sawmill → Sawmill (Carpentry) and Sawmill (Logging))
  • Generate new TypeScript source files for:
    • Recipes
    • Items
    • Skills
    • Crafting Tables
  • Preserve backups of original .ts files with timestamps
  • Automatic cleanup of old backups and temporary output directories
  • Toggleable logic via flags (e.g., GenerateCraftingTableBySkill = true)

🧠 How It Works

  1. Load the JSON data
    Directly from the API endpoint.
  2. Deserialize into structured objects
    Converts JSON into strongly typed C# classes like RecipeCollection, EcoCalcItem, etc.
  3. Optionally process recipes
    If enabled, splits crafting tables by profession.
  4. Convert to TypeScript
    Uses methods like ConvertToTypeScriptRecipes, ConvertToTypeScriptItems, etc.
  5. Write and back up
    Generates .ts files inside CustomRecipes/ and replaces the originals in the EcoCalc project.
    Backs up the originals as _YYYYMMDD_HHmmss.ts.

🧰 Requirements

  • VS Code with the Polyglot Notebooks extension
  • .NET 6.0 or newer
  • Newtonsoft.Json and System.Text.Json (handled via #r "nuget: ...")

📂 File Outputs

TypeScript File Description
recipes.ts Full list of all crafting recipes
items.ts Item definitions used across recipes
skills.ts Skill definitions and metadata
crafting-tables.ts Crafting table definitions, including profession-specific variants

All generated files are backed up automatically as: recipes_20250306_182719.ts


🔄 Configuration Flags

Variable Description Default
GenerateCraftingTableBySkill Split shared crafting tables by skill true
basePath Path to EcoCalc /src/assets/data/ directory (set manually in notebook)

🧪 Typical Workflow

  1. Open ConvertEcojsonToEcoCalcTs.dib in VS Code.
  2. Set your paths and flags (top of the notebook).
  3. Run the notebook:
    • Fetches data
    • Cleans it
    • Converts to .ts
    • Backs up originals
  4. Review generated files in CustomRecipes/ or directly in your EcoCalc repo.

💡 Example Split

Before:

getCraftingTableByNameID('SawmillObject')
```6

### After
```ts
getCraftingTableByNameID('SawmillCarpentryObject')
getCraftingTableByNameID('SawmillLoggingObject')

This ensures profession-specific upgrades and specialization mechanics work correctly in EcoCalc.


🛡️ Backup & Safety

Each time the notebook runs:

  • Original files are backed up with timestamps
  • Previous backups are automatically pruned
  • CustomRecipes/ output directory is cleaned before regeneration

🌱 About EcoCalc

EcoCalc (also known as Eco Crafting Calculator) is an open-source web tool designed to help Eco players and server administrators manage recipes, materials, and crafting workflows.

This notebook was created to extend EcoCalc’s data generation pipeline, allowing users to:

  • Pull live recipe data from Eco servers
  • Automatically generate profession-split crafting tables
  • Keep EcoCalc’s TypeScript data (recipes.ts, items.ts, etc.) up-to-date with the latest Eco content

🧔‍♂️ Special Thanks

Mr Jobber Man - greenleafcalc.co.uk
For inspiring this automation workflow and integrating it into the Greenleaf Eco Server Tools project.
His Greenleaf calculator uses the data generated by this notebook to power real-time custom recipe calculations and visualizations.


❤️ Credits

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors