mirror of
https://gitlab.com/Oreolek/salet-module.git
synced 2024-06-26 03:50:49 +03:00
More tests; added link() and bilink() functions
This commit is contained in:
parent
b5fc0944bc
commit
08b9e4bf0e
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "salet",
|
||||
"version": "1.6.5",
|
||||
"version": "1.6.6",
|
||||
"description": "A general client-side framework for cybertext interactive fiction games.",
|
||||
"keywords": ["ifiction", "interactive fiction", "games", "coffee-script", "text", "menu"],
|
||||
"homepage": "http://salet.oreolek.ru",
|
||||
|
|
|
@ -231,6 +231,18 @@ class SaletRoom
|
|||
return salet.view.cycleLink(response)
|
||||
}
|
||||
|
||||
# Short way of saying "this room is connected to that room"
|
||||
@link = (name) =>
|
||||
if salet.rooms[name]
|
||||
@ways.push(name)
|
||||
|
||||
# Short way of saying "this room is connected to that room and vice versa"
|
||||
@bilink = (name) =>
|
||||
another = salet.rooms[name]
|
||||
if another
|
||||
@link(name)
|
||||
another.link(@name)
|
||||
|
||||
for index, value of spec
|
||||
this[index] = value
|
||||
return this
|
||||
|
|
|
@ -6,7 +6,7 @@ There is only one instance of this class.
|
|||
###
|
||||
class Salet
|
||||
constructor: (spec) ->
|
||||
@version = "1.6.5"
|
||||
@version = "1.6.6"
|
||||
@character = new Character
|
||||
|
||||
# REDEFINE THIS IN YOUR GAME
|
||||
|
|
|
@ -40,7 +40,7 @@ $(document).ready(function() {
|
|||
assert.equal(salet.character.has("lamp"), false, "The character has no lamp again");
|
||||
return;
|
||||
});
|
||||
QUnit.test("Rooms and units", function(assert) {
|
||||
QUnit.test("Units in rooms", function(assert) {
|
||||
var lamp;
|
||||
lamp = unit("lamp", {
|
||||
display: "lamp description",
|
||||
|
@ -66,24 +66,43 @@ $(document).ready(function() {
|
|||
salet.view.append("<p>hello</p>");
|
||||
return assert.equal(jQuery("#content").html(), "<p>hello</p>", "View writes new content");
|
||||
});
|
||||
return setTimeout(function() {
|
||||
setTimeout(function() {
|
||||
salet.goTo("start2");
|
||||
QUnit.test("Salet enters second room", function(assert) {
|
||||
assert.equal(salet.current, "start2", "This is the second room");
|
||||
return assert.equal($("#content").text(), "This is the second room.\n", "The room description is printed ok.");
|
||||
});
|
||||
|
||||
QUnit.test("Player visited the second room", function(assert) {
|
||||
assert.equal(salet.isVisited("start2"), true, "Salet assures us the player visited the second room");
|
||||
assert.equal(salet.isVisited("third"), false, "Salet assures us the player did not visit the third room yet");
|
||||
});
|
||||
|
||||
salet.goTo("start");
|
||||
QUnit.test("The second room forbids exiting (boolean)", function(assert) {
|
||||
return assert.equal(salet.current, "start2", "This is still the second room");
|
||||
});
|
||||
salet.goTo("start2");
|
||||
|
||||
salet.goBack()
|
||||
QUnit.test("goBack() returns the player back", function(assert) {
|
||||
return assert.equal(salet.current, "start2", "The player went back as intended");
|
||||
});
|
||||
|
||||
salet.rooms["start2"].canExit = function() {
|
||||
return false;
|
||||
};
|
||||
salet.goTo("start2");
|
||||
salet.goTo("start");
|
||||
return QUnit.test("The second room forbids exiting (function)", function(assert) {
|
||||
QUnit.test("The second room forbids exiting (function)", function(assert) {
|
||||
return assert.equal(salet.current, "start2", "This is still the second room");
|
||||
});
|
||||
salet.rooms["start2"].canExit = true;
|
||||
|
||||
salet.rooms["start2"].bilink("start");
|
||||
QUnit.test("The second room is linked to first one and vice versa", function(assert) {
|
||||
assert.equal(salet.rooms["start2"].ways[0], "start", "Second room is linked to the first one");
|
||||
assert.equal(salet.rooms["start"].ways[0], "start2", "First room is linked to the second one");
|
||||
});
|
||||
}, 100);
|
||||
});
|
||||
|
||||
|
@ -95,3 +114,8 @@ room("start2", {
|
|||
dsc: "This is the second room.",
|
||||
canExit: false
|
||||
});
|
||||
|
||||
room("third", {
|
||||
dsc: "This is the third room.",
|
||||
tags: ["tag", "third"]
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue