Code Monkey home page Code Monkey logo

lpc-spritesheet-generator's Introduction

LPC Spritesheet Generator

A browser app for generating spritesheets for Liberated Pixel Cup characters.

Try it out here.

Licensing and Attribution

The code is available under the MIT license.

Specific license details for each image varies, but all images are licensed under at least one of: CC-BY-SA 3.0, CC-BY-SA 4.0, OGA-BY 3.0, GPL 3.0, or a more permissive license. Licensing details for each item are in sheet-definitions.json.

Adding items to the generator

Spritesheets

Folder Structure and Naming

Each spritesheet should be split into individual animations (walk, cast, idle, etc.) and should be stored in ./resources/spritesheets/category/item/animation.png

For example, the male character base is in the category body, so the paths to the walk, cast, and idle animations would be: ./resources/spritesheets/body/male/walk.png ./resources/spritesheets/body/male/cast.png ./resources/spritesheets/body/male/idle.png

Sheet Definitions

Every new item must also have a definition file which should be stored in ./resources/sheet-definitions/category/item.json. The path to the definition for the male character base is ./resources/sheet-definitions/body/male.json.

The definitions are structured as JSON data. For the male character base they would look like this:

{
  "default": true,
  "tags": [
    "male",
    "adult"
  ],
  "excluded-by": [],
  "palettes": [
    "skin",
    "eyes"
  ],
  "z_position": 25,
  "authors": [
    "Stephen Challener (Redshrike)",
    "Johannes Sjölund (wulax)"
  ],
  "licenses": [
    "CC-BY-SA 3.0",
    "GPL 3.0"
  ],
  "links": [
    "https://opengameart.org/content/liberated-pixel-cup-lpc-base-assets-sprites-map-tiles",
    "https://opengameart.org/content/lpc-medieval-fantasy-character-sprites"
  ]
}
  • default (optional) sets if this is the default option for the category. If multiple items are set as the default the first will be used. If this is not set for any item in the category it will default to "none"
  • tags (optional) used with excluded-by to hide incompatible items
  • excluded-by (optional) a list of tags. If it includes any tags on selected items then this item will not appear as an option
  • palettes (optional) the palette-definitions key for each palette used by the image. If it is left blank then the item will not be recolorable. List multiple palettes if the item has multiple recolorable pieces (a shirt with stripes, helmet with a feather, etc.)
  • z_position (optional) overrides the category's default z position
  • label (optional) the label for the item in the option picker. Defaults to the name of the item. If a selection is made incompatible with the spritesheet (e.g. by switching from the male to female body) a compatible item with the same label will automatically activate if one is available in the same category. Both the label and item name will be included in the attribution.
  • authors (required) a list of everyone who contributed to creating this item
  • licenses (required) a list of every license the authors applied to the item
  • links (required) a list of links to the item's source. It should include at least a link to the item's Open Game Art page

Color Palettes

Color palettes also have definition files, which should be added to ./resources/palette-definitions.

The file should be a JSON file named for the palette. The content is an array of color ramps.

Each color ramp is an array of color hexcodes. The first color will be the fill color for the button in the UI, and the second will be the border. The first color ramp is the default for that palette.

Images should use the first color ramp of any palette they use. The do not need to include all the colors, but only colors listed in the first color ramp will be recolored.

A truncated example of a palette definition:

{
  [
    ["#faece7", "#f9d5ba", "#e4a47c", "#cc8665", "#99423c", "#271920"],
    ["#deac9b", "#d68c61", "#a96b4c", "#895b4a", "#593636", "#2a1722"],
    ["#714535", "#603429", "#442725", "#2e1f1c", "#1a1213", "#050606"]
  ]
}

Running locally

This should work with any recent version of Node, but has been tested on the version specified by the .node-version file.

npm install
npm start

You should then be able to visit http://localhost:8080.

To run the server on a different port:

npm start -- --port 4000

If you add or modify a definition file you can recompile the merged definitions without restarting the server by running:

npm run merge-definitions

lpc-spritesheet-generator's People

Contributors

bencreating avatar kylesmile avatar

Stargazers

rongyao avatar Gibran Ali avatar Andreas Volz avatar  avatar  avatar

Watchers

 avatar

Forkers

honor-game

lpc-spritesheet-generator's Issues

Multi-layer assets

Some items require multiple layers, such as long hair that has a piece that needs to be drawn in front of everything, and a second piece that needs to be drawn behind everything.

Problems to solve:

  • How to indicate additional images in the sheet definitions
  • Naming and folder structure for additional images

Filter options

As more options are added it would be nice to have ways to filter them by license, supported animations, etc.

Collapsible categories and colors

As more items are added to the generator the sidebar will start to become difficult to navigate. Collapsing the categories and the colors would help this issue a lot.

Categories could hide all options except the selected one, and the colors could be in a color selection menu.

A rough mockup of how this could look:

collapsible-category-design

Match head to body color

Currently, the color needs to be set separately for the head and body. This will be extra annoying once ears and noses are added.

This should be implemented in a way that allows the user to override the color if they want. This could possibly be done by adding a special "match" color option that is selected by default.

Customize GitHub Pages deploy

As of August 10, GitHub Pages build and deploy using GitHub Actions, which should allow customizing the build process. This opens up several possibilities, including:

  • Processing CSS with Autoprefixer.
  • Split sheet definition JSON files, which are combined (or an index file created) in a build step
  • JavaScript bundling. Useful for external packages, but otherwise not crucial.
  • Asset fingerprinting. Though, GitHub Pages sets a 10 minute max-age in the Cache-Control header, so this isn't a huge win.

Implement custom animations

Sanderfrenken's generator recently implemented a feature where certain assets can declare new animations by re-arranging existing animation frames. Example: the fishing rod uses frames from the "thrust" animation, played in a different order. https://sanderfrenken.github.io/Universal-LPC-Spritesheet-Character-Generator/#?body=Body_color_light&head=Human_male_light&weapon=Rod_rod .

Implementation there: https://github.com/sanderfrenken/Universal-LPC-Spritesheet-Character-Generator/blob/master/sources/chargen.js#L406-L471

Implementation here would likely be related to #2

Oversized animation

This would require being able to set the frame size for an asset in the sheet definitions file. This may need to be done on a per-animation basis.

Other selected assets would need to be drawn to fit the largest frame size.

Transfer assets and metadata from existing generator to this one

All assets, metadata, and credits will eventually need to be transferred from https://github.com/sanderfrenken/Universal-LPC-Spritesheet-Character-Generator to here:

a. Images are stored like this in this generator https://github.com/BenCreating/LPC-Spritesheet-Generator/tree/main/resources/spritesheets/pants/male vs. like this in Sander's generator: https://github.com/sanderfrenken/Universal-LPC-Spritesheet-Character-Generator/tree/master/spritesheets/legs/pants/male . It would generally be possible to convert from one to the other using lpctools but someone will need to go through and do so, either manually or with a script.

b. Image/layer metadata is stored like this https://github.com/sanderfrenken/Universal-LPC-Spritesheet-Character-Generator/blob/master/sheet_definitions/cape_solid.json in Sander's generator, vs. like this here https://github.com/BenCreating/LPC-Spritesheet-Generator/blob/main/resources/sheet-definitions.json#L491-L548 . Again, will need to be translated. Ben's generator also uses a slightly different ontology, which I'll discuss below.

c. Sander's generator stores attributions in this format https://github.com/sanderfrenken/Universal-LPC-Spritesheet-Character-Generator/blob/master/CREDITS.csv while this generator stores credits in this format https://github.com/BenCreating/LPC-Spritesheet-Generator/blob/main/resources/sheet-definitions.json#L503-L516 . These would need to be translated over, accounting for any changes in arrangement of the image files described in 2a.

4 sprite poses only

Would like to use this tool but for my needs, I would like a single sprite pose for each direction.

How would I go about getting this generator to make a sprite with only Left/right/Up/down poses. Do not need to be animated.

Also a side question, how would I export an upscaled version?

Preview all animations at once

Maybe add a checkbox that replaces the full spritesheet with the preview? I'm not sure if there's any other way to display all animations at once, especially as more animations are added.

Use names for colors

Names would make discussions easier and the color URL parameters would be less brittle if the order ever changes.

Data model: group related assets for different body types

I'd like to propose changing the structure of data in sheet-definitions.json:

  • in Sander's generator, even though male and female pants (for example) use different images, they are treated as the same "asset;" that is, they share the same JSON metadata file in sheet_definitions and represent a single entry in the tree on the left side of the generator. A different image is applied depending on the selected body type. https://github.com/sanderfrenken/Universal-LPC-Spritesheet-Character-Generator/blob/master/sheet_definitions/legs_pants.json#L6-L9 (It is also possible that one image is used for multiple or even all body types; for example, the "female" shoes are used for female, teen, and pregnant body types).
    • The main advantage: if you have red pants selected on a male character and you change the body type to "female", the character updates automatically and keeps their red pants, but adapted to the female body. In this generator, when you do the same thing... actually the body type changes but the character keep their male pants, which seems like a bug :p Anyway I think Sander's behavior is more desirable.
  • in this generator, male pants and female pants are treated as separate metadata entries https://github.com/BenCreating/LPC-Spritesheet-Generator/blob/main/resources/sheet-definitions.json#L439-L489 and there doesn't seem to be a clear connection between them.
    • This generator should allow for a more flexible system of constraints, e.g. certain assets could be declared mutually exclusive on criteria other than body type.

There's a related issue with credits: in Sander's generator, credits are assigned to each image. In Ben's generator, they are assigned to the asset. In a lot of cases, one person draws the "male" version of the asset and someone else adapts it to the "female" (and other) version(s), so the credits for the male and female version of an asset are overlapping but not identical. In Ben's current setup, this situation kinda requires any two objects that have separate attributions to be separate "assets" (i.e. separate entries in resources/sheet-definitions.json.

I would propose that this generator adopt a model of "one asset, multiple images", similar to Sander's generator. In fact, perhaps we can (ab)use the notion of layers to implement this model, and create a "cascading" series of definitions: category > asset > layer:

  • Each category (e.g. https://github.com/BenCreating/LPC-Spritesheet-Generator/blob/main/resources/category-definitions.json) contains zero or more assets, which are mutually exclusive. The category has some default properties (e.g. z_order, tags, perhaps others)? that apply to any assets in that category, but that can be overridden by assets or layers.
  • Each asset contains one or more layers. The asset can have properties such as excluded-by, credits, tags, palettes, etc.; if given, those properties will serve as defaults for all layers within the asset.
  • Each layer has properties like excluded-by, credits, tags, palettes, etc. If given, these override properties with the same name from the asset.
  • An asset is selectable in the generator as long as one or more of its layers is selectable, i.e. it is not excluded by any tags used by any other assets (at least, I think that is how the excluded-by key is supposed to work; put another way, an asset is selectable if at least one of its layers is not excluded).
  • Credits are assembled for a sheet by combining the credits for all layers in use.
    • within a layer, the credits block would by default overwrite the credits for the asset. However, the layer credits block can have an append key, which, if true, causes any authors and links given to be appended to those for the asset. For example, it is often the case that someone draws an original asset for the male body type, then someone else adapts it to the female body. So the credits for the female version are (credits for the male version) + (additional author and/or URLs). (licenses probably shouldn't work this way, since the rules about when more licenses can be added to a derivative work are complicated.)

Example:

"cape": {
    "solid": {
      "tags": [],
      "credits": {
        "authors": [
          "bluecarrot16",
          "David Conway Jr. (JaidynReiman)",
          "Nila122"
        ],
        "licenses": [
          "CC-BY-SA 3.0",
          "GPL 3.0"
        ],
        "links": [
          "https://opengameart.org/content/lpc-curly-hair-elven-ears-white-cape-with-blue-trim-and-more",
          "https://opengameart.org/content/lpc-roman-armor",
          "http://opengameart.org/content/lpc-clothing-updates"
        ],            
      },
      "palettes": [
        "cloth"
      ],
      "layers": {
        "male": {
          "excluded-by": [
            "child",
            "muscular",
            "female",
            "teen"
          ]
        },
        "female": {
          "excluded-by": [
            "child",
            "muscular",
            "male"
          ],
          "credits": {
            "append": true,
            "authors": [
              "someone_else_who_made_the_female_version"
            ],
            "links": [
              "http://opengameart.org/content/lpc-special-clothing-modifications"
            ],
          }
        },
        "solid_behind": {"z_position": 5 }
      }
    }
  }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.