Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/binaries/data/mods/public/gui/gamesetup/gamesetup.js
Show First 20 Lines • Show All 880 Lines • ▼ Show 20 Lines | |||||
} | } | ||||
function initDefaults() | function initDefaults() | ||||
{ | { | ||||
// Remove gaia from both arrays | // Remove gaia from both arrays | ||||
g_DefaultPlayerData = g_Settings.PlayerDefaults; | g_DefaultPlayerData = g_Settings.PlayerDefaults; | ||||
g_DefaultPlayerData.shift(); | g_DefaultPlayerData.shift(); | ||||
// Don't change the underlying defaults file, as Atlas uses that file too | |||||
for (let i in g_DefaultPlayerData) | for (let i in g_DefaultPlayerData) | ||||
{ | |||||
g_DefaultPlayerData[i].Civ = "random"; | g_DefaultPlayerData[i].Civ = "random"; | ||||
g_DefaultPlayerData[i].Teams = -1; | |||||
} | |||||
} | } | ||||
/** | /** | ||||
* Sets default values for all g_GameAttribute settings which don't have a value set. | * Sets default values for all g_GameAttribute settings which don't have a value set. | ||||
*/ | */ | ||||
function supplementDefaults() | function supplementDefaults() | ||||
{ | { | ||||
for (let dropdown in g_Dropdowns) | for (let dropdown in g_Dropdowns) | ||||
▲ Show 20 Lines • Show All 456 Lines • ▼ Show 20 Lines | |||||
} | } | ||||
function sanitizePlayerData(playerData) | function sanitizePlayerData(playerData) | ||||
{ | { | ||||
// Remove gaia | // Remove gaia | ||||
if (playerData.length && !playerData[0]) | if (playerData.length && !playerData[0]) | ||||
playerData.shift(); | playerData.shift(); | ||||
// Use defaults if the map doesn't specify a value | |||||
playerData.forEach((pData, index) => { | playerData.forEach((pData, index) => { | ||||
pData.Color = pData.Color || g_PlayerColorPickerList[index]; | for (let prop in g_DefaultPlayerData[index]) | ||||
pData.Civ = pData.Civ || "random"; | if (!(prop in pData)) | ||||
pData[prop] = g_DefaultPlayerData[index][prop]; | |||||
if (!("Team" in pData)) | |||||
pData.Team = -1; | |||||
// Use default AI if the map doesn't specify any explicitly | |||||
if (!("AI" in pData)) | |||||
pData.AI = g_DefaultPlayerData[index].AI; | |||||
if (!("AIDiff" in pData)) | |||||
pData.AIDiff = g_DefaultPlayerData[index].AIDiff; | |||||
}); | }); | ||||
// Replace colors with the best matching color of PlayerDefaults | // Replace colors with the best matching color of PlayerDefaults | ||||
if (g_GameAttributes.mapType != "scenario") | if (g_GameAttributes.mapType != "scenario") | ||||
{ | { | ||||
playerData.forEach((pData, index) => { | playerData.forEach((pData, index) => { | ||||
let colorDistances = g_PlayerColorPickerList.map(color => colorDistance(color, pData.Color)); | let colorDistances = g_PlayerColorPickerList.map(color => colorDistance(color, pData.Color)); | ||||
let smallestDistance = colorDistances.find(distance => colorDistances.every(distance2 => (distance2 >= distance))); | let smallestDistance = colorDistances.find(distance => colorDistances.every(distance2 => (distance2 >= distance))); | ||||
▲ Show 20 Lines • Show All 743 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator