| Config/script.js | this.name					= "commandersLog";
this.author					= "Thargoid";
this.copyright				= "Creative Commons: attribution, non-commercial, sharealike with clauses - see readme.txt";
this.description			= "Saves a list of significant events to the Commander";
this.version				= "1.01";
this.startUpComplete = function()
	{
	if(!missionVariables.commandersLogText) // if this is the first run of the OXP
		{ missionVariables.commandersLogText = "Log system first initialised"; }
	
	if(!missionVariables.commandersLogDate) // if this is the first run of the OXP
		{ missionVariables.commandersLogDate = clock.days + ":" + clock.hoursComponent + ":" + clock.minutesComponent + ":" + clock.secondsComponent; }
	this.textArray = missionVariables.commandersLogText.split(",");
	this.dateArray = missionVariables.commandersLogDate.split(",");
	this.oldRank = player.rank;
	this.oldCredits = player.credits;
	this.maxLogSize = 100; // set how max number of entries to store
	this.setInterface();
	}
this.shipDockedWithStation = function()
	{
	this.setInterface();
	this.playerWillSaveGame();
	}
this.playerWillSaveGame = function()
	{ 
	missionVariables.commandersLogText = this.textArray;
	missionVariables.commandersLogDate = this.dateArray;
	}
this.setInterface = function()
	{
	player.ship.dockedStation.setInterface("CommandersLog",
		{ title: "Commander's Log",
		category: "Logs",
		summary: "Displays the Commander's ship purchase and galactic jump history.",
		callback: this.$showLog.bind(this) });
	}	
	
this.$showLog = function()
	{
	mission.runScreen({title:"Commander's Log", messageKey:"commandersLog_header", choicesKey:"commandersLog_choices"}, this.choice);
	this.startPoint = 0;
	this.endPoint = this.textArray.length;
	if(this.endPoint > 14)
		{this.startPoint = this.endPoint - 15;}
	let listCounter = 0; // reset the counter
	for(listCounter = this.startPoint; listCounter < this.endPoint; listCounter++)
		{ mission.addMessageText(this.dateArray[listCounter] + " - " + this.textArray[listCounter]); }
	}
this.choice = function(choice)
	{
	switch(choice)
		{
		case "COMMANDERSLOG_1_DUMP":
			{
			player.consoleMessage("Commanders log written to latest.log", 6);
			log(this.name, "==========================================================");
			log(this.name, " ");
			
			let logCounter = 0 ; // reset the counter
			for(logCounter = 0;logCounter<this.dateArray.length;logCounter++)
				{ log(this.name, (this.dateArray[logCounter] + " - " + this.textArray[logCounter])); }
			log(this.name, " ");
			log(this.name, "==========================================================");
			break;
			}
			case "COMMANDERSLOG_2_RESET":
			{
			delete this.textArray;
			delete this.dateArray;
			this.textArray = new Array;
			this.dateArray = new Array;
			this.textArray[0] = "Commanders log reset";
			this.dateArray[0] = clock.days + ":" + clock.hoursComponent + ":" + clock.minutesComponent + ":" + clock.secondsComponent; 
			player.consoleMessage("Commander's log reset.", 6);
			this.playerWillSaveGame();
			break;
			}
		}
	}
	
this.playerEnteredNewGalaxy = function(galaxyNumber)
	{
	this.galaxyNumber = (galaxyNumber * 1 ) + 1;
	this.clockString = clock.days + ":" + clock.hoursComponent + ":" + clock.minutesComponent + ":" + clock.secondsComponent; 
	this.dateArray.push(this.clockString);
	this.textArray.push("Ship jumped to galaxy " + this.galaxyNumber);
	this.trimArrays();
	}
	
this.playerBoughtNewShip = function(ship)
	{
	this.clockString = clock.days + ":" + clock.hoursComponent + ":" + clock.minutesComponent + ":" + clock.secondsComponent; 
	this.dateArray.push(this.clockString);
	this.firstLetter = ship.name.charAt(0).toLowerCase();
	this.vowels = "aeiou";
	if(this.vowels.indexOf(this.firstLetter))
		{ this.prefix = "a ";}
	else
		{this.prefix = "an ";}
	this.textArray.push("Commander purchased "+ this.prefix + ship.name);
	this.trimArrays();
	}
	
this.shipWillExitWitchspace = function()
	{
	if(system.ID === -1)
		{
		this.clockString = clock.days + ":" + clock.hoursComponent + ":" + clock.minutesComponent + ":" + clock.secondsComponent; 
		this.dateArray.push(this.clockString);
		this.textArray.push("Witchspace misjump occurred");
		this.trimArrays();
		}
	}
this.guiScreenChanged = function(to, from)
	{
	if(to && to === "GUI_SCREEN_EQUIP_SHIP")
		{ this.oldCredits = player.credits; }
	}
	
this.playerBoughtEquipment = function(equip)
	{
	if(equip && equip == "EQ_RENOVATION")
		{	
		this.clockString = clock.days + ":" + clock.hoursComponent + ":" + clock.minutesComponent + ":" + clock.secondsComponent; 
		this.dateArray.push(this.clockString);
		this.textArray.push("Maintenance overhaul purchased at " + system.name + " for " + (this.oldCredits - player.credits) + "cr");
		this.trimArrays();
		}
	this.oldCredits = player.credits;	
	}
	
this.shipKilledOther = function(whom, damageType)
	{
	if(player.rank !== this.oldRank)
		{
		this.clockString = clock.days + ":" + clock.hoursComponent + ":" + clock.minutesComponent + ":" + clock.secondsComponent; 
		this.dateArray.push(this.clockString);
		this.textArray.push("Rank of " + player.rank + " achieved");
		this.trimArrays();
		}
	this.oldRank = player.rank;
	}
	
this.trimArrays = function()
	{
	if(this.dateArray[0] === "" || this.dateArray.length > this.maxLogSize) // remove the first empty item if present after adding first entry, or if array is too large
		{
		this.dateArray.shift();
		this.textArray.shift();
		}
	} |