GithubHelp home page GithubHelp logo

hearthsim / sunwell Goto Github PK

View Code? Open in Web Editor NEW
95.0 19.0 20.0 50.5 MB

Canvas-based high quality Hearthstone card renderer - no longer maintained

License: MIT License

JavaScript 8.85% TypeScript 88.89% HTML 2.27%
canvas hearthstone card

sunwell's Introduction

This project is no longer maintained! Please see the forks page for a list of alternative repositores.

Sunwell

A high quality Hearthstone card renderer in TypeScript.

  • Use it as a Javascript library in the browser to render to a <canvas> element.
  • Or in NodeJS using node-canvas

Download

The latest, minified version of Sunwell is available here:

https://sunwell.hearthsim.net/branches/master/sunwell.cdn.min.js

Requirements

The following dependencies are required to build Sunwell:

Run yarn install to install the dependencies. Then, run webpack to build the project into dist/sunwell.js.

If you run NODE_ENV=production webpack, it will instead build a minified version into dist/sunwell.min.js.

The assets in the assets/ folder can be copied as-is.

Sunwell currently has no runtime dependencies outside of Webpack.

Fonts

To create faithful renders, the Belwe and Franklin Gothic proprietary fonts are required. Make sure to obtain a license if you wish to distribute cards rendered with them.

Sunwell should work with any fallback font you give it.

Usage

Instanciate a new Sunwell object as such:

const Sunwell = require("Sunwell").Sunwell;
let sunwell = new Sunwell(options);

The options object is defined further down.

To render a card, you can use Sunwell.createCard(card). Sunwell aims to be compatible with HearthstoneJSON. You can pass a card object from the HearthstoneJSON API as-is and get a usable card in return.

var card = sunwell.createCard(card, width, target, callback);

width is the size of the render (height is determined automatically). The target argument should be a Canvas or Image object the render will be applied to.

Internally, Sunwell renders to a Canvas already. If you target an image, the conversion to PNG and compression will result in performance loss with frequent updates. Rendering to a Canvas is more direct, however will likely result in performance degradation with large amounts of cards on screen. Pick your poison.

The optional callback argument is a function called when the rendering finishes.

Sunwell options

The following options can be forwarded to the Sunwell instance:

  • debug (boolean: false): If true, extra output will be logged.
  • titleFont (string: "Belwe"): The font to use for the card's name.
  • bodyFont (string: "Franklin Gothic"): The font to use for the card's body.
  • assetFolder (string: "/assets/"): The path to the assets folder.
  • cacheSkeleton (boolean: false): Whether to cache the card's frame render (slow).
  • drawTimeout (number: 5000): The maximum amount of milliseconds Sunwell will spend rendering any single card before giving up.
  • maxActiveRenders (number: 12): How many concurrent renders Sunwell will perform.
  • preloadedAssets (Array): A list of assets to always preload.

Card properties

The following card properties are supported:

  • name (string): The card's name
  • text (string): The card's body text
  • collectionText (string): The card's body text. Has precedence over text.
  • raceText (string): The card's race as a string. Has precedence over race.
  • cost (number): The card's cost.
  • attack (number): The card's attack value (has no effect for spells).
  • health (number): The card's health value (has no effect for spells).
  • costsHealth (boolean): Set to true to render the card's cost as health.
  • hideStats (boolean): Set to true to hide the attack/health textures and the cost value.
  • silenced (boolean): Set to true to show the card as silenced (card text crossed out).
  • language (string): The language of the card. Only used to determine the race text for enums.

Enums are standard Hearthstone enums. They can be passed as an int (preferred) or as their string variant:

  • type (enum CardType): The card's type (only MINION, SPELL and WEAPON are supported).
  • cardClass (enum CardClass): The card's class. This determines the card frame to use.
  • set (enum CardSet): Determines the body text background watermark.
  • rarity (enum Rarity): Determines the card's rarity gem. Note that COMMON cards from the CORE set will not show a rarity gem, despite not being FREE.
  • multiClassGroup (enum MultiClassGroup): Determines the card's multiclass banner.
  • race (enum Race): The card's race.

Finally, a texture property should be passed as well, for the card art. The texture may be a string, in which case it's treated as a URL, or it may be an Image. If null, an empty grey texture will be created in its place.

NOTE: Some properties only affect certain card types unless explicitly set on the card itself. For example, a spell or weapon will not render a race text even if given one.

Community

Sunwell is a HearthSim project. All development happens on our IRC channel #hearthsim on Freenode.

License

This project is licensed under the MIT license. The full license text is available in the LICENSE file.

The assets directory includes files that are copyright © Blizzard Entertainment.

sunwell's People

Contributors

andburn avatar azeier avatar beheh avatar jleclanche avatar joolean avatar lett1 avatar martinbonnin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sunwell's Issues

Korean font we are using looks bad

This is a story for changing the font and size we are using for our Korean translations on the cards and the Twitch Extension. We have a customer support ticket opened here of a new user giving feedback on how hard it is to read the font:

https://app.intercom.io/a/apps/lhrr2hfa/inbox/inbox/all/conversations/17911380051

Also here is a screenshot of what a card looks like on the site in Korean right now:

https://s3.amazonaws.com/art.hearthstonejson.com/v1/render/latest/koKR/512x/AT_001.png

Non-latin fonts are incorrect

Hello! Thank you for a wonderful script!
Very cool thing, though - thank you!

  1. This version of the script is not working (24 Dec 2016)
  2. Russian fonts look horrible on http://hearthstonelabs.com/sunwell. (Maybe use BenguiatBoldITC and FranklinGothicURWConMed?)
  3. How can I render a large number of cards on one page? (Do not write the text by hand?)

Highlighting

Do you think there is way to get realtime highlighting when rendering the cards?

I have something like that in mind (ie for query 'ta')

image

Clipping ellipse on spell cards

Failed Clipping

The area used to clip normal minion card images will sometimes persist into spell cards, causing the grey area above. Happens in both chrome and safari on osx.

Fix overflowing lines with manual linbreaks

Card descriptions with manual linebreak (starting with [x]) tend to overflow the body.

We should be rendering them and then check whether they exceed the body. If they do, either resize the sprite or just rerender with a slightly smaller font size until they are contained.

Directly set mana/atk/health color

We'd like to directly be able to set the mana/attack/health colors (negative/positive/neutral = red/green/white) without having to rely on the internal (stateful) mechanism. The main motivation is using this in Joust, where the colors can be deduced by the default card values and other tags, such as health/max_health.

As an example, it's currently not easy to set the health on a minion effected by equality - it's health might be lower than it's default health, but it should be white since the current health is equal to the max health. Compare this to a minion though that has been noramlly attacked, and has it's current health set to one - it should be red.

Implement HIDE_STATS

The medivh brawl implemented HIDE_STATS which does the following:

  • Hides health and attack from the minion token on the board
  • Hides health and attack from the card render
  • Does not render text for the mana gem.

Sunwell should have a way to do the latter two.

Add a prettier default texture

With support for arbitrary cards nearly complete, we're still missing a better looking default texture.

image

I figure we might as well add this in Sunwell itself, but we'd need the texture to be the same license as Sunwell (or even more permissive).
Anyone wants to take a crack at it? @andburn feeling inspired? :)

Weapon rarity gem is incorrect

image

There's some visible cut happening there. The asset itself looks kinda weird, should probably just get the one from ingame.

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.