Fixed loading issues by forcing rm_Ocean to wait until all prefabs are loaded before running.

Also added debug messages for all scripts loading.
This commit is contained in:
Robbie Antenesse 2016-05-18 14:35:29 -06:00
parent 2847374049
commit 27e95d4011
16 changed files with 99 additions and 42 deletions

View File

@ -1,4 +1,6 @@
function inventoryGUI() {}
function inventoryGUI() {
if (Oversimplified.DEBUG.showMessages) console.log("Ran inventoryGUI()");
}
guiControl.inventory = {
screen: "main",

View File

@ -1,4 +1,6 @@
function mapGUI() {}
function mapGUI() {
if (Oversimplified.DEBUG.showMessages) console.log("Ran mapGUI()");
}
guiControl.map = {
show: false,

View File

@ -1,4 +1,6 @@
function titleScreen () {}
function titleScreen () {
if (Oversimplified.DEBUG.showMessages) console.log("Ran titleScreen()");
}
guiControl.title = {
screen: "main",

View File

@ -1,4 +1,6 @@
function tradeGUI() {}
function tradeGUI() {
if (Oversimplified.DEBUG.showMessages) console.log("Ran tradeGUI()");
}
guiControl.trade = {
screen: "main", // "main", "buy", "sell", "gossip"

View File

@ -14,4 +14,6 @@ var snd_select = new OS.E.AddSound("Select", {wav: "audio/sounds/Select.wav", mp
var snd_sell = new OS.E.AddSound("Sell", {wav: "audio/sounds/Sell.wav", mp3: "audio/sounds/Sell.mp3"});
var snd_wave = new OS.E.AddSound("Wave Crash", {wav: "audio/sounds/Wave_Crash.wav", mp3: "audio/sounds/Wave_Crash.mp3"});
function loadAudio() {}
function loadAudio() {
if (Oversimplified.DEBUG.showMessages) console.log("Ran loadAudio()");
}

View File

@ -14,7 +14,9 @@ var ct_x = OS.C.Add("X", OS.Keycode.x);
var ct_m = OS.C.Add("M", OS.Keycode.m);
var ct_esc = OS.C.Add("Cancel", OS.Keycode.escape);
function loadControls () {}
function loadControls () {
if (Oversimplified.DEBUG.showMessages) console.log("Ran loadControls()");
}
function ct_up () {
return {

View File

@ -3,6 +3,8 @@ function loadGUIs() {
OS.AddScript("gui/inventoryGUI.js");
OS.AddScript("gui/mapGUI.js");
OS.AddScript("gui/tradeGUI.js");
if (Oversimplified.DEBUG.showMessages) console.log("Ran loadGUIs()");
}
var guiControl = {

View File

@ -217,4 +217,6 @@ function loadGameManager () {
for (var i = 0; i < G.economy.cargoItemWorth.length; i++) {
G.economy.cargoItemWorth[i] += Math.round(Math.randomRange(-5, 5));
}
if (Oversimplified.DEBUG.showMessages) console.log("Ran loadGameManager()");
}

View File

@ -1,6 +1,33 @@
var prefabsLoaded = 0;
var prefabsToLoad = 4;
function loadPrefabs() {
OS.AddScript("prefabs/shipPrefab.js");
OS.AddScript("prefabs/islandPrefab.js");
OS.AddScript("prefabs/oceanTilePrefab.js");
OS.AddScript("prefabs/wavePrefab.js");
// Delay switching to Ocean room until everything is loaded.
WaitForPrefabsToLoad();
if (Oversimplified.DEBUG.showMessages) console.log("Ran loadPrefabs()");
}
// Callback function that prevents Ocean room from loading before everything it references is loaded.
WaitForPrefabsToLoad = function () {
console.log("waiting for " + (prefabsToLoad - prefabsLoaded).toString() + " prefabs to load");
if (prefabsLoaded < prefabsToLoad || !window["oceanRoom"])
{
setTimeout(function(){WaitForPrefabsToLoad()}, 0.1);
} else {
// Create player and ocean objects in rm_Ocean.
G.player = rm_Ocean.AddObject(OS.P["Ship"]);
G.oceanParticle = rm_Ocean.AddObject(OS.P["Ocean Particle"]);
if (G.player.xBound) { // Force rm_Ocean to wait until G.player is completely loaded!
// Load the rooms only after the prefabs are loaded.
rm_Ocean.SetAsCurrentRoom();
} else {
setTimeout(function(){WaitForPrefabsToLoad()}, 0.1);
}
}
}

View File

@ -1,4 +1,5 @@
var rm_Ocean = OS.R.Add("Default", {
var rm_Load = OS.R.Add("Default");
var rm_Ocean = OS.R.Add("Ocean Room", {
// Putting my room "constants" here.
width: pixel(64) * 50, //50x45 map of 64x64 squares. This will allow a single pixel on the map to represent a 64x square and fit comfortably on screen.
height: pixel(64) * 44,
@ -13,5 +14,7 @@ var rm_Ocean = OS.R.Add("Default", {
function loadRooms() {
OS.AddScript("rooms/oceanRoom.js");
OS.SetRoom(rm_Ocean);
rm_Load.SetAsCurrentRoom();
if (Oversimplified.DEBUG.showMessages) console.log("Ran loadRooms()");
}

View File

@ -1,6 +1,9 @@
var ani_island_1 = OS.A.Add("Island 1", 256, 256, {});
function islandPrefab() {}
function islandPrefab() {
if (Oversimplified.DEBUG.showMessages) console.log("Ran islandPrefab()");
prefabsLoaded++;
}
var pr_island = OS.P.Add("Island", {
solid: true,

View File

@ -1,6 +1,9 @@
var ani_ocean = OS.A.Add("Ocean", 256, 256, {columns: 10, speed: 1/60});
function oceanTilePrefab() {}
function oceanTilePrefab() {
if (Oversimplified.DEBUG.showMessages) console.log("Ran oceanTilePrefab()");
prefabsLoaded++;
}
var pr_ocean = OS.P.Add("Ocean Particle", {
imageSrc: "images/ocean_sheet.png",

View File

@ -7,7 +7,10 @@ var ani_ship_dl = OS.A.Add("Ship Down-Left", 64, 64, {columns: 2, speed: 1/60, y
var ani_ship_d = OS.A.Add("Ship Down", 64, 64, {columns: 2, speed: 1/60, yOffset: 64 * 0});
var ani_ship_dr = OS.A.Add("Ship Down-Right", 64, 64, {columns: 2, speed: 1/60, yOffset: 64 * 2});
function shipPrefab() {}
function shipPrefab() {
if (Oversimplified.DEBUG.showMessages) console.log("Ran shipPrefab()");
prefabsLoaded++;
}
var pr_ship = OS.P.Add("Ship", {
solid: true,
@ -118,49 +121,49 @@ pr_ship.CheckMovement = function () {
var movedSuccessfully = false;
switch (this.direction) {
case 0:
if (this.image.currentAnimation != "Ship Right") this.SetAnimation("Ship Right");
if (this.sprite.currentAnimation != "Ship Right") this.SetAnimation("Ship Right");
if (this.doTakeStep) movedSuccessfully = this.SimpleMove(moveAmount, 0, true, pixel(4));
this.pointInFront.x = this.x + this.xBound + pixel(2) + moveAmount;
this.pointInFront.y = this.y;
break;
case 45:
if (this.image.currentAnimation != "Ship Up-Right") this.SetAnimation("Ship Up-Right");
if (this.sprite.currentAnimation != "Ship Up-Right") this.SetAnimation("Ship Up-Right");
if (this.doTakeStep) movedSuccessfully = this.SimpleMove(moveAmount, -moveAmount, true, pixel(4));
this.pointInFront.x = this.x + this.xBound + pixel(2) + moveAmount;
this.pointInFront.y = this.y - this.yBound - pixel(2) - moveAmount;
break;
case 90:
if (this.image.currentAnimation != "Ship Up") this.SetAnimation("Ship Up");
if (this.sprite.currentAnimation != "Ship Up") this.SetAnimation("Ship Up");
if (this.doTakeStep) movedSuccessfully = this.SimpleMove(0, -moveAmount, true, pixel(4));
this.pointInFront.x = this.x;
this.pointInFront.y = this.y - this.yBound - pixel(2) - moveAmount;
break;
case 135:
if (this.image.currentAnimation != "Ship Up-Left") this.SetAnimation("Ship Up-Left");
if (this.sprite.currentAnimation != "Ship Up-Left") this.SetAnimation("Ship Up-Left");
if (this.doTakeStep) movedSuccessfully = this.SimpleMove(-moveAmount, -moveAmount, true, pixel(4));
this.pointInFront.x = this.x - this.xBound - pixel(2) - moveAmount;
this.pointInFront.y = this.y - this.yBound - pixel(2) - moveAmount;
break;
case 180:
if (this.image.currentAnimation != "Ship Left") this.SetAnimation("Ship Left");
if (this.sprite.currentAnimation != "Ship Left") this.SetAnimation("Ship Left");
if (this.doTakeStep) movedSuccessfully = this.SimpleMove(-moveAmount, 0, true, pixel(4));
this.pointInFront.x = this.x - this.xBound - pixel(2) - moveAmount;
this.pointInFront.y = this.y;
break;
case 225:
if (this.image.currentAnimation != "Ship Down-Left") this.SetAnimation("Ship Down-Left");
if (this.sprite.currentAnimation != "Ship Down-Left") this.SetAnimation("Ship Down-Left");
if (this.doTakeStep) movedSuccessfully = this.SimpleMove(-moveAmount, moveAmount, true, pixel(4));
this.pointInFront.x = this.x - this.xBound - pixel(2) - moveAmount;
this.pointInFront.y = this.y + this.yBound + pixel(2) + moveAmount;
break;
case 270:
if (this.image.currentAnimation != "Ship Down") this.SetAnimation("Ship Down");
if (this.sprite.currentAnimation != "Ship Down") this.SetAnimation("Ship Down");
if (this.doTakeStep) movedSuccessfully = this.SimpleMove(0, moveAmount, true, pixel(4));
this.pointInFront.x = this.x;
this.pointInFront.y = this.y + this.yBound + pixel(2) + moveAmount;
break;
case 315:
if (this.image.currentAnimation != "Ship Down-Right") this.SetAnimation("Ship Down-Right");
if (this.sprite.currentAnimation != "Ship Down-Right") this.SetAnimation("Ship Down-Right");
if (this.doTakeStep) movedSuccessfully = this.SimpleMove(moveAmount, moveAmount, true, pixel(4));
this.pointInFront.x = this.x + this.xBound + pixel(2) + moveAmount;
this.pointInFront.y = this.y + this.yBound + pixel(2) + moveAmount;

View File

@ -1,6 +1,9 @@
var ani_wave = OS.A.Add("Wave", 64, 64, {columns: 10, speed: 1/10});
function wavePrefab() {}
function wavePrefab() {
if (Oversimplified.DEBUG.showMessages) console.log("Ran wavePrefab()");
prefabsLoaded++;
}
var pr_wave = OS.P.Add("Wave Particle", {
imageSrc: "images/wave_sheet.png",

View File

@ -1,13 +1,5 @@
function oceanRoom () {
// Create objects on room creation for persistence.
G.player = rm_Ocean.AddObject(OS.P["Ship"]);
G.oceanParticle = rm_Ocean.AddObject(OS.P["Ocean Particle"]);
rm_Ocean.GenerateMap();
// When room is loaded, explicitly set room to rm_Ocean, just in case "Default" doesn't work/is loaded too slowly
// to make sure DoFirst runs.
OS.SetRoom(rm_Ocean);
if (Oversimplified.DEBUG.showMessages) console.log("Ran oceanRoom()");
}
rm_Ocean.waveTimer = Math.round(Math.randomRange(30, 150));
@ -16,6 +8,11 @@ rm_Ocean.clockTimerCount = 1; // Set it to 1 so it doesn't check for player il
rm_Ocean.DoFirst = function () {
mus_title.Play();
// G.player and G.oceanParticle are created in loadPrefabs.js
rm_Ocean.GenerateMap();
console.log("player xBound: " + G.player.xBound);
G.player.x = (this.squareSize * (this.squaresX / 2)) - (this.squareSize / 2) - G.player.xBound;
G.player.y = (this.squareSize * (this.squaresY / 2));
// console.log(G.player.name + " created at " + G.player.x + ", " + G.player.y);

View File

@ -13,9 +13,11 @@ function start()
OS.AddScript("loadControls.js");
OS.AddScript("loadAudio.js");
OS.AddScript("loadGameManager.js");
OS.AddScript("loadPrefabs.js");
OS.AddScript("loadGUIs.js");
OS.AddScript("loadPrefabs.js");
OS.AddScript("loadRooms.js");
if (Oversimplified.DEBUG.showMessages) console.log("Ran start()");
}
function pixel(number) {