Skip to content

Commit

Permalink
Merge pull request #180 from HerrZatacke/develop
Browse files Browse the repository at this point in the history
Version 1.42.2
  • Loading branch information
HerrZatacke authored Sep 4, 2024
2 parents b1d29b4 + aa5144d commit 4ffcd9f
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 7 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "gb-printer-web",
"version": "1.42.1",
"version": "1.42.2",
"description": "gb-printer-web",
"scripts": {
"start": "webpack serve --config ./scripts/webpack.dev.js",
Expand Down
6 changes: 6 additions & 0 deletions src/javascript/app/store/middlewares/animate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import type { State } from '../State';
import unique from '../../../tools/unique';
import type { ProgressCreateGifAction } from '../../../../types/actions/ProgressActions';
import type { ErrorAction } from '../../../../types/actions/GlobalActions';
import { loadFrameData } from '../../../tools/applyFrame/frameData';

interface GifFrameData {
palette: number[],
Expand Down Expand Up @@ -142,6 +143,10 @@ const createAnimation = async (state: State, dispatch: Dispatch<AnyAction>) => {
const tiles = await tileLoader(image.hash);
const palette = getImagePalette(state, image);

const frame = state.frames.find(({ id }) => id === image.frame);
const frameData = frame ? await loadFrameData(frame.hash) : null;
const imageStartLine = frameData ? frameData.upper.length / 20 : 2;

if (!tiles || !palette) {
throw new Error('missing tiles or palette');
}
Expand All @@ -167,6 +172,7 @@ const createAnimation = async (state: State, dispatch: Dispatch<AnyAction>) => {
tiles: tiles as string[],
palette: (palette as Palette).palette as string[],
lockFrame,
imageStartLine,
invertPalette,
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import type {
import type { ImagesUpdateAction } from '../../../../../types/actions/ImageActions';
import { DialoqQuestionType } from '../../../../../types/Dialog';
import type { RepoContents } from '../../../../../types/Export';
import { loadFrameData } from '../../../../tools/applyFrame/frameData';

interface WithContentHash {
dropboxContentHash: string,
Expand Down Expand Up @@ -232,11 +233,15 @@ const middleware = (store: TypedStore): ((action: AnyAction) => Promise<void>) =
const imagePalette = getImagePalette(state, image);
const tiles = await loadTiles(image.hash);

const frame = state.frames.find(({ id }) => id === image.frame);
const frameData = frame ? await loadFrameData(frame?.hash) : null;
const imageStartLine = frameData ? frameData.upper.length / 20 : 2;

if (!imagePalette || !tiles) {
throw new Error('palette or tiles missing');
}

const imageBlobs = await prepareFiles(imagePalette, image)(tiles);
const imageBlobs = await prepareFiles(imagePalette, image)(tiles, imageStartLine);

const result = await Promise.all(
imageBlobs.map(async (dlInfo: DownloadInfo): Promise<DownloadArrayBuffer> => ({
Expand Down
6 changes: 6 additions & 0 deletions src/javascript/app/store/middlewares/plugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import type { Plugin, PluginArgs, PluginClassInstance, PluginConfigValues, Plugi
import type { TypedStore } from '../State';
import type { ProgressExecutePluginAction } from '../../../../types/actions/ProgressActions';
import type { PluginUpdatePropertiesAction } from '../../../../types/actions/PluginActions';
import { loadFrameData } from '../../../tools/applyFrame/frameData';

interface RegisteredPlugins {
[url: string]: PluginClassInstance,
Expand Down Expand Up @@ -66,6 +67,10 @@ const pluginsMiddleware: MiddlewareWithState = (store) => {
const tiles = await getTiles();
let decoder: RGBNDecoder | Decoder;

const frame = state.frames.find(({ id }) => id === meta.frame);
const frameData = frame ? await loadFrameData(frame.hash) : null;
const imageStartLine = frameData ? frameData.upper.length / 20 : 2;

if (isRGBN) {
decoder = new RGBNDecoder();
decoder.update({
Expand All @@ -81,6 +86,7 @@ const pluginsMiddleware: MiddlewareWithState = (store) => {
tiles: tiles as string[],
palette: (palette as Palette).palette as string[],
lockFrame,
imageStartLine,
invertPalette,
});
}
Expand Down
9 changes: 8 additions & 1 deletion src/javascript/app/store/middlewares/share.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { loadImageTiles } from '../../../tools/loadImageTiles';
import getImagePalette from '../../../tools/getImagePalette';
import { Actions } from '../actions';
import type { MiddlewareWithState } from '../../../../types/MiddlewareWithState';
import { loadFrameData } from '../../../tools/applyFrame/frameData';

const batch: MiddlewareWithState = (store) => (next) => async (action) => {

Expand All @@ -14,6 +15,8 @@ const batch: MiddlewareWithState = (store) => (next) => async (action) => {
throw new Error('image not found');
}

const frame = state.frames.find(({ id }) => id === image.frame);

const imagePalette = getImagePalette(state, image);
if (!imagePalette) {
throw new Error('imagePalette not found');
Expand All @@ -30,7 +33,11 @@ const batch: MiddlewareWithState = (store) => (next) => async (action) => {

const tiles = await loadImageTiles(state)(image.hash);

const downloadInfo = await prepareFiles(imagePalette, image)(tiles || []);
const frameData = frame ? await loadFrameData(frame?.hash) : null;

const imageStartLine = frameData ? frameData.upper.length / 20 : 2;

const downloadInfo = await prepareFiles(imagePalette, image)(tiles || [], imageStartLine);

const { blob, filename, title } = downloadInfo[0];

Expand Down
18 changes: 16 additions & 2 deletions src/javascript/app/store/middlewares/startDownload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { Actions } from '../actions';
import type { State } from '../State';
import type { PrepareFilesReturnType } from '../../../tools/download/getPrepareFiles';
import type { MiddlewareWithState } from '../../../../types/MiddlewareWithState';
import { loadFrameData } from '../../../tools/applyFrame/frameData';

const handleSingleImage = (
prepareFiles: PrepareFilesReturnType,
Expand All @@ -17,6 +18,8 @@ const handleSingleImage = (
throw new Error('image not found');
}

const frame = state.frames.find(({ id }) => id === image.frame);

const imagePalette = getImagePalette(state, image);
if (!imagePalette) {
throw new Error('imagePalette not found');
Expand All @@ -29,11 +32,15 @@ const handleSingleImage = (

const tiles = await loadImageTiles(state)(image.hash);

const frameData = frame ? await loadFrameData(frame?.hash) : null;

const imageStartLine = frameData ? frameData.upper.length / 20 : 2;

if (!tiles) {
throw new Error('no tiles');
}

const files = await prepareFiles(imagePalette, image)(tiles);
const files = await prepareFiles(imagePalette, image)(tiles, imageStartLine);
return download(zipFilename)(files);
};

Expand All @@ -50,13 +57,20 @@ const handleImageCollection =
throw new Error('image not found');
}

const frame = state.frames.find(({ id }) => id === image.frame);

const imagePalette = getImagePalette(state, image);
if (!imagePalette) {
throw new Error('imagePalette not found');
}

const tiles = await loadImageTiles(state)(image.hash);
return prepareFiles(imagePalette, image)(tiles || []);

const frameData = frame ? await loadFrameData(frame?.hash) : null;

const imageStartLine = frameData ? frameData.upper.length / 20 : 2;

return prepareFiles(imagePalette, image)(tiles || [], imageStartLine);
}))
.then((resultImages) => resultImages.flat())
.then(download(zipFilename));
Expand Down
2 changes: 2 additions & 0 deletions src/javascript/tools/download/getPrepareFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const getPrepareFiles =
image: Image,
) => async (
tiles: string[] | RGBNTiles,
imageStartLine: number,
): Promise<DownloadInfo[]> => {
const { exportScaleFactors, exportFileTypes, handleExportFrame } = state;

Expand All @@ -42,6 +43,7 @@ const getPrepareFiles =
tiles: tiles as string[],
palette: (palette as Palette).palette as string[],
lockFrame,
imageStartLine,
invertPalette,
});
}
Expand Down

0 comments on commit 4ffcd9f

Please sign in to comment.