RFC: revised mission screens for JavaScript
Posted: Wed Oct 07, 2009 7:47 pm
The current interface/protocol for mission screens is a horrible mess. I’d like to replace it with a less horrible mess, but as I don’t actually use this stuff from the scripting side very much I need some sanity checking. (Paging Dr. Eric… Paging Dr Eric…)
Proposal:
1. Deprecate mission.showShipModel(), mission.setMusic(), mission.setBackgroundImage(), mission.showMissionScreen(), mission.addMessageText(), mission.addMessageTextKey() and mission.setChoicesKey(). I am not aware of any need to use these instead of mission.runMissionScreen().
2. Introduce a new mission screen method. I’m not sure what to call it since showMissionScreen() and runMissionScreen() are taken, but let’s call it newMissionScreen() for now. This function will take two arguments: a settings object, and a completion callback function. It will return true if the mission screen could be shown, and false otherwise. Example:
Since only the active mission screen’s completion function is called, and choice is passed as a parameter rather than a property of mission, there is no need to clear choice after the mission screen or deal with the possibility of other scripts’ choices being passed. The use of missionVariables.offering in Eric’s example also becomes unnecessary.
3. Also deprecate mission.runMissionScreen() and mission.choice, since the new mechanism makes them redundant. For 1.74, mission.runMissionScreen() would be implemented by calling mission.newMissionScreen(), then sending missionScreenEnded to the calling script only (not all world scripts as before).
4. Add a new event, missionScreenOpportunity, which is sent at the following times:
Because any given script may receive it an arbitrary number of times, scripts that want to decide whether to show a screen randomly should make the decision in shipDockedWithStation, rather than missionScreenEnded.
Issues
One issue I haven’t dealt with is the missionChoiceWasReset event, because frankly I can’t remember what it’s for.
Questions
Proposal:
1. Deprecate mission.showShipModel(), mission.setMusic(), mission.setBackgroundImage(), mission.showMissionScreen(), mission.addMessageText(), mission.addMessageTextKey() and mission.setChoicesKey(). I am not aware of any need to use these instead of mission.runMissionScreen().
2. Introduce a new mission screen method. I’m not sure what to call it since showMissionScreen() and runMissionScreen() are taken, but let’s call it newMissionScreen() for now. This function will take two arguments: a settings object, and a completion callback function. It will return true if the mission screen could be shown, and false otherwise. Example:
Code: Select all
var trumbleCompletion = function(choice)
{
if (choice == "OOLITE_TRUMBLE_YES")
{
missionVariables.trumbles = "TRUMBLE_BOUGHT";
player.credits -= 30;
player.ship.awardEquipment("EQ_TRUMBLE");
}
else
{
missionVariables.trumbles = "NOT_NOW";
}
}
mission.newMissionScreen({ messageKey: "oolite_trumble_offer", choiceKey: "oolite_trumble_offer_yesno", backgroundImage: "trumblebox.png" }, trumbleCompletion);
3. Also deprecate mission.runMissionScreen() and mission.choice, since the new mechanism makes them redundant. For 1.74, mission.runMissionScreen() would be implemented by calling mission.newMissionScreen(), then sending missionScreenEnded to the calling script only (not all world scripts as before).
4. Add a new event, missionScreenOpportunity, which is sent at the following times:
- Immediately after shipDockedWithStation, if no report screen was shown.
- Immediately after reportScreenEnded.
- Immediately after missionScreenEnded, as long as we’re still on the F5 screen.
Because any given script may receive it an arbitrary number of times, scripts that want to decide whether to show a screen randomly should make the decision in shipDockedWithStation, rather than missionScreenEnded.
Issues
One issue I haven’t dealt with is the missionChoiceWasReset event, because frankly I can’t remember what it’s for.
Questions
- Would changing to this system, and deprecating (in 1.74) and removing (in 1.75) the old system restrict OXPs in some way? In other words, can the additional flexibility of the current horribly complicated system actually be used for anything useful?
- Is there some source of complexity I haven’t addressed? Would it still be necessary to do a bunch of work outside the missionScreenOpportunity in order to implement simple mission screens?