RanvierMUD / core

Core engine code for Ranvier
https://ranviermud.com
MIT License
45 stars 40 forks source link

allow metadata to be set safely in yaml #86

Closed ratacat closed 5 years ago

ratacat commented 5 years ago

…luded in yaml

referenced here: https://github.com/RanvierMUD/ranviermud/issues/390 Currently if you define any metadata in an npcs.yml file, then all copies of that npc share a single metadata object. Not ideal! Being able to set metadata in yaml is quite useful though, and it would be a shame to not be able to do that.

shawncplus commented 5 years ago

Object.assign() does a shallow copy so it's not the correct approach to have the metadata object not be shared. A better approach would be in the Character constructor instead of

this.metadata = data.metadata || {};

do

if (data.metadata) {
  this.metadata = JSON.parse(JSON.stringify(data.metadata));
} else {
 this.metadata = {};
}
ratacat commented 5 years ago

Creating a new pull request (#90) so we can close off this one. The commits were getting messy.