Skip to content

Commit 301baae

Browse files
refactor: remove country API, add local JSON file, load on server
1 parent d68836a commit 301baae

File tree

4 files changed

+203
-15
lines changed

4 files changed

+203
-15
lines changed

client/main.lua

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ local function skyCam(bool)
6868
end
6969

7070
local function openCharMenu(bool)
71-
QBCore.Functions.TriggerCallback('qb-multicharacter:server:GetNumberOfCharacters', function(result)
71+
QBCore.Functions.TriggerCallback('qb-multicharacter:server:GetNumberOfCharacters', function(result, countries)
7272
local translations = {}
7373
for k in pairs(Lang.fallback and Lang.fallback.phrases or Lang.phrases) do
7474
if k:sub(0, ('ui.'):len()) then
@@ -82,7 +82,8 @@ local function openCharMenu(bool)
8282
toggle = bool,
8383
nChar = result,
8484
enableDeleteButton = Config.EnableDeleteButton,
85-
translations = translations
85+
translations = translations,
86+
countries = countries,
8687
})
8788
skyCam(bool)
8889
if not loadScreenCheckState then

countries.json

Lines changed: 197 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,197 @@
1+
[
2+
"Afghanistan",
3+
"Albania",
4+
"Algeria",
5+
"Andorra",
6+
"Angola",
7+
"Antigua and Barbuda",
8+
"Argentina",
9+
"Armenia",
10+
"Australia",
11+
"Austria",
12+
"Azerbaijan",
13+
"Bahamas",
14+
"Bahrain",
15+
"Bangladesh",
16+
"Barbados",
17+
"Belarus",
18+
"Belgium",
19+
"Belize",
20+
"Benin",
21+
"Bhutan",
22+
"Bolivia",
23+
"Bosnia and Herzegovina",
24+
"Botswana",
25+
"Brazil",
26+
"Brunei",
27+
"Bulgaria",
28+
"Burkina Faso",
29+
"Burundi",
30+
"Cabo Verde",
31+
"Cambodia",
32+
"Cameroon",
33+
"Canada",
34+
"Central African Republic",
35+
"Chad",
36+
"Chile",
37+
"China",
38+
"Colombia",
39+
"Comoros",
40+
"Congo (Congo-Brazzaville)",
41+
"Congo (Democratic Republic of the Congo)",
42+
"Costa Rica",
43+
"Croatia",
44+
"Cuba",
45+
"Cyprus",
46+
"Czech Republic",
47+
"Denmark",
48+
"Djibouti",
49+
"Dominica",
50+
"Dominican Republic",
51+
"Ecuador",
52+
"Egypt",
53+
"El Salvador",
54+
"Equatorial Guinea",
55+
"Eritrea",
56+
"Estonia",
57+
"Eswatini",
58+
"Ethiopia",
59+
"Fiji",
60+
"Finland",
61+
"France",
62+
"Gabon",
63+
"Gambia",
64+
"Georgia",
65+
"Germany",
66+
"Ghana",
67+
"Greece",
68+
"Grenada",
69+
"Guatemala",
70+
"Guinea",
71+
"Guinea-Bissau",
72+
"Guyana",
73+
"Haiti",
74+
"Honduras",
75+
"Hungary",
76+
"Iceland",
77+
"India",
78+
"Indonesia",
79+
"Iran",
80+
"Iraq",
81+
"Ireland",
82+
"Israel",
83+
"Italy",
84+
"Jamaica",
85+
"Japan",
86+
"Jordan",
87+
"Kazakhstan",
88+
"Kenya",
89+
"Kiribati",
90+
"Kosovo",
91+
"Kuwait",
92+
"Kyrgyzstan",
93+
"Latvia",
94+
"Lebanon",
95+
"Lesotho",
96+
"Liberia",
97+
"Libya",
98+
"Liechtenstein",
99+
"Lithuania",
100+
"Luxembourg",
101+
"Madagascar",
102+
"Malawi",
103+
"Malaysia",
104+
"Maldives",
105+
"Mali",
106+
"Malta",
107+
"Marshall Islands",
108+
"Mauritania",
109+
"Mauritius",
110+
"Mexico",
111+
"Micronesia",
112+
"Moldova",
113+
"Monaco",
114+
"Mongolia",
115+
"Montenegro",
116+
"Morocco",
117+
"Mozambique",
118+
"Myanmar",
119+
"Namibia",
120+
"Nauru",
121+
"Nepal",
122+
"Netherlands",
123+
"New Zealand",
124+
"Nicaragua",
125+
"Niger",
126+
"Nigeria",
127+
"North Korea",
128+
"North Macedonia",
129+
"Norway",
130+
"Oman",
131+
"Pakistan",
132+
"Palau",
133+
"Palestine",
134+
"Panama",
135+
"Papua New Guinea",
136+
"Paraguay",
137+
"Peru",
138+
"Philippines",
139+
"Poland",
140+
"Portugal",
141+
"Qatar",
142+
"Romania",
143+
"Russia",
144+
"Rwanda",
145+
"Saint Kitts and Nevis",
146+
"Saint Lucia",
147+
"Saint Vincent and the Grenadines",
148+
"Samoa",
149+
"San Marino",
150+
"Sao Tome and Principe",
151+
"Saudi Arabia",
152+
"Senegal",
153+
"Serbia",
154+
"Seychelles",
155+
"Sierra Leone",
156+
"Singapore",
157+
"Slovakia",
158+
"Slovenia",
159+
"Solomon Islands",
160+
"Somalia",
161+
"South Africa",
162+
"South Korea",
163+
"South Sudan",
164+
"Spain",
165+
"Sri Lanka",
166+
"Sudan",
167+
"Suriname",
168+
"Sweden",
169+
"Switzerland",
170+
"Syria",
171+
"Taiwan",
172+
"Tajikistan",
173+
"Tanzania",
174+
"Thailand",
175+
"Timor-Leste",
176+
"Togo",
177+
"Tonga",
178+
"Trinidad and Tobago",
179+
"Tunisia",
180+
"Turkey",
181+
"Turkmenistan",
182+
"Tuvalu",
183+
"Uganda",
184+
"Ukraine",
185+
"United Arab Emirates",
186+
"United Kingdom",
187+
"United States of America",
188+
"Uruguay",
189+
"Uzbekistan",
190+
"Vanuatu",
191+
"Vatican City",
192+
"Venezuela",
193+
"Vietnam",
194+
"Yemen",
195+
"Zambia",
196+
"Zimbabwe"
197+
]

html/app.js

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,6 @@ document.addEventListener("DOMContentLoaded", () => {
3232
nationalities: [],
3333
},
3434
methods: {
35-
async fetchData() {
36-
const response = await fetch("https://restcountries.com/v3.1/all");
37-
if (response.ok) {
38-
const countries = await response.json();
39-
const result = countries.sort((a, b) => (a.name.common > b.name.common ? 1 : -1));
40-
41-
result.forEach((obj) => {
42-
this.nationalities.push(obj.name.common);
43-
});
44-
}
45-
},
4635
click_character: function (idx, type) {
4736
this.selectedCharacter = idx;
4837

@@ -156,7 +145,6 @@ document.addEventListener("DOMContentLoaded", () => {
156145
},
157146
},
158147
mounted() {
159-
this.fetchData();
160148
initializeValidator();
161149
var loadingProgress = 0;
162150
var loadingDots = 0;
@@ -167,6 +155,7 @@ document.addEventListener("DOMContentLoaded", () => {
167155
this.customNationality = event.data.customNationality;
168156
translationManager.setTranslations(event.data.translations);
169157
this.translations = event.data.translations;
158+
this.nationalities = event.data.countries;
170159
this.characterAmount = data.nChar;
171160
this.selectedCharacter = -1;
172161
this.show.register = false;

server/main.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
local QBCore = exports['qb-core']:GetCoreObject()
22
local hasDonePreloading = {}
3+
local Countries = json.decode(LoadResourceFile(GetCurrentResourceName(), '/countries.json'))
34

45
-- Functions
56

@@ -179,7 +180,7 @@ QBCore.Functions.CreateCallback('qb-multicharacter:server:GetNumberOfCharacters'
179180
else
180181
numOfChars = Config.DefaultNumberOfCharacters
181182
end
182-
cb(numOfChars)
183+
cb(numOfChars, Countries)
183184
end)
184185

185186
QBCore.Functions.CreateCallback('qb-multicharacter:server:setupCharacters', function(source, cb)

0 commit comments

Comments
 (0)