New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for embedded palettes and other sprite metadata #15668

Merged
merged 4 commits into from Oct 28, 2018

Conversation

Projects
None yet
4 participants
@pchote
Copy link
Member

pchote commented Oct 1, 2018

Games commonly stored useful metadata (e.g. palettes, weapon offsets, tileset data) alongside the pixel data in their sprite files. We used to require modders to load this extra data using a custom trait, adding both complexity and load-time overheads.

This PR extends ISpriteLoader with support for returning an arbitrary metadata TypeDictionary, which can be exported via the sequence parser (and, in the future, the tilesert parser) for use by traits.

This plumbing is used to expose palettes embedded in png and r8 files via the EmbeddedPalette sequence entry and PaletteFromEmbeddedSpritePalette trait.

@@ -57,9 +62,20 @@ public R8Frame(Stream s)

Data = s.ReadBytes(width * height);

// Ignore palette
// Palette palette

This comment has been minimized.

@IceReaper

IceReaper Oct 1, 2018

Contributor

Should be // Read palette

@@ -93,6 +113,8 @@ public class DefaultSpriteSequence : ISpriteSequence
public int[] Frames { get; private set; }
public Rectangle Bounds { get; private set; }

public readonly uint[] EmbeddedPalette = null;

This comment has been minimized.

@IceReaper

IceReaper Oct 1, 2018

Contributor

Initializing field by default value is redundant.


namespace OpenRA.Mods.Common.Traits
{
class PaletteFromEmbeddedSpritePaletteInfo : ITraitInfo

This comment has been minimized.

@IceReaper

IceReaper Oct 2, 2018

Contributor

should be public

public object Create(ActorInitializer init) { return new PaletteFromEmbeddedSpritePalette(this); }
}

class PaletteFromEmbeddedSpritePalette : ILoadsPalettes, IProvidesAssetBrowserPalettes

This comment has been minimized.

@IceReaper

IceReaper Oct 2, 2018

Contributor

should be public

@pchote

This comment has been minimized.

Copy link
Member

pchote commented Oct 6, 2018

Depends on #15652.

@pchote pchote force-pushed the pchote:sprite-metadata branch from d52fbbd to b6fbc1d Oct 7, 2018

@pchote

This comment has been minimized.

Copy link
Member

pchote commented Oct 7, 2018

Rebased and updated. I don't have a testcase for embedded cursor palettes, so will need somebody to test this.

@reaperrr

This comment has been minimized.

Copy link
Contributor

reaperrr commented Oct 7, 2018

PaletteFromEmbeddedSpritePaletteInfo must explicitly implement the interface member IProvidesCursorPaletteInfo.ReadPalette

@pchote pchote force-pushed the pchote:sprite-metadata branch from b6fbc1d to 2e5af54 Oct 7, 2018

@pchote

This comment has been minimized.

Copy link
Member

pchote commented Oct 7, 2018

Fixed.

@OpenRA OpenRA deleted a comment from pchote Oct 24, 2018

@@ -66,6 +69,11 @@ public bool TryParseSprite(Stream s, out ISpriteFrame[] frames)
Array.Copy(png.Data, frameStart + y * png.Width, frames[i].Data, y * frames[i].Size.Width, frames[i].Size.Width);
}

metadata = new TypeDictionary
{
new EmbeddedSpritePalette(png.Palette.Select(x => (uint)x.ToArgb()).ToArray())

This comment has been minimized.

@IceReaper

IceReaper Oct 24, 2018

Contributor

In case of PNG, wouldnt it make sense to make all png metadata available?

This comment has been minimized.

@pchote

pchote Oct 24, 2018

Member

Done.

@pchote pchote dismissed stale reviews from IceReaper and abcdefg30 via 8728df5 Oct 24, 2018

@pchote pchote force-pushed the pchote:sprite-metadata branch from 2e5af54 to 8728df5 Oct 24, 2018

@pchote pchote merged commit 2ad8179 into OpenRA:bleed Oct 28, 2018

2 checks passed

continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details

@pchote pchote deleted the pchote:sprite-metadata branch Nov 18, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment