Removing requirement that priority be an integer
This commit is contained in:
+3
-3
@@ -49,7 +49,7 @@ StoryManager.storylets["Conversation"] = {
|
|||||||
passage: "Conversation",
|
passage: "Conversation",
|
||||||
description: "Talk to " + character.name,
|
description: "Talk to " + character.name,
|
||||||
character: character,
|
character: character,
|
||||||
priority: 0
|
priority: 1
|
||||||
}
|
}
|
||||||
yield storylet;
|
yield storylet;
|
||||||
}
|
}
|
||||||
@@ -119,7 +119,7 @@ StoryManager.storylets["Conversation"] = {
|
|||||||
let storylet = {
|
let storylet = {
|
||||||
passage: "Conversation",
|
passage: "Conversation",
|
||||||
description: "Talk to " + character.name,
|
description: "Talk to " + character.name,
|
||||||
priority: 0,
|
priority: 1,
|
||||||
character: character
|
character: character
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -254,7 +254,7 @@ StoryManager.storylets["Conversation topic"] = {
|
|||||||
yield {
|
yield {
|
||||||
passage: "Conversation topic",
|
passage: "Conversation topic",
|
||||||
description: "Talk about " + topic,
|
description: "Talk about " + topic,
|
||||||
priority: 0,
|
priority: 1,
|
||||||
topic: topic
|
topic: topic
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
+10
-13
@@ -113,11 +113,9 @@ StoryManager.getAllStorylets = function(tag=null) {
|
|||||||
for (let key in this.storylets) {
|
for (let key in this.storylets) {
|
||||||
storylet = this.storylets[key];
|
storylet = this.storylets[key];
|
||||||
if (tag === null || ("tags" in storylet && storylet.tags.includes(tag))) {
|
if (tag === null || ("tags" in storylet && storylet.tags.includes(tag))) {
|
||||||
// TODO: If using yield, this part will change
|
|
||||||
//storylets = storylet.generate();
|
|
||||||
for (let boundStorylet of storylet.generate()) {
|
for (let boundStorylet of storylet.generate()) {
|
||||||
//boundStorylet = storylets[i];
|
//boundStorylet = storylets[i];
|
||||||
if (!("priority" in boundStorylet)) boundStorylet.priority = 0;
|
if (!("priority" in boundStorylet)) boundStorylet.priority = 1;
|
||||||
allStorylets.push(boundStorylet);
|
allStorylets.push(boundStorylet);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -133,9 +131,6 @@ StoryManager.getStorylets = function(n=null, tag=null, respect_interrupt=true) {
|
|||||||
tag: Only get storylets matching this tag
|
tag: Only get storylets matching this tag
|
||||||
respect_interrupt: if true, any interrupt storylet overrides n and priority
|
respect_interrupt: if true, any interrupt storylet overrides n and priority
|
||||||
|
|
||||||
For now assume that priorities are integers, but it would be nice
|
|
||||||
to be more flexible.
|
|
||||||
|
|
||||||
*/
|
*/
|
||||||
let allStorylets;
|
let allStorylets;
|
||||||
allStorylets = this.getAllStorylets(tag);
|
allStorylets = this.getAllStorylets(tag);
|
||||||
@@ -155,16 +150,18 @@ StoryManager.getStorylets = function(n=null, tag=null, respect_interrupt=true) {
|
|||||||
}
|
}
|
||||||
else n = allStorylets.length;
|
else n = allStorylets.length;
|
||||||
let selectedStorylets = [];
|
let selectedStorylets = [];
|
||||||
// First sort by ascending priority:
|
|
||||||
allStorylets.sort((a, b) => b.priority - a.priority);
|
|
||||||
|
|
||||||
let currentPriority = allStorylets[0].priority;
|
// Select by strict priority; randomize among matching priority.
|
||||||
|
let priorities = Array.from(new Set(allStorylets.map(x => x.priority)));
|
||||||
|
priorities.sort((a, b) => b - a);
|
||||||
|
|
||||||
|
let currentPriority = 0;
|
||||||
while (selectedStorylets.length < n) {
|
while (selectedStorylets.length < n) {
|
||||||
let priorityStorylets = allStorylets.filter(s => s.priority==currentPriority);
|
let priorityStorylets = allStorylets.filter(s => s.priority==priorities[currentPriority]);
|
||||||
priorityStorylets.sort((a, b) => (Math.random() - Math.random()));
|
priorityStorylets.sort((a, b) => (Math.random() - Math.random()));
|
||||||
let nAdd = Math.min(n - selectedStorylets.length, priorityStorylets.length);
|
let nAdd = Math.min(n - selectedStorylets.length, priorityStorylets.length);
|
||||||
for (let i=0; i<nAdd; i++) selectedStorylets.push(priorityStorylets.pop());
|
for (let i=0; i<nAdd; i++) selectedStorylets.push(priorityStorylets.pop());
|
||||||
currentPriority--;
|
currentPriority++;
|
||||||
}
|
}
|
||||||
return selectedStorylets;
|
return selectedStorylets;
|
||||||
}
|
}
|
||||||
@@ -228,7 +225,7 @@ StoryManager.storylets["Conversation"] = {
|
|||||||
let storylet = {
|
let storylet = {
|
||||||
passage: "Conversation",
|
passage: "Conversation",
|
||||||
description: "Talk to " + character.name,
|
description: "Talk to " + character.name,
|
||||||
priority: 0,
|
priority: 1,
|
||||||
character: character
|
character: character
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -264,7 +261,7 @@ StoryManager.storylets["Conversation topic"] = {
|
|||||||
storylets.push({
|
storylets.push({
|
||||||
passage: "Conversation topic",
|
passage: "Conversation topic",
|
||||||
description: "Talk about " + topic,
|
description: "Talk about " + topic,
|
||||||
priority: 0,
|
priority: 1,
|
||||||
topic: topic
|
topic: topic
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ StoryManager.storylets["Conversation"] = {
|
|||||||
let storylet = {
|
let storylet = {
|
||||||
passage: "Conversation",
|
passage: "Conversation",
|
||||||
description: "Talk to " + character.name,
|
description: "Talk to " + character.name,
|
||||||
priority: 0,
|
priority: 1,
|
||||||
character: character
|
character: character
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -91,7 +91,7 @@ StoryManager.storylets["Conversation topic"] = {
|
|||||||
storylets.push({
|
storylets.push({
|
||||||
passage: "Conversation topic",
|
passage: "Conversation topic",
|
||||||
description: "Talk about " + topic,
|
description: "Talk about " + topic,
|
||||||
priority: 0,
|
priority: 1,
|
||||||
topic: topic
|
topic: topic
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -113,11 +113,9 @@ StoryManager.getAllStorylets = function(tag=null) {
|
|||||||
for (let key in this.storylets) {
|
for (let key in this.storylets) {
|
||||||
storylet = this.storylets[key];
|
storylet = this.storylets[key];
|
||||||
if (tag === null || ("tags" in storylet && storylet.tags.includes(tag))) {
|
if (tag === null || ("tags" in storylet && storylet.tags.includes(tag))) {
|
||||||
// TODO: If using yield, this part will change
|
|
||||||
//storylets = storylet.generate();
|
|
||||||
for (let boundStorylet of storylet.generate()) {
|
for (let boundStorylet of storylet.generate()) {
|
||||||
//boundStorylet = storylets[i];
|
//boundStorylet = storylets[i];
|
||||||
if (!("priority" in boundStorylet)) boundStorylet.priority = 0;
|
if (!("priority" in boundStorylet)) boundStorylet.priority = 1;
|
||||||
allStorylets.push(boundStorylet);
|
allStorylets.push(boundStorylet);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -133,9 +131,6 @@ StoryManager.getStorylets = function(n=null, tag=null, respect_interrupt=true) {
|
|||||||
tag: Only get storylets matching this tag
|
tag: Only get storylets matching this tag
|
||||||
respect_interrupt: if true, any interrupt storylet overrides n and priority
|
respect_interrupt: if true, any interrupt storylet overrides n and priority
|
||||||
|
|
||||||
For now assume that priorities are integers, but it would be nice
|
|
||||||
to be more flexible.
|
|
||||||
|
|
||||||
*/
|
*/
|
||||||
let allStorylets;
|
let allStorylets;
|
||||||
allStorylets = this.getAllStorylets(tag);
|
allStorylets = this.getAllStorylets(tag);
|
||||||
@@ -155,16 +150,18 @@ StoryManager.getStorylets = function(n=null, tag=null, respect_interrupt=true) {
|
|||||||
}
|
}
|
||||||
else n = allStorylets.length;
|
else n = allStorylets.length;
|
||||||
let selectedStorylets = [];
|
let selectedStorylets = [];
|
||||||
// First sort by ascending priority:
|
|
||||||
allStorylets.sort((a, b) => b.priority - a.priority);
|
|
||||||
|
|
||||||
let currentPriority = allStorylets[0].priority;
|
// Select by strict priority; randomize among matching priority.
|
||||||
|
let priorities = Array.from(new Set(allStorylets.map(x => x.priority)));
|
||||||
|
priorities.sort((a, b) => b - a);
|
||||||
|
|
||||||
|
let currentPriority = 0;
|
||||||
while (selectedStorylets.length < n) {
|
while (selectedStorylets.length < n) {
|
||||||
let priorityStorylets = allStorylets.filter(s => s.priority==currentPriority);
|
let priorityStorylets = allStorylets.filter(s => s.priority==priorities[currentPriority]);
|
||||||
priorityStorylets.sort((a, b) => (Math.random() - Math.random()));
|
priorityStorylets.sort((a, b) => (Math.random() - Math.random()));
|
||||||
let nAdd = Math.min(n - selectedStorylets.length, priorityStorylets.length);
|
let nAdd = Math.min(n - selectedStorylets.length, priorityStorylets.length);
|
||||||
for (let i=0; i<nAdd; i++) selectedStorylets.push(priorityStorylets.pop());
|
for (let i=0; i<nAdd; i++) selectedStorylets.push(priorityStorylets.pop());
|
||||||
currentPriority--;
|
currentPriority++;
|
||||||
}
|
}
|
||||||
return selectedStorylets;
|
return selectedStorylets;
|
||||||
}
|
}
|
||||||
|
|||||||
+10
-13
@@ -113,11 +113,9 @@ StoryManager.getAllStorylets = function(tag=null) {
|
|||||||
for (let key in this.storylets) {
|
for (let key in this.storylets) {
|
||||||
storylet = this.storylets[key];
|
storylet = this.storylets[key];
|
||||||
if (tag === null || ("tags" in storylet && storylet.tags.includes(tag))) {
|
if (tag === null || ("tags" in storylet && storylet.tags.includes(tag))) {
|
||||||
// TODO: If using yield, this part will change
|
|
||||||
//storylets = storylet.generate();
|
|
||||||
for (let boundStorylet of storylet.generate()) {
|
for (let boundStorylet of storylet.generate()) {
|
||||||
//boundStorylet = storylets[i];
|
//boundStorylet = storylets[i];
|
||||||
if (!("priority" in boundStorylet)) boundStorylet.priority = 0;
|
if (!("priority" in boundStorylet)) boundStorylet.priority = 1;
|
||||||
allStorylets.push(boundStorylet);
|
allStorylets.push(boundStorylet);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -133,9 +131,6 @@ StoryManager.getStorylets = function(n=null, tag=null, respect_interrupt=true) {
|
|||||||
tag: Only get storylets matching this tag
|
tag: Only get storylets matching this tag
|
||||||
respect_interrupt: if true, any interrupt storylet overrides n and priority
|
respect_interrupt: if true, any interrupt storylet overrides n and priority
|
||||||
|
|
||||||
For now assume that priorities are integers, but it would be nice
|
|
||||||
to be more flexible.
|
|
||||||
|
|
||||||
*/
|
*/
|
||||||
let allStorylets;
|
let allStorylets;
|
||||||
allStorylets = this.getAllStorylets(tag);
|
allStorylets = this.getAllStorylets(tag);
|
||||||
@@ -155,16 +150,18 @@ StoryManager.getStorylets = function(n=null, tag=null, respect_interrupt=true) {
|
|||||||
}
|
}
|
||||||
else n = allStorylets.length;
|
else n = allStorylets.length;
|
||||||
let selectedStorylets = [];
|
let selectedStorylets = [];
|
||||||
// First sort by ascending priority:
|
|
||||||
allStorylets.sort((a, b) => b.priority - a.priority);
|
|
||||||
|
|
||||||
let currentPriority = allStorylets[0].priority;
|
// Select by strict priority; randomize among matching priority.
|
||||||
|
let priorities = Array.from(new Set(allStorylets.map(x => x.priority)));
|
||||||
|
priorities.sort((a, b) => b - a);
|
||||||
|
|
||||||
|
let currentPriority = 0;
|
||||||
while (selectedStorylets.length < n) {
|
while (selectedStorylets.length < n) {
|
||||||
let priorityStorylets = allStorylets.filter(s => s.priority==currentPriority);
|
let priorityStorylets = allStorylets.filter(s => s.priority==priorities[currentPriority]);
|
||||||
priorityStorylets.sort((a, b) => (Math.random() - Math.random()));
|
priorityStorylets.sort((a, b) => (Math.random() - Math.random()));
|
||||||
let nAdd = Math.min(n - selectedStorylets.length, priorityStorylets.length);
|
let nAdd = Math.min(n - selectedStorylets.length, priorityStorylets.length);
|
||||||
for (let i=0; i<nAdd; i++) selectedStorylets.push(priorityStorylets.pop());
|
for (let i=0; i<nAdd; i++) selectedStorylets.push(priorityStorylets.pop());
|
||||||
currentPriority--;
|
currentPriority++;
|
||||||
}
|
}
|
||||||
return selectedStorylets;
|
return selectedStorylets;
|
||||||
}
|
}
|
||||||
@@ -200,7 +197,7 @@ StoryManager.storylets["Conversation"] = {
|
|||||||
let storylet = {
|
let storylet = {
|
||||||
passage: "Conversation",
|
passage: "Conversation",
|
||||||
description: "Talk to " + character.name,
|
description: "Talk to " + character.name,
|
||||||
priority: 0,
|
priority: 1,
|
||||||
character: character
|
character: character
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -236,7 +233,7 @@ StoryManager.storylets["Conversation topic"] = {
|
|||||||
yield {
|
yield {
|
||||||
passage: "Conversation topic",
|
passage: "Conversation topic",
|
||||||
description: "Talk about " + topic,
|
description: "Talk about " + topic,
|
||||||
priority: 0,
|
priority: 1,
|
||||||
topic: topic
|
topic: topic
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ StoryManager.storylets["Conversation"] = {
|
|||||||
let storylet = {
|
let storylet = {
|
||||||
passage: "Conversation",
|
passage: "Conversation",
|
||||||
description: "Talk to " + character.name,
|
description: "Talk to " + character.name,
|
||||||
priority: 0,
|
priority: 1,
|
||||||
character: character
|
character: character
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -72,7 +72,7 @@ StoryManager.storylets["Conversation topic"] = {
|
|||||||
yield {
|
yield {
|
||||||
passage: "Conversation topic",
|
passage: "Conversation topic",
|
||||||
description: "Talk about " + topic,
|
description: "Talk about " + topic,
|
||||||
priority: 0,
|
priority: 1,
|
||||||
topic: topic
|
topic: topic
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
+8
-9
@@ -12,7 +12,7 @@ StoryManager.getAllStorylets = function(tag=null) {
|
|||||||
if (tag === null || ("tags" in storylet && storylet.tags.includes(tag))) {
|
if (tag === null || ("tags" in storylet && storylet.tags.includes(tag))) {
|
||||||
for (let boundStorylet of storylet.generate()) {
|
for (let boundStorylet of storylet.generate()) {
|
||||||
//boundStorylet = storylets[i];
|
//boundStorylet = storylets[i];
|
||||||
if (!("priority" in boundStorylet)) boundStorylet.priority = 0;
|
if (!("priority" in boundStorylet)) boundStorylet.priority = 1;
|
||||||
allStorylets.push(boundStorylet);
|
allStorylets.push(boundStorylet);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -28,9 +28,6 @@ StoryManager.getStorylets = function(n=null, tag=null, respect_interrupt=true) {
|
|||||||
tag: Only get storylets matching this tag
|
tag: Only get storylets matching this tag
|
||||||
respect_interrupt: if true, any interrupt storylet overrides n and priority
|
respect_interrupt: if true, any interrupt storylet overrides n and priority
|
||||||
|
|
||||||
For now assume that priorities are integers, but it would be nice
|
|
||||||
to be more flexible.
|
|
||||||
|
|
||||||
*/
|
*/
|
||||||
let allStorylets;
|
let allStorylets;
|
||||||
allStorylets = this.getAllStorylets(tag);
|
allStorylets = this.getAllStorylets(tag);
|
||||||
@@ -50,16 +47,18 @@ StoryManager.getStorylets = function(n=null, tag=null, respect_interrupt=true) {
|
|||||||
}
|
}
|
||||||
else n = allStorylets.length;
|
else n = allStorylets.length;
|
||||||
let selectedStorylets = [];
|
let selectedStorylets = [];
|
||||||
// First sort by ascending priority:
|
|
||||||
allStorylets.sort((a, b) => b.priority - a.priority);
|
|
||||||
|
|
||||||
let currentPriority = allStorylets[0].priority;
|
// Select by strict priority; randomize among matching priority.
|
||||||
|
let priorities = Array.from(new Set(allStorylets.map(x => x.priority)));
|
||||||
|
priorities.sort((a, b) => b - a);
|
||||||
|
|
||||||
|
let currentPriority = 0;
|
||||||
while (selectedStorylets.length < n) {
|
while (selectedStorylets.length < n) {
|
||||||
let priorityStorylets = allStorylets.filter(s => s.priority==currentPriority);
|
let priorityStorylets = allStorylets.filter(s => s.priority==priorities[currentPriority]);
|
||||||
priorityStorylets.sort((a, b) => (Math.random() - Math.random()));
|
priorityStorylets.sort((a, b) => (Math.random() - Math.random()));
|
||||||
let nAdd = Math.min(n - selectedStorylets.length, priorityStorylets.length);
|
let nAdd = Math.min(n - selectedStorylets.length, priorityStorylets.length);
|
||||||
for (let i=0; i<nAdd; i++) selectedStorylets.push(priorityStorylets.pop());
|
for (let i=0; i<nAdd; i++) selectedStorylets.push(priorityStorylets.pop());
|
||||||
currentPriority--;
|
currentPriority++;
|
||||||
}
|
}
|
||||||
return selectedStorylets;
|
return selectedStorylets;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user