当前位置: 首页>>代码示例>>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;未经允许,请勿转载。