Fixed a heisenbug with taverns.
This commit is contained in:
parent
36387c563c
commit
e9119d0eb9
|
@ -69,23 +69,27 @@ class Maze
|
|||
console.log "Special encounter set to (#{x}, #{y})"
|
||||
###
|
||||
|
||||
mettavern = false
|
||||
metbath = false
|
||||
metworkshop = false
|
||||
for y in [0..(@height-1)]
|
||||
for x in [0..(@width-1)]
|
||||
type = @data[x][y].getType()
|
||||
if type == 'bath'
|
||||
metbath = true
|
||||
salet.character.bathname = @data[x][y].loctitle
|
||||
jQuery(document).on("maze_"+x+"_"+y, () ->
|
||||
bathevent()
|
||||
)
|
||||
if type == 'workshop'
|
||||
metworkshop = true
|
||||
salet.character.workshopname = @data[x][y].loctitle
|
||||
jQuery(document).on("maze_"+x+"_"+y, () ->
|
||||
workshopevent()
|
||||
)
|
||||
switch type
|
||||
when 'bath'
|
||||
metbath = true
|
||||
salet.character.bathname = @data[x][y].loctitle
|
||||
jQuery(document).on("maze_"+x+"_"+y, () ->
|
||||
bathevent()
|
||||
)
|
||||
when 'workshop'
|
||||
metworkshop = true
|
||||
salet.character.workshopname = @data[x][y].loctitle
|
||||
jQuery(document).on("maze_"+x+"_"+y, () ->
|
||||
workshopevent()
|
||||
)
|
||||
when 'tavern'
|
||||
mettavern = true
|
||||
|
||||
# если внезапно на карте ни одной бани, ставим баню на 0,0 и вешаем событие
|
||||
unless metbath
|
||||
|
@ -97,6 +101,9 @@ class Maze
|
|||
@setCell('workshop', 'interior', @height-2, @width-1, improv, () ->
|
||||
workshopevent()
|
||||
)
|
||||
# особенно если ни одной таверны
|
||||
unless mettavern
|
||||
@setCell('tavern', 'interior', 0, @width-1, improv)
|
||||
|
||||
return true
|
||||
setCell: (type, position, x, y, improv, event) ->
|
||||
|
@ -104,7 +111,8 @@ class Maze
|
|||
@data[x][y].setTag('position', position)
|
||||
@data[x][y].loctitle = improv.gen('loctitle', @data[x][y])
|
||||
salet.character.bathname = @data[x][y].loctitle
|
||||
jQuery(document).on("maze_"+x+"_"+y, event)
|
||||
if event?
|
||||
jQuery(document).on("maze_"+x+"_"+y, event)
|
||||
at: (x, y) ->
|
||||
if x? and y? and @data[x]? and @data[x][y]?
|
||||
return @data[x][y]
|
||||
|
|
|
@ -35,10 +35,12 @@ sysroom = (name, options) ->
|
|||
options.dsc ?= () ->
|
||||
return @text.fcall()
|
||||
options.text ?= () -> name.l()
|
||||
###
|
||||
options.actions = {
|
||||
exit: () ->
|
||||
return salet.goBack()
|
||||
}
|
||||
###
|
||||
return croom(name, options)
|
||||
|
||||
croom = (name, spec) ->
|
||||
|
|
|
@ -52,12 +52,11 @@
|
|||
<!-- Dependency JS Libraries -->
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/marked/0.3.5/marked.min.js"></script>
|
||||
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/sigma.js/1.2.0/sigma.min.js"></script>
|
||||
<script src="https://code.jquery.com/qunit/qunit-2.3.3.js"></script>
|
||||
|
||||
<script src="game/salet.min.js"></script>
|
||||
<script src="game/bundle.js"></script>
|
||||
|
||||
<script defer="defer" src="game/bundle.js"></script>
|
||||
<script defer="defer" src="test/main.js"></script>
|
||||
|
||||
</body>
|
||||
|
|
36
test/main.js
36
test/main.js
|
@ -4,32 +4,30 @@ salet.autoload = false;
|
|||
$(document).ready(function() {
|
||||
QUnit.test("The game starts okay.", function(assert) {
|
||||
assert.notEqual(salet, void 0, "Salet is initialized");
|
||||
return assert.equal(salet.current, salet.start, "Salet is in the room called '"+salet.start+"'");
|
||||
assert.notEqual(salet.character.maze, void 0, "The maze exists");
|
||||
assert.notEqual(salet.character.x, undefined, "We know the character's position.");
|
||||
assert.notEqual(salet.character.y, undefined, "We know the character's position.");
|
||||
assert.notEqual(salet.character.getCell(), false, "The current map cell exists")
|
||||
});
|
||||
QUnit.test("There are no game-breaking bugs when entering rooms.", function(assert) {
|
||||
QUnit.test("There are no game-breaking bugs in all rooms or actions.", function(assert) {
|
||||
for (var key in salet.rooms) {
|
||||
// skip loop if the property is from prototype
|
||||
if (!salet.rooms.hasOwnProperty(key)) continue;
|
||||
|
||||
var room = salet.rooms[key];
|
||||
|
||||
// we place the character to the map centre, so there are cells around
|
||||
salet.character.x = 2;
|
||||
salet.character.y = 2;
|
||||
assert.ok(salet.goTo(room.name), "Entered room "+room.name);
|
||||
}
|
||||
});
|
||||
QUnit.test("There are no game-breaking bugs in all actions.", function(assert) {
|
||||
for (var key in salet.rooms) {
|
||||
// skip loop if the property is from prototype
|
||||
if (!salet.rooms.hasOwnProperty(key)) continue;
|
||||
var room = salet.rooms[key];
|
||||
|
||||
salet.goTo(room.name);
|
||||
for (var act in room.actions) {
|
||||
if (!room.actions.hasOwnProperty(act)) continue;
|
||||
assert.ok(act.fcall(room), "Executed action "+act);
|
||||
}
|
||||
for (var act in room.writers) {
|
||||
if (!room.writers.hasOwnProperty(act)) continue;
|
||||
assert.ok(act.fcall(room), "Executed action "+act);
|
||||
if (room.actions !== undefined) {
|
||||
for (var act in room.actions) {
|
||||
if (!room.actions.hasOwnProperty(act)) continue;
|
||||
assert.ok(act.fcall(room), "Executed action "+act);
|
||||
}
|
||||
for (var act in room.writers) {
|
||||
if (!room.writers.hasOwnProperty(act)) continue;
|
||||
assert.ok(act.fcall(room), "Executed action "+act);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue