-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added null checl. * Updated version numbers. * Force text to have LF for EOL. * Tweak version number for release.
- Loading branch information
1 parent
49a0f03
commit ff223b8
Showing
4 changed files
with
113 additions
and
144 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,7 @@ | ||
# Handle line endings automatically for files detected as text | ||
# and leave all files detected as binary untouched. | ||
* text=auto | ||
* text=auto | ||
* text eol=lf | ||
|
||
gradlew text eol=lf | ||
|
||
# | ||
# The above will handle all files NOT found below | ||
# | ||
# These files are text and should be normalized (Convert crlf => lf) | ||
*.bash text eol=lf | ||
*.css text diff=css | ||
*.df text | ||
*.htm text diff=html | ||
*.html text diff=html | ||
*.java text diff=java | ||
*.js text | ||
*.json text | ||
*.jsp text | ||
*.jspf text | ||
*.jspx text | ||
*.properties text | ||
*.sh text eol=lf | ||
*.tld text | ||
*.txt text | ||
*.tag text | ||
*.tagx text | ||
*.xml text | ||
*.yml text | ||
|
||
# These files are binary and should be left untouched | ||
# (binary is a macro for -text -diff) | ||
*.class binary | ||
*.dll binary | ||
*.ear binary | ||
*.gif binary | ||
*.ico binary | ||
*.jar binary | ||
*.jpg binary | ||
*.jpeg binary | ||
*.png binary | ||
*.so binary | ||
*.war binary | ||
*.jar binary | ||
*.png binary | ||
*.gif binary | ||
*.ico binary |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
191 changes: 98 additions & 93 deletions
191
mutters-ink-bot/src/main/java/com/rabidgremlin/mutters/bot/ink/SessionUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,93 +1,98 @@ | ||
package com.rabidgremlin.mutters.bot.ink; | ||
|
||
import com.bladecoder.ink.runtime.StoryState; | ||
import com.rabidgremlin.mutters.core.session.Session; | ||
|
||
/** | ||
* Utility class for InkBot's interactions with a Session. | ||
* | ||
* @author rabidgremlin | ||
* | ||
*/ | ||
public class SessionUtils | ||
extends com.rabidgremlin.mutters.core.util.SessionUtils | ||
{ | ||
|
||
protected SessionUtils() | ||
{ | ||
// utility class | ||
} | ||
|
||
/** | ||
* Stores the failed to understand count for the bot. | ||
* | ||
* @param session The session. | ||
* @param count The count. | ||
*/ | ||
public static void setFailedToUnderstandCount(Session session, int count) | ||
{ | ||
session.setAttribute(SLOT_PREFIX + "0987654321FAILEDCOUNT1234567890", new Integer(count)); | ||
} | ||
|
||
/** | ||
* Gets the failed to understand count for the bot. | ||
* | ||
* @param session The session. | ||
* @return The count. | ||
*/ | ||
public static int getFailedToUnderstandCount(Session session) | ||
{ | ||
Integer failedToUnderstandCount = (Integer) session.getAttribute(SLOT_PREFIX + "0987654321FAILEDCOUNT1234567890"); | ||
|
||
if (failedToUnderstandCount == null) | ||
{ | ||
return 0; | ||
} | ||
else | ||
{ | ||
return failedToUnderstandCount; | ||
} | ||
} | ||
|
||
/** | ||
* Stores the current Ink story state for the user into the session. | ||
* | ||
* @param session The session. | ||
* @param storyState The story state. | ||
*/ | ||
public static void saveInkStoryState(Session session, StoryState storyState) | ||
{ | ||
try | ||
{ | ||
session.setAttribute(SLOT_PREFIX + "0987654321STORYSTATE1234567890", storyState.toJson()); | ||
} | ||
catch (Exception e) | ||
{ | ||
throw new RuntimeException("Unexpected error. Failed to save story state", e); | ||
} | ||
} | ||
|
||
/** | ||
* Gets the user's current Ink story state from the session. | ||
* | ||
* @param session The session. | ||
* @param storyState The story state. | ||
*/ | ||
public static void loadInkStoryState(Session session, StoryState storyState) | ||
{ | ||
try | ||
{ | ||
String stateJson = (String) session | ||
.getAttribute(SLOT_PREFIX + "0987654321STORYSTATE1234567890"); | ||
if (stateJson != null) | ||
{ | ||
storyState.loadJson(stateJson); | ||
} | ||
} | ||
catch (Exception e) | ||
{ | ||
throw new BadInkStoryState("Unexpected error. Failed to load story state", e); | ||
} | ||
} | ||
|
||
} | ||
package com.rabidgremlin.mutters.bot.ink; | ||
|
||
import com.bladecoder.ink.runtime.StoryState; | ||
import com.rabidgremlin.mutters.core.session.Session; | ||
|
||
/** | ||
* Utility class for InkBot's interactions with a Session. | ||
* | ||
* @author rabidgremlin | ||
* | ||
*/ | ||
public class SessionUtils | ||
extends com.rabidgremlin.mutters.core.util.SessionUtils | ||
{ | ||
|
||
protected SessionUtils() | ||
{ | ||
// utility class | ||
} | ||
|
||
/** | ||
* Stores the failed to understand count for the bot. | ||
* | ||
* @param session The session. | ||
* @param count The count. | ||
*/ | ||
public static void setFailedToUnderstandCount(Session session, int count) | ||
{ | ||
session.setAttribute(SLOT_PREFIX + "0987654321FAILEDCOUNT1234567890", new Integer(count)); | ||
} | ||
|
||
/** | ||
* Gets the failed to understand count for the bot. | ||
* | ||
* @param session The session. | ||
* @return The count. | ||
*/ | ||
public static int getFailedToUnderstandCount(Session session) | ||
{ | ||
Integer failedToUnderstandCount = (Integer) session.getAttribute(SLOT_PREFIX + "0987654321FAILEDCOUNT1234567890"); | ||
|
||
if (failedToUnderstandCount == null) | ||
{ | ||
return 0; | ||
} | ||
else | ||
{ | ||
return failedToUnderstandCount; | ||
} | ||
} | ||
|
||
/** | ||
* Stores the current Ink story state for the user into the session. | ||
* | ||
* @param session The session. | ||
* @param storyState The story state. | ||
*/ | ||
public static void saveInkStoryState(Session session, StoryState storyState) | ||
{ | ||
if (storyState == null) | ||
{ | ||
throw new BadInkStoryState("storyState should not be null"); | ||
} | ||
|
||
try | ||
{ | ||
session.setAttribute(SLOT_PREFIX + "0987654321STORYSTATE1234567890", storyState.toJson()); | ||
} | ||
catch (Exception e) | ||
{ | ||
throw new RuntimeException("Unexpected error. Failed to save story state", e); | ||
} | ||
} | ||
|
||
/** | ||
* Gets the user's current Ink story state from the session. | ||
* | ||
* @param session The session. | ||
* @param storyState The story state. | ||
*/ | ||
public static void loadInkStoryState(Session session, StoryState storyState) | ||
{ | ||
try | ||
{ | ||
String stateJson = (String) session | ||
.getAttribute(SLOT_PREFIX + "0987654321STORYSTATE1234567890"); | ||
if (stateJson != null) | ||
{ | ||
storyState.loadJson(stateJson); | ||
} | ||
} | ||
catch (Exception e) | ||
{ | ||
throw new BadInkStoryState("Unexpected error. Failed to load story state", e); | ||
} | ||
} | ||
|
||
} |