Skip to content

Commit

Permalink
Merge pull request #44 from Cadesh/issue-34
Browse files Browse the repository at this point in the history
Issue 34: Create multiple characters in a row - I have code dependent on this push 😇
  • Loading branch information
KingFruit85 committed Oct 14, 2019
2 parents 79c25db + 5232ca4 commit 0e6775f
Showing 1 changed file with 32 additions and 4 deletions.
36 changes: 32 additions & 4 deletions core.js
Original file line number Diff line number Diff line change
Expand Up @@ -763,6 +763,31 @@ function NewCharacter(){

}

charQty = 1;
for (let j = 0; j < process.argv.length; j++) { //loops all arguments
if (process.argv[j] == '-n') { //check for the argument -n, if 'true' user wants several chars
var isnum = /^\d+$/.test(process.argv[j+1]); //checks if the next argument is a number
if (isnum == true) {
charQty = process.argv[j+1];
}
}
//console.log(j + ' -> ' + (process.argv[j])); //used to print all arguments on screen for testing
}

for (var k = 0; k < charQty; k++) { //loop to create several characters in a row

var x = new NewCharacter();

console.log(x.variant + " " + x.firstName + " " + x.lastName);

// console.log(JSON.stringify(x.variant, undefined, 2));

JsonExport = JSON.stringify(x, undefined, 2);

fs.writeFile("./" + x.firstName + " " + x.lastName + "- " + x.race + " " + x.characterClass.name + ".JSON", JsonExport, function(err) {
if(err) {
return console.log(err);
}
//assigns a new character object to x
x = new NewCharacter();

Expand All @@ -772,9 +797,12 @@ console.log(x.firstName + " " + x.lastName + " -character created. File saved in
//Exports character object to JSON file in root dir
JsonExport = JSON.stringify(x, undefined, 2);

fs.writeFile("./" + x.firstName + " " + x.lastName + "- " + x.race + " " + x.characterClass.name + ".JSON", JsonExport, function(err) {
if(err) {
return console.log(err);
}
console.log("The file was saved!");


});

}

});

0 comments on commit 0e6775f

Please sign in to comment.