mirror of
https://github.com/billsonnn/nitro-renderer.git
synced 2024-11-30 03:00:51 +01:00
Fix pet palettes
This commit is contained in:
parent
fe20138abf
commit
e96869d7eb
@ -1,5 +1,5 @@
|
|||||||
import { IGraphicAssetPalette } from '@nitrots/api';
|
import { IGraphicAssetPalette } from '@nitrots/api';
|
||||||
import { TextureUtils } from '@nitrots/utils';
|
import { GetRenderer } from '@nitrots/utils';
|
||||||
import { Texture } from 'pixi.js';
|
import { Texture } from 'pixi.js';
|
||||||
|
|
||||||
export class GraphicAssetPalette implements IGraphicAssetPalette
|
export class GraphicAssetPalette implements IGraphicAssetPalette
|
||||||
@ -20,18 +20,13 @@ export class GraphicAssetPalette implements IGraphicAssetPalette
|
|||||||
|
|
||||||
public applyPalette(texture: Texture): Texture
|
public applyPalette(texture: Texture): Texture
|
||||||
{
|
{
|
||||||
const pixelOutput = TextureUtils.getPixels(texture);
|
const canvas = GetRenderer().texture.generateCanvas(texture);
|
||||||
const pixels = pixelOutput?.pixels;
|
|
||||||
|
|
||||||
if(!pixels) return texture;
|
|
||||||
|
|
||||||
const canvas = document.createElement('canvas');
|
|
||||||
const ctx = canvas.getContext('2d');
|
const ctx = canvas.getContext('2d');
|
||||||
const imageData = ctx.createImageData(texture.width, texture.height);
|
const imageData = ctx.getImageData(0, 0, canvas.width, canvas.height);
|
||||||
|
|
||||||
for(let i = 0; i < pixels.length; i += 4)
|
for(let i = 0; i < imageData.data.length; i += 4)
|
||||||
{
|
{
|
||||||
let paletteColor = this._palette[pixels[i + 1]];
|
let paletteColor = this._palette[imageData.data[i + 1]];
|
||||||
|
|
||||||
if(paletteColor === undefined) paletteColor = [0, 0, 0];
|
if(paletteColor === undefined) paletteColor = [0, 0, 0];
|
||||||
|
|
||||||
@ -42,7 +37,12 @@ export class GraphicAssetPalette implements IGraphicAssetPalette
|
|||||||
|
|
||||||
ctx.putImageData(imageData, 0, 0);
|
ctx.putImageData(imageData, 0, 0);
|
||||||
|
|
||||||
return Texture.from(canvas);
|
const newTexture = Texture.from(canvas);
|
||||||
|
|
||||||
|
//@ts-ignore
|
||||||
|
newTexture.source.hitMap = imageData.data;
|
||||||
|
|
||||||
|
return newTexture;
|
||||||
}
|
}
|
||||||
|
|
||||||
public get primaryColor(): number
|
public get primaryColor(): number
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { AlphaTolerance } from '@nitrots/api';
|
import { AlphaTolerance } from '@nitrots/api';
|
||||||
import { TextureUtils } from '@nitrots/utils';
|
import { GetRenderer } from '@nitrots/utils';
|
||||||
import { Point, Sprite, Texture, TextureSource } from 'pixi.js';
|
import { Point, Sprite, Texture, TextureSource } from 'pixi.js';
|
||||||
|
|
||||||
export class ExtendedSprite extends Sprite
|
export class ExtendedSprite extends Sprite
|
||||||
@ -78,10 +78,12 @@ export class ExtendedSprite extends Sprite
|
|||||||
if(!textureSource) return false;
|
if(!textureSource) return false;
|
||||||
|
|
||||||
const texture = new Texture(textureSource);
|
const texture = new Texture(textureSource);
|
||||||
const pixels = TextureUtils.getPixels(texture);
|
const canvas = GetRenderer().texture.generateCanvas(texture);
|
||||||
|
const ctx = canvas.getContext('2d');
|
||||||
|
const imageData = ctx.getImageData(0, 0, canvas.width, canvas.height);
|
||||||
|
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
textureSource.hitMap = pixels.pixels;
|
textureSource.hitMap = imageData.data;
|
||||||
texture.destroy();
|
texture.destroy();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
Loading…
Reference in New Issue
Block a user