Changeset View
Standalone View
binaries/data/mods/public/gui/campaign/gamesetup/gamesetup.js
- This file was added.
// Here should go functions to set up Campaign games. | |||||
var g_GameAttributes = { "settings": {} }; | |||||
var g_DefaultPlayerData = []; | |||||
function sanitizePlayerData(playerData) | |||||
{ | |||||
// Remove gaia | |||||
if (playerData.length && !playerData[0]) | |||||
playerData.shift(); | |||||
playerData.forEach((pData, index) => { | |||||
pData.Color = pData.Color; | |||||
pData.Civ = pData.Civ; | |||||
// 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; | |||||
}); | |||||
} | |||||
elexis: I recall having complained about introducing copies right?
Remember what the reason is why we… | |||||
// TODO: this is a minimalist patchwork from gamesetup.Js and only barely attempts to work. | |||||
Not Done Inline Actionsseriously elexis: seriously | |||||
function launchGame(level, levelID) | |||||
{ | |||||
Not Done Inline Actions
D194 also reuses some gamesetup functions to start the game (since gamesetup contains some things that are always intended to be done, like copying over playernames, determining unique seeds, randomizing botnames and potentially civs / map.
The campaign map should be able to specify arguments that are loaded in g_GameAttributes. Therefore this patch comes up with exactly the same set of needed commenmethods as D194 by the looks of things. elexis: 1. Move to common:
D194 also reuses some gamesetup functions to start the game (since gamesetup… | |||||
Not Done Inline ActionsWould love better input on that, possibly a PR on my GitHub branch. wraitii: Would love better input on that, possibly a PR on my GitHub branch. | |||||
Not Done Inline ActionsDon't introduce copies of code, but move the shared code to a helper function. Otherwise I have to sit on that for days again trying to figure out the differences between the copies and removing the differences (rP20354, rP20306, more to come and complained in the commits introducing these otherwise awesome maps, see /audits). PR possibly, after I finished removing your experimental copies that are already committed. elexis: Don't introduce copies of code, but move the shared code to a helper function. Otherwise I have… | |||||
if (!level.Map) | |||||
{ | |||||
warn("cannot start scenario: no maps specified."); | |||||
return; | |||||
} | |||||
loadSettingsValues(); | |||||
Not Done Inline ActionsAdding code when not sure if it's needed, then just keeping it if doesn't fall apart shows that you didn't quadruple check your code before proposing it for review. elexis: Adding code when not sure if it's needed, then just keeping it if doesn't fall apart shows that… | |||||
g_DefaultPlayerData = g_Settings.PlayerDefaults; | |||||
g_DefaultPlayerData.shift(); | |||||
let mapData = Engine.LoadMapSettings("maps/" + level.Map); | |||||
if (!mapData) | |||||
{ | |||||
warn("Could not load map"); | |||||
return; | |||||
} | |||||
let mapSettings = mapData && mapData.settings ? deepcopy(mapData.settings) : {}; | |||||
if (mapSettings.PlayerData) | |||||
sanitizePlayerData(mapSettings.PlayerData); | |||||
// Copy any new settings | |||||
g_GameAttributes.map = "maps/" + level.Map; | |||||
g_GameAttributes.script = mapSettings.Script; | |||||
for (let prop in mapSettings) | |||||
g_GameAttributes.settings[prop] = mapSettings[prop]; | |||||
// TODO: support default victory conditions? | |||||
Not Done Inline ActionsNo elexis: No | |||||
g_GameAttributes.settings.TriggerScripts = g_GameAttributes.settings.TriggerScripts || []; | |||||
g_GameAttributes.settings.mapType = "scenario"; | |||||
g_GameAttributes.mapType = "scenario"; | |||||
// Seed used for both map generation and simulation | |||||
g_GameAttributes.settings.Seed = Math.floor(Math.random() * Math.pow(2, 32)); | |||||
g_GameAttributes.settings.AISeed = Math.floor(Math.random() * Math.pow(2, 32)); | |||||
g_GameAttributes.matchID = Engine.GetMatchID(); | |||||
// TODO: player should be defined in the map or the campaign at the least. | |||||
let playerID = 1; | |||||
g_GameAttributes.campaignData = {"ID" : g_CampaignID, "template" : g_CampaignTemplate, "save": g_CampaignSave, "data" : g_CampaignData, "level" : levelID}; | |||||
Engine.StartGame(g_GameAttributes, playerID); | |||||
Engine.SwitchGuiPage("page_loading.xml", { | |||||
"attribs": g_GameAttributes, | |||||
"isNetworked" : false, | |||||
"playerAssignments": {} | |||||
}); | |||||
return g_GameAttributes.matchID; | |||||
} | |||||
No newline at end of file | |||||
leperUnsubmitted Not Done Inline ActionsThis whole file is a hack, most of this should reuse the new gamesetup, but I guess having this as minimal as needed until then is ok. Also some campaign maps might not even need (or want) and game setup screen (or choices) at all. leper: This whole file is a hack, most of this should reuse the new gamesetup, but I guess having this… | |||||
wraitiiAuthorUnsubmitted Not Done Inline ActionsDefinitely, I just needed something to start a game. wraitii: Definitely, I just needed something to start a game. |
I recall having complained about introducing copies right?
Remember what the reason is why we don't like copies? Because authors don't apply bugfixes that happened in the last months to this copy.