當前位置: 首頁>>代碼示例>>Java>>正文


Java Story類代碼示例

本文整理匯總了Java中com.bladecoder.ink.runtime.Story的典型用法代碼示例。如果您正苦於以下問題:Java Story類的具體用法?Java Story怎麽用?Java Story使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Story類屬於com.bladecoder.ink.runtime包,在下文中一共展示了Story類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getLocalDate

import com.bladecoder.ink.runtime.Story; //導入依賴的package包/類
/**
 * Returns the specified variable as a LocalDate. Note LocalDates should be stored as an ink string in the format
 * yyyy-MM-dd.
 * 
 * @param story The story to get the variable from.
 * @param varName The name of the variable (case-sensitive).
 * @return The LocalDate or null if the variable does not exist or is not a LocalDate.
 */
public static LocalDate getLocalDate(Story story, String varName)
{
  String dateStr = (String) story.getVariablesState().get(varName);
  if (StringUtils.isEmpty(dateStr))
  {
    return null;
  }

  try
  {
    return LocalDate.parse(dateStr);
  }
  catch (IllegalArgumentException e)
  {
    return null;
  }
}
 
開發者ID:rabidgremlin,項目名稱:Mutters,代碼行數:26,代碼來源:StoryUtils.java

示例2: getBoolean

import com.bladecoder.ink.runtime.Story; //導入依賴的package包/類
/**
 * This method returns the boolean value of the specified story variable. Note Ink stores booleans values as integers,
 * 1 is true. This method returns false if variable does not exist.
 * 
 * @param story The story to extract the variable from.
 * @param varName The name of variable. Case sensitive.
 * @return The value of variable, or false if the variable does not exist.
 */
public static boolean getBoolean(Story story, String varName)
{
  Integer boolVal = (Integer) story.getVariablesState().get(varName);
  if (boolVal == null)
  {
    return false;
  }

  try
  {
    if (boolVal.equals(1))
    {
      return true;
    }
    return false;
  }
  catch (IllegalArgumentException e)
  {
    return false;
  }
}
 
開發者ID:rabidgremlin,項目名稱:Mutters,代碼行數:30,代碼來源:StoryUtils.java

示例3: execute

import com.bladecoder.ink.runtime.Story; //導入依賴的package包/類
@Override
public void execute(CurrentResponse currentResponse, Session session, IntentMatch intentMatch, Story story, String param)
{
  FunctionDetails details = FunctionHelper.parseFunctionString(param);

  if (details.getFunctionParams() == null)
  {
    throw new IllegalArgumentException("Missing name and value values for SET_LONG_TERM_ATTR");
  }

  String name = details.getFunctionParams().get("name");
  if (name == null)
  {
    throw new IllegalArgumentException("Missing name value for SET_LONG_TERM_ATTR");
  }

  String value = details.getFunctionParams().get("value");
  if (value == null)
  {
    throw new IllegalArgumentException("Missing value value for SET_LONG_TERM_ATTR");
  }

  session.setLongTermAttribute(name, value);
}
 
開發者ID:rabidgremlin,項目名稱:Mutters,代碼行數:25,代碼來源:SetLongTermAttributeFunction.java

示例4: execute

import com.bladecoder.ink.runtime.Story; //導入依賴的package包/類
@Override
public void execute(CurrentResponse currentResponse, Session session, IntentMatch intentMatch,
  Story story, String param)
{
  FunctionDetails details = FunctionHelper.parseFunctionString(param);

  if (details.getFunctionParams() == null || details.getFunctionParams().get("type") == null)
  {
    throw new IllegalArgumentException("Missing type value for ADD_ATTACHMENT function.");
  }

  BotResponseAttachment attachment = new BotResponseAttachment(details.getFunctionParams().get("type"));

  for (String key : details.getFunctionParams().keySet())
  {
    if (!key.equals("type"))
    {
      attachment.addParameters(key, details.getFunctionParams().get(key));
    }
  }

  currentResponse.addResponseAttachement(attachment);
}
 
開發者ID:rabidgremlin,項目名稱:Mutters,代碼行數:24,代碼來源:AddAttachmentFunction.java

示例5: nestedFlow

import com.bladecoder.ink.runtime.Story; //導入依賴的package包/類
/**
 *     "- allow nested options to pop out to a higher level gather"
 */
@Test
public void nestedFlow() throws Exception {
	List<String> text = new ArrayList<String>();
	
	String json = TestUtils.getJsonString("inkfiles/gather/nested-flow.ink.json");
	Story story = new Story(json);
	
	TestUtils.nextAll(story, text);
	story.chooseChoiceIndex(0);
	
	text.clear();
	TestUtils.nextAll(story, text);
	story.chooseChoiceIndex(2);
	
	text.clear();
	TestUtils.nextAll(story, text);
	Assert.assertEquals(2, text.size());
	Assert.assertEquals("\"Myself!\"", text.get(0));
	Assert.assertEquals("Mrs. Christie lowered her manuscript a moment. The rest of the writing group sat, open-mouthed.", text.get(1));
}
 
開發者ID:bladecoder,項目名稱:blade-ink,代碼行數:24,代碼來源:GatherSpecTest.java

示例6: autoStitch2

import com.bladecoder.ink.runtime.Story; //導入依賴的package包/類
/**
 *     "- be automatically diverted to if there is no other content in a knot" 
 */
@Test
public void autoStitch2() throws Exception {
	List<String> text = new ArrayList<String>();
	
	String json = TestUtils.getJsonString("inkfiles/stitch/auto-stitch.ink.json");
	Story story = new Story(json);
	
	TestUtils.nextAll(story, text);
	story.chooseChoiceIndex(1);
	
	text.clear();
	TestUtils.nextAll(story, text);
	Assert.assertEquals(1, text.size());
	Assert.assertEquals("I settled my master.", text.get(0));
}
 
開發者ID:bladecoder,項目名稱:blade-ink,代碼行數:19,代碼來源:StitchSpecTest.java

示例7: manualStitch

import com.bladecoder.ink.runtime.Story; //導入依賴的package包/類
/**
 *     "- not be diverted to if the knot has content" 
 */
@Test
public void manualStitch() throws Exception {
	List<String> text = new ArrayList<String>();
	
	String json = TestUtils.getJsonString("inkfiles/stitch/manual-stitch.ink.json");
	Story story = new Story(json);
	
	TestUtils.nextAll(story, text);
	Assert.assertEquals(1, text.size());
	Assert.assertEquals("How shall we travel?", text.get(0));
	story.chooseChoiceIndex(1);
	
	text.clear();
	TestUtils.nextAll(story, text);
	Assert.assertEquals(1, text.size());
	Assert.assertEquals("I put myself in third.", text.get(0));
}
 
開發者ID:bladecoder,項目名稱:blade-ink,代碼行數:21,代碼來源:StitchSpecTest.java

示例8: manualStitch2

import com.bladecoder.ink.runtime.Story; //導入依賴的package包/類
/**
 *     "- be usable locally without the full name"
 */
@Test
public void manualStitch2() throws Exception {
	List<String> text = new ArrayList<String>();
	
	String json = TestUtils.getJsonString("inkfiles/stitch/manual-stitch.ink.json");
	Story story = new Story(json);
	
	TestUtils.nextAll(story, text);
	Assert.assertEquals(1, text.size());
	Assert.assertEquals("How shall we travel?", text.get(0));
	story.chooseChoiceIndex(0);
	
	text.clear();
	TestUtils.nextAll(story, text);
	Assert.assertEquals(1, text.size());
	Assert.assertEquals("I settled my master.", text.get(0));
}
 
開發者ID:bladecoder,項目名稱:blade-ink,代碼行數:21,代碼來源:StitchSpecTest.java

示例9: singleChoice2

import com.bladecoder.ink.runtime.Story; //導入依賴的package包/類
/**
 * "- continue processing with the choice text when a choice is selected"
 */
@Test
public void singleChoice2() throws Exception {
	List<String> text = new ArrayList<String>();

	String json = TestUtils.getJsonString("inkfiles/choices/single-choice.ink.json");
	Story story = new Story(json);

	TestUtils.nextAll(story, text);
	story.chooseChoiceIndex(0);

	text.clear();
	TestUtils.nextAll(story, text);

	Assert.assertEquals(2, text.size());
	Assert.assertEquals("Hello back!", text.get(0));
	Assert.assertEquals("Nice to hear from you", text.get(1));
}
 
開發者ID:bladecoder,項目名稱:blade-ink,代碼行數:21,代碼來源:ChoiceSpecTest.java

示例10: mixedChoice

import com.bladecoder.ink.runtime.Story; //導入依賴的package包/類
/**
 * "- be suppressed in the text flow using the [] syntax"
 */
@Test
public void mixedChoice() throws Exception {
	List<String> text = new ArrayList<String>();

	String json = TestUtils.getJsonString("inkfiles/choices/mixed-choice.ink.json");
	Story story = new Story(json);

	TestUtils.nextAll(story, text);
	Assert.assertEquals("Hello back!", story.getCurrentChoices().get(0).getText());
	story.chooseChoiceIndex(0);

	text.clear();
	TestUtils.nextAll(story, text);
	Assert.assertEquals(2, text.size());

	Assert.assertEquals("Hello  right back to you!", text.get(0));
	Assert.assertEquals("Nice to hear from you.", text.get(1));
}
 
開發者ID:bladecoder,項目名稱:blade-ink,代碼行數:22,代碼來源:ChoiceSpecTest.java

示例11: varyingChoice

import com.bladecoder.ink.runtime.Story; //導入依賴的package包/類
/**
 * "- disappear when used if they are a once-only choice"
 */
@Test
public void varyingChoice() throws Exception {
	List<String> text = new ArrayList<String>();

	String json = TestUtils.getJsonString("inkfiles/choices/varying-choice.ink.json");
	Story story = new Story(json);

	TestUtils.nextAll(story, text);
	Assert.assertEquals(2, story.getCurrentChoices().size());
	story.chooseChoiceIndex(0);

	text.clear();
	TestUtils.nextAll(story, text);
	Assert.assertEquals(1, story.getCurrentChoices().size());

	Assert.assertEquals("The man with the briefcase?", story.getCurrentChoices().get(0).getText());
}
 
開發者ID:bladecoder,項目名稱:blade-ink,代碼行數:21,代碼來源:ChoiceSpecTest.java

示例12: stickyChoice

import com.bladecoder.ink.runtime.Story; //導入依賴的package包/類
/**
 * "- not disappear when used if they are a sticky choices"
 */
@Test
public void stickyChoice() throws Exception {
	List<String> text = new ArrayList<String>();

	String json = TestUtils.getJsonString("inkfiles/choices/sticky-choice.ink.json");
	Story story = new Story(json);

	TestUtils.nextAll(story, text);
	Assert.assertEquals(2, story.getCurrentChoices().size());
	story.chooseChoiceIndex(0);

	text.clear();
	TestUtils.nextAll(story, text);
	Assert.assertEquals(2, story.getCurrentChoices().size());
}
 
開發者ID:bladecoder,項目名稱:blade-ink,代碼行數:19,代碼來源:ChoiceSpecTest.java

示例13: fallbackChoice2

import com.bladecoder.ink.runtime.Story; //導入依賴的package包/類
/**
 * "- not be shown if it is a fallback choice and there are non-fallback
 * choices available"
 */
@Test
public void fallbackChoice2() throws Exception {
	List<String> text = new ArrayList<String>();

	String json = TestUtils.getJsonString("inkfiles/choices/fallback-choice.ink.json");
	Story story = new Story(json);

	TestUtils.nextAll(story, text);
	Assert.assertEquals(2, story.getCurrentChoices().size());
	story.chooseChoiceIndex(0);

	text.clear();
	TestUtils.nextAll(story, text);
	story.chooseChoiceIndex(0);

	text.clear();
	TestUtils.nextAll(story, text);

	Assert.assertEquals(true, TestUtils.isEnded(story));
}
 
開發者ID:bladecoder,項目名稱:blade-ink,代碼行數:25,代碼來源:ChoiceSpecTest.java

示例14: labelFlow2

import com.bladecoder.ink.runtime.Story; //導入依賴的package包/類
/**
 * "- handle labels on choices and evaluate in expressions (example 2)"
 */
@Test
public void labelFlow2() throws Exception {
	List<String> text = new ArrayList<String>();

	String json = TestUtils.getJsonString("inkfiles/choices/label-flow.ink.json");
	Story story = new Story(json);

	TestUtils.nextAll(story, text);
	story.chooseChoiceIndex(1);

	text.clear();
	TestUtils.nextAll(story, text);
	Assert.assertEquals(2, story.getCurrentChoices().size());
	Assert.assertEquals("Shove him aside", story.getCurrentChoices().get(1).getText());
}
 
開發者ID:bladecoder,項目名稱:blade-ink,代碼行數:19,代碼來源:ChoiceSpecTest.java

示例15: labelScope

import com.bladecoder.ink.runtime.Story; //導入依賴的package包/類
/**
 * "- allow label references out of scope using the full path id"
 */
@Test
public void labelScope() throws Exception {
	List<String> text = new ArrayList<String>();

	String json = TestUtils.getJsonString("inkfiles/choices/label-scope.ink.json");
	Story story = new Story(json);

	TestUtils.nextAll(story, text);
	story.chooseChoiceIndex(0);

	text.clear();
	TestUtils.nextAll(story, text);
	Assert.assertEquals(1, story.getCurrentChoices().size());
	Assert.assertEquals("Found gatherpoint", story.getCurrentChoices().get(0).getText());
}
 
開發者ID:bladecoder,項目名稱:blade-ink,代碼行數:19,代碼來源:ChoiceSpecTest.java


注:本文中的com.bladecoder.ink.runtime.Story類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。