mirror of
https://github.com/doublespeakgames/adarkroom.git
synced 2026-05-28 00:01:54 +08:00
db4a346d21
Introduced state_manager.js almost all State gets/sets are now run through the manager (alias $SM). For now it was a simple, mostly straightforward replacement of calls. This means that there are redundancies and a lot of now unneeded code for things the SM will handle. However, since I had trouble with making those changes as well as introducing the manager all at once my first attempt, I am taking the wiser approach and making "one change" at a time like I should have instead of being too sure of myself. At this point, it seems to work, but there may be bugs I didn't catch. There was also no attempt made to update old saves to work with this. In theory, it shouldn't be too hard. (included is a list of all state changes) TODO: Save Update. Refactor: a lot, many many redundancies now. Refactor: "location centric" to "global centric". Relocate all calls to different update functions to event listeners where possible. ====================================================== The changes to State are as follows: .room (exists) > features.location.room .room > game.room .room.builder > game.room.builder .room.temperature > game.room.temperature .room.fire > game.room.fire .room.buttons > game.room.buttons .outside (exists) > features.location.outside .outside > game.outside .outside.population > game.outside.population .outside.buildings > game.outside.buildings .outside.workers > game.outside.workers .outside.seenForest > game.outside.seenForest .world (exists) > features.location.world .world > game.world .world.map > game.world.map .world.mask > game.world.mask .starved > character.starved .dehydrated > character.dehydrated .ship (exists) > featuers.location.spaceShip .ship > game.spaceShip .ship.hull > game.spaceShip.hull .ship.thrusters > game.spaceShip.thrusters .ship.seenWarning > game.spaceShip.seenWarning .ship.seenShip > game.spaceShip.seenShip .punches > character.punches .perks > character.perks .thieves > game.thieves .stolen > game.stolen .cityCleared > game.cityCleared .stores > stores .income > income
168 lines
4.5 KiB
JavaScript
168 lines
4.5 KiB
JavaScript
/**
|
|
* Module that registers the starship!
|
|
*/
|
|
var Ship = {
|
|
LIFTOFF_COOLDOWN: 120,
|
|
ALLOY_PER_HULL: 1,
|
|
ALLOY_PER_THRUSTER: 1,
|
|
BASE_HULL: 0,
|
|
BASE_THRUSTERS: 1,
|
|
|
|
name: "Ship",
|
|
init: function(options) {
|
|
this.options = $.extend(
|
|
this.options,
|
|
options
|
|
);
|
|
|
|
if(!$SM.get('features.location.spaceShip')) {
|
|
$SM.set('features.location.spaceShip', true);
|
|
$SM.setM('game.spaceShip', {
|
|
hull: Ship.BASE_HULL,
|
|
thrusters: Ship.BASE_THRUSTERS
|
|
});
|
|
}
|
|
|
|
// Create the Ship tab
|
|
this.tab = Header.addLocation("An Old Starship", "ship", Ship);
|
|
|
|
// Create the Ship panel
|
|
this.panel = $('<div>').attr('id', "shipPanel")
|
|
.addClass('location')
|
|
.appendTo('div#locationSlider');
|
|
|
|
Engine.updateSlider();
|
|
|
|
// Draw the hull label
|
|
var hullRow = $('<div>').attr('id', 'hullRow').appendTo('div#shipPanel');
|
|
$('<div>').addClass('row_key').text('hull:').appendTo(hullRow);
|
|
$('<div>').addClass('row_val').text($SM.get('game.spaceShip.hull')).appendTo(hullRow);
|
|
$('<div>').addClass('clear').appendTo(hullRow);
|
|
|
|
// Draw the thrusters label
|
|
var engineRow = $('<div>').attr('id', 'engineRow').appendTo('div#shipPanel');
|
|
$('<div>').addClass('row_key').text('engine:').appendTo(engineRow);
|
|
$('<div>').addClass('row_val').text($SM.get('game.spaceShip.thrusters')).appendTo(engineRow);
|
|
$('<div>').addClass('clear').appendTo(engineRow);
|
|
|
|
// Draw the reinforce button
|
|
new Button.Button({
|
|
id: 'reinforceButton',
|
|
text: 'reinforce hull',
|
|
click: Ship.reinforceHull,
|
|
width: '100px',
|
|
cost: {'alien alloy': Ship.ALLOY_PER_HULL}
|
|
}).appendTo('div#shipPanel');
|
|
|
|
// Draw the engine button
|
|
new Button.Button({
|
|
id: 'engineButton',
|
|
text: 'upgrade engine',
|
|
click: Ship.upgradeEngine,
|
|
width: '100px',
|
|
cost: {'alien alloy': Ship.ALLOY_PER_THRUSTER}
|
|
}).appendTo('div#shipPanel');
|
|
|
|
// Draw the lift off button
|
|
var b = new Button.Button({
|
|
id: 'liftoffButton',
|
|
text: 'lift off',
|
|
click: Ship.checkLiftOff,
|
|
width: '100px',
|
|
cooldown: Ship.LIFTOFF_COOLDOWN
|
|
}).appendTo('div#shipPanel');
|
|
|
|
if($SM.get('game.spaceShip.hull') <= 0) {
|
|
Button.setDisabled(b, true);
|
|
}
|
|
|
|
// Init Space
|
|
Space.init();
|
|
},
|
|
|
|
options: {}, // Nothing for now
|
|
|
|
onArrival: function(transition_diff) {
|
|
Ship.setTitle();
|
|
if(!$SM.get('game.spaceShip.seenShip')) {
|
|
Notifications.notify(Ship, 'somewhere above the debris cloud, the wanderer fleet hovers. been on this rock too long.');
|
|
$SM.set('game.spaceShip.seenShip', true);
|
|
Engine.saveGame();
|
|
}
|
|
|
|
Engine.moveStoresView(null, transition_diff);
|
|
},
|
|
|
|
setTitle: function() {
|
|
if(Engine.activeModule == this) {
|
|
document.title = "An Old Starship";
|
|
}
|
|
},
|
|
|
|
reinforceHull: function() {
|
|
if(Engine.getStore('alien alloy') < Ship.ALLOY_PER_HULL) {
|
|
Notifications.notify(Ship, "not enough alien alloy");
|
|
return false;
|
|
}
|
|
Engine.addStore('alien alloy', -Ship.ALLOY_PER_HULL);
|
|
$SM.add('game.spaceShip.hull', 1);
|
|
if($SM.get('game.spaceShip.hull') > 0) {
|
|
Button.setDisabled($('#liftoffButton', Ship.panel), false);
|
|
}
|
|
$('#hullRow .row_val', Ship.panel).text($SM.get('game.spaceShip.hull'));
|
|
},
|
|
|
|
upgradeEngine: function() {
|
|
if(Engine.getStore('alien alloy') < Ship.ALLOY_PER_THRUSTER) {
|
|
Notifications.notify(Ship, "not enough alien alloy");
|
|
return false;
|
|
}
|
|
Engine.addStore('alien alloy', -Ship.ALLOY_PER_THRUSTER);
|
|
$SM.add('game.spaceShip.thrusters', 1)
|
|
$('#engineRow .row_val', Ship.panel).text($SM.get('game.spaceShip.thrusters'));
|
|
},
|
|
|
|
getMaxHull: function() {
|
|
return $SM.get('game.spaceShip.hull');
|
|
},
|
|
|
|
checkLiftOff: function() {
|
|
if(!$SM.get('game.spaceShip.seenWarning')) {
|
|
Events.startEvent({
|
|
title: 'Ready to Leave?',
|
|
scenes: {
|
|
'start': {
|
|
text: [
|
|
"time to get out of this place. won't be coming back."
|
|
],
|
|
buttons: {
|
|
'fly': {
|
|
text: 'lift off',
|
|
onChoose: function() {
|
|
$SM.set('game.spaceShip.seenWarning', true);
|
|
Ship.liftOff();
|
|
},
|
|
nextScene: 'end'
|
|
},
|
|
'wait': {
|
|
text: 'linger',
|
|
onChoose: function() {
|
|
Button.clearCooldown($('#liftoffButton'));
|
|
},
|
|
nextScene: 'end'
|
|
}
|
|
}
|
|
}
|
|
}
|
|
});
|
|
} else {
|
|
Ship.liftOff();
|
|
}
|
|
},
|
|
|
|
liftOff: function () {
|
|
$('#outerSlider').animate({top: '700px'}, 300);
|
|
Space.onArrival();
|
|
Engine.activeModule = Space;
|
|
}
|
|
}; |