WIP: Template Upload
- Drag and drop - Launche template TODO: Banner generation TODO: File dialog
This commit is contained in:
+17
-30
@@ -11,6 +11,7 @@ import europa from '$lib/assets/fonts/Europa-Mono-Medium.otf';
|
||||
import { BASE_LIBRARY_DIR } from './settings';
|
||||
import figlet from 'figlet';
|
||||
import shadow from 'figlet/fonts/Classy';
|
||||
import { getInstalledVersions } from './library';
|
||||
figlet.parseFont('Big', shadow);
|
||||
|
||||
/**
|
||||
@@ -58,10 +59,10 @@ export async function createIcon(iconText) {
|
||||
|
||||
/**
|
||||
* Create a custom banner with version number next to the baseIcon image
|
||||
* @param {string} versionText - Version text to display
|
||||
* @param {string} text - Version text to display
|
||||
* @returns {Promise<Blob>} Promise resolving to a PNG blob of the banner
|
||||
*/
|
||||
export async function createBanner(versionText) {
|
||||
export async function createBanner(text) {
|
||||
// Create canvas element for banner
|
||||
const canvas = document.createElement('canvas');
|
||||
const ctx = canvas.getContext('2d');
|
||||
@@ -82,11 +83,6 @@ export async function createBanner(versionText) {
|
||||
img.onload = resolve;
|
||||
});
|
||||
|
||||
// Calculate icon position (centered vertically, left-aligned)
|
||||
const iconSize = 70;
|
||||
const iconX = 20;
|
||||
const iconY = (canvas.height - iconSize) / 2;
|
||||
|
||||
// Add version text
|
||||
ctx.fillStyle = '#f5f5f5';
|
||||
ctx.textAlign = 'left';
|
||||
@@ -102,7 +98,9 @@ export async function createBanner(versionText) {
|
||||
const textX = 20;
|
||||
const textY = canvas.height / 2;
|
||||
|
||||
const bannerText = await figlet.text(versionText + ' - Base', { font: 'Big' });
|
||||
const bannerText = await figlet.text(text, {
|
||||
font: 'Big'
|
||||
});
|
||||
const lines = bannerText.split('\n');
|
||||
const lineHeight = fontSize * 1.2;
|
||||
const startY = textY - (lines.length * lineHeight) / 2 + lineHeight / 2;
|
||||
@@ -121,6 +119,17 @@ export async function createBanner(versionText) {
|
||||
}, 'image/png');
|
||||
});
|
||||
}
|
||||
|
||||
export async function addTemplateFile(version, templateFilePath) {
|
||||
const newFileName = await pathBasename(templateFilePath);
|
||||
const templatesPath = await join(version.path, 'templates', newFileName);
|
||||
await copyFile(templateFilePath, templatesPath);
|
||||
|
||||
await getInstalledVersions();
|
||||
|
||||
console.log('adding ', templateFilePath, ' to ', version.path);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create library directory structure if it doesn't exist
|
||||
* @param {string} libraryDir - Library directory path
|
||||
@@ -131,10 +140,6 @@ export async function ensureLibraryStructure(libraryDir) {
|
||||
const baseDir = await join(libraryDir, BASE_LIBRARY_DIR);
|
||||
const blenderDir = await join(baseDir, 'blender');
|
||||
await mkdir(blenderDir, { recursive: true });
|
||||
|
||||
const templatesDir = await join(baseDir, 'templates');
|
||||
await mkdir(templatesDir, { recursive: true });
|
||||
|
||||
const configDir = await join(baseDir, 'config');
|
||||
await mkdir(configDir, { recursive: true });
|
||||
|
||||
@@ -201,24 +206,6 @@ export async function ensureDirectory(path) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the basename of a path (file or directory name)
|
||||
* @param {string} path - Full path
|
||||
* @returns {Promise<string>} Basename
|
||||
*/
|
||||
export async function basename(path) {
|
||||
return pathBasename(path);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the directory name of a path
|
||||
* @param {string} path - Full path
|
||||
* @returns {Promise<string>} Directory name
|
||||
*/
|
||||
export async function dirname(path) {
|
||||
return pathDirname(path);
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy a file or directory recursively
|
||||
* @param {string} source - Source path
|
||||
|
||||
Reference in New Issue
Block a user