zengm-games / zengm

Basketball GM (and other ZenGM games) are single-player sports management simulation games, made entirely in client-side JavaScript.
https://zengm.com
Other
361 stars 131 forks source link

Allow for Player Faces to be a part of Global Settings, similar to Player Photos #440

Open tomkennedy22 opened 1 year ago

tomkennedy22 commented 1 year ago

It'd be cool if we could import a player photo JSON into the Global Settings screen to have a fixed cartoon player face, similar to player photos. Either by a user who creates a cartoon face themselves, or dedicated user who make entire libraries of them. Similar to screenshot below, bottom right text input box.

image

I might be able to take this issue on, but wanted any thoughts on the subject, if you think it's a good idea at all

dumbmatter commented 1 year ago

It's a good idea.

Player photos is currently (in TypeScript terms) Record<string, string> but instead it could be Record<string, string | Face>, to support either URLs or face objects, or even both mixed together. typeof x === "string" can distinguish if it's a URL (string) or a face (object).

I think basically the only part of code that'd need to change is https://github.com/zengm-games/zengm/blob/aa859e9dd797e7f7bc9056568e50e685c54f5126/src/worker/core/league/processPlayerNewLeague.ts#L29-L41 - check if the player's photo entry is a string or an object, and then update both p.imgURL and p.face.

Please feel free to give it a shot!

tomkennedy22 commented 1 year ago

Cool, I'll take a look. Do you have an opinion on the scenario: if a player has both photo URL & and face JSON present in player profile, which to use? In the game currently, users can decide in player profiles, just wanted to see if you would prefer a default.

dumbmatter commented 1 year ago

Currently I believe it uses the URL if present, and the face otherwise. No need to change that here unless that behavior is a problem. Cause if real player photos is Record<string, string | Face> then it's only one of the two that will be added - but if it's a Face you would need to delete any existing imgURL so it doesn't get overridden.