| 695 | const CONFIGID_GAMEATTRIBUTES_SP = "lobbysettings"; |
| 696 | const CONFIGID_GAMEATTRIBUTES_MP = "lobbysettings_mp"; |
| 697 | function loadGameAttributesFromUserCfg() |
| 698 | { |
| 699 | var newAttributes_str = Engine.ConfigDB_GetValue("user", g_IsNetworked ? CONFIGID_GAMEATTRIBUTES_MP : CONFIGID_GAMEATTRIBUTES_SP); |
| 700 | if (newAttributes_str == null || newAttributes_str == "") |
| 701 | return; |
| 702 | |
| 703 | try |
| 704 | { |
| 705 | var attrs = JSON.parse(newAttributes_str); |
| 706 | } |
| 707 | catch (e) |
| 708 | { |
| 709 | warn("Error while loading game settings from user config: "+e); |
| 710 | return; |
| 711 | } |
| 712 | |
| 713 | if (!attrs.settings) |
| 714 | return; |
| 715 | |
| 716 | g_IsInGuiUpdate = true; |
| 717 | |
| 718 | // TODO: Check new attributes for being semantically correct. |
| 719 | g_GameAttributes = attrs; |
| 720 | |
| 721 | var mapName = attrs.map || ""; |
| 722 | var mapSettings = attrs.settings; |
| 723 | |
| 724 | // Assign new seeds and match id |
| 725 | attrs.matchID = Engine.GetMatchID(); |
| 726 | mapSettings.Seed = Math.floor(Math.random() * 65536); |
| 727 | mapSettings.AISeed = Math.floor(Math.random() * 65536); |
| 728 | |
| 729 | var mapFilterSelection = Engine.GetGUIObjectByName("mapFilterSelection"); |
| 730 | mapFilterSelection.selected = mapFilterSelection.list_data.indexOf(attrs.mapFilter); |
| 731 | |
| 732 | var mapTypeSelection = Engine.GetGUIObjectByName("mapTypeSelection"); |
| 733 | mapTypeSelection.selected = mapTypeSelection.list_data.indexOf(attrs.mapType); |
| 734 | |
| 735 | initMapNameList(); |
| 736 | |
| 737 | var mapSelectionBox = Engine.GetGUIObjectByName("mapSelection"); |
| 738 | mapSelectionBox.selected = mapSelectionBox.list_data.indexOf(mapName); |
| 739 | |
| 740 | if (mapSettings.PopulationCap) |
| 741 | { |
| 742 | var populationCapBox = Engine.GetGUIObjectByName("populationCap"); |
| 743 | populationCapBox.selected = populationCapBox.list_data.indexOf(mapSettings.PopulationCap); |
| 744 | } |
| 745 | if (mapSettings.StartingResources) |
| 746 | { |
| 747 | var startingResourcesBox = Engine.GetGUIObjectByName("startingResources"); |
| 748 | startingResourcesBox.selected = startingResourcesBox.list_data.indexOf(mapSettings.StartingResources); |
| 749 | } |
| 750 | |
| 751 | g_IsInGuiUpdate = false; |
| 752 | |
| 753 | onGameAttributesChange(); |
| 754 | } |
| 755 | |
| 756 | function saveGameAttributesToUserCfg() |
| 757 | { |
| 758 | Engine.ConfigDB_CreateValue("user", g_IsNetworked ? CONFIGID_GAMEATTRIBUTES_MP : CONFIGID_GAMEATTRIBUTES_SP, JSON.stringify(g_GameAttributes)); |
| 759 | Engine.ConfigDB_WriteFile("user", "config/user.cfg"); |
| 760 | } |