Open CalebJohn opened 8 years ago
window
is inherently accessible from everywhere, I think making world data a property of window
is a reasonable solution. Perhaps even better would be to attach it to game
since it is inherently a part of the game as well.
So it looks like globally defined variables in javascript are implicitly added to window, I highly recommend reading the top comment on this stackoverflow post. For reference I ran some quick tests: I defined these at the top of main.js
var worldData = 20;
test = 10;
window.test2 = 5;
this.test3 = 1;
and these in the preload function
console.log(worldData);
console.log(window.worldData);
console.log(test);
console.log(window.test);
console.log(test2);
console.log(window.test2);
console.log(test3);
console.log(this.test3);
console.log(window.test3);
this was the output
20
20
10
10
5
5
1
undefined
1
I also tried printing out worldData and window.worldData from Menu.js and got the same result (20) in both cases.
I think what this means for us is that we need to decide on a convention for globally accessible variables, because it doesn't matter how we define them they are always the same. I suggest we use the standard javascript format for global variables worldData = X
and given that idiomatic.js doesn't seem to have much to say on formatting of globals, I propase we leave it as is (worldData
).
edit: I forgot to discuss the possibility of adding the variable to game
, I like the way it reads and am not opposed to doing it that way if you would prefer it like that.
To elaborate on this,
PlanetData should keep reference to each of the sectors present in the planet. Each sector will be a separate object that holds the sector specific data.
PlanetData should also keep reference to the player and locations of all bases (1 for the prototype) and locations of radio towers. Player and bases will both be separate objects.
Whenever possible information should be stored and accessed through planetData and planet data. Systems like the primary gui and the global map view should be calling into planetData to get information about how to display.
Planet data should maintain a seed for the world generation for prototype
Rockiness Fertility Humidity Altitude Variablity
I'm gonna add some basic info to this so that I can work on the graphical planet map
I think this is done?
I want to add a seeded random number generator to this so that we can store other attributes that havent been generated yet. Such as abundance of each resource. Currently the only seed we store is the seed for the noise, which is created by calling a random function. So we will want to implement an actual seeded random number generator so that we can save a seed a regenerate the same planet again if we want.
Im gonna take a stab at this in the Godot build, but its likely something well want to do a few revisions of.
We need an object that can hold all of our world (and player?) data and be accessible globally. When implementing this we'll have to look up the best way to make things globally accessible from javascript