Skip to content

Commit

Permalink
add random method
Browse files Browse the repository at this point in the history
  • Loading branch information
memelotsqui committed Dec 3, 2023
1 parent b155417 commit 6d74e07
Showing 1 changed file with 30 additions and 3 deletions.
33 changes: 30 additions & 3 deletions src/library/characterManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,22 @@ export class CharacterManager {
if (manifestURL)
this.manifest = await this.loadManifest(manifestURL, options)

this.manifestData= null;
this.manifestData = null;
this.avatar = {}; // Holds information of traits within the avatar
this.traitLoadManager = new TraitLoadingManager();
}



setParentModel(model){
this.parentModel = model;
}

async loadManifestRandomTraits(){
console.log("get random");
console.log(this.manifestData.getRandomTraits());
}

async loadTraits(options){
this.traitLoadManager.loadTraitOptions(getAsArray(options)).then(loadedData=>{
loadedData.forEach(itemData => {
Expand Down Expand Up @@ -731,8 +736,26 @@ class ManifestData{
console.log(this.textureTraitsMap);
}

getRandomTraits(optionalGroupTraitIDs){
const traits = []
const searchArray = optionalGroupTraitIDs || this.randomTraits;
searchArray.forEach(groupTraitID => {
const trait = this.getRandomTrait(groupTraitID);
if (trait)
traits.push(trait);
});
return traits;
}

getRandomTrait(groupTraitID){

const traitModelsGroup = this.getTraitGroup(groupTraitID);
if (traitModelsGroup){
return traitModelsGroup.getRandomTrait();
}
else{
console.warn("No trait group with name " + groupTraitID + " was found.")
return null;
}
}

// model traits
Expand Down Expand Up @@ -822,6 +845,10 @@ class TraitModelsGroup{
return this.collectionMap.get(traitID);
}

getRandomTrait(){
return this.collection[Math.floor(Math.random() * this.collection.length)];
}

createCollection(itemCollection, replaceExisting = false){
if (replaceExisting) this.collection = [];

Expand Down

0 comments on commit 6d74e07

Please sign in to comment.