-
Notifications
You must be signed in to change notification settings - Fork 57
refactor(esx_dmvschool): code structure #76
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ghost
wants to merge
6
commits into
main
Choose a base branch
from
dmvschool-fix
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,30 +1,34 @@ | ||
| Locales['es'] = { | ||
| ['you_paid'] = 'Pagaste %s$ a la autoescuela', | ||
| ['go_next_point'] = '¡Vete al siguiente punto!', | ||
| ['in_town_speed'] = '¡Entraste a la ciudad, presta atención a tu velocidad! Límite de velocidad: %s km/h', | ||
| ['next_point_speed'] = '¡Vete al siguiente punto! Límite de velocidad: %s km/h', | ||
| ['stop_for_ped'] = '~r~Para en el paso de peatones', | ||
| ['good_lets_cont'] = 'Bien, continua', | ||
| ['stop_look_left'] = '~r~Para y mira a la izquierda. Límite de velocidad: %s km/h', | ||
| ['good_turn_right'] = 'Bien, gira a la derecha y sigue la línea', | ||
| ['watch_traffic_lightson'] = '¡Mira el tráfico y enciende las luces!', | ||
| ['stop_for_passing'] = '¡~r~Para para que pasen los vehículos!', | ||
| ['hway_time'] = '¡Es hora de conducir por la autopista! Límite de velocidad: %s km/h', | ||
| ['gratz_stay_alert'] = '¡Estoy impresionado pero no dejes de estar ~r~alerta mientras conduces!', | ||
| ['passed_test'] = 'Has aprobado el examen, ¡Enorabuena!', | ||
| ['failed_test'] = 'Has ~r~suspendido el examen, ¡Más suerte la próxima vez!', | ||
| ['theory_test'] = 'Examen teórico de conducir', | ||
| ['road_test_car'] = 'Examen práctico de conducir', | ||
| ['road_test_bike'] = 'Examen práctico de moto', | ||
| ['road_test_truck'] = 'Examen práctico de camiones', | ||
| ['school_item'] = '%s$', | ||
| ['driving_school'] = 'Escuela de conducción', | ||
| ['press_open_menu'] = 'Pulsa [E] para abrir el menú', | ||
| ['driving_school_blip'] = 'Autoescuela', | ||
| ['driving_test_complete'] = 'Examen de conducir finalizado', | ||
| ['driving_too_fast'] = '¡~r~Estás conduciendo muy rápido, el límite de velocidad actual es: %s km/h!', | ||
| Locales['en'] = { | ||
| ['you_paid'] = 'you paid $%s to the DMV school', | ||
| ['go_next_point'] = 'go to the next point!', | ||
| ['in_town_speed'] = 'entered town, pay attention to your speed! Speed Limit: %s km/h', | ||
| ['next_point_speed'] = 'go to the next point! Speed Limit: %s km/h', | ||
| ['stop_for_ped'] = '~r~Stop for the pedestrian crossing', | ||
| ['good_lets_cont'] = 'Good, continue.', | ||
| ['stop_look_left'] = '~r~Stop and look left. Speed Limit: %s km/h', | ||
| ['good_turn_right'] = 'Good, turn right and follow the line', | ||
| ['watch_traffic_lightson'] = 'watch the traffic and turn on your lights!', | ||
| ['stop_for_passing'] = '~r~Stop for passing vehicles!', | ||
| ['hway_time'] = 'it\'s time to drive on the highway! Speed Limit: %s km/h', | ||
| ['gratz_stay_alert'] = 'i\'m impressed, but don\'t forget to stay ~r~alert whilst driving!', | ||
| ['passed_test'] = 'you passed the test, congratulations!', | ||
| ['failed_test'] = 'you ~r~failed the test, better luck next time!', | ||
| ['theory_test'] = 'theoretical Driving Test', | ||
| ['road_test_car'] = 'driving Test', | ||
| ['road_test_bike'] = 'motorcycle Skills Test', | ||
| ['road_test_truck'] = 'truck Skills Test', | ||
| ['school_item'] = '$%s', | ||
| ['driving_school'] = 'driving School', | ||
| ['press_open_menu'] = 'press [E] to open the menu', | ||
| ['driving_school_blip'] = 'driving School', | ||
| ['driving_test_complete'] = 'driving test completed', | ||
| ['driving_too_fast'] = '~r~You\'re driving too fast, the current speed limit is: %s km/h!', | ||
| ['test_failed_go_to_start_point'] = '~r~Go to the starting point, because you failed the test!', | ||
| ['errors'] = 'Fallos: ~r~%s / %s', | ||
| ['you_damaged_veh'] = '¡Has dañado el vehículo!', | ||
| ['not_enough_money'] = 'No tienes suficiente dinero' | ||
| ['errors'] = 'mistakes: ~r~%s/%s', | ||
| ['you_damaged_veh'] = 'you damaged the vehicle', | ||
| ['not_enough_money'] = 'You don\'t have enough money', | ||
| ['yourVersion'] = "Your version: ", | ||
| ['latestVersion'] = "You are using the latest version!", | ||
| ['needUpdateResource'] = "You need download latest version! You are using an old version at the moment!", | ||
| ['errorGetCurrentVersion'] = "An error occurred while trying to get the current version!" | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| DMV = DMV or {} | ||
|
|
||
| DMV.VersionCheckBaseURL = "https://raw.githubusercontent.com/esx-framework/ESX-Legacy-Addons/main/%5Besx_addons%5D/" | ||
|
|
||
| function DMV:ErrorHandle(msg) | ||
| local resourceName = GetCurrentResourceName() | ||
| print(("[^1ERROR^7] ^3%s^7: %s"):format(resourceName, msg)) | ||
| end | ||
|
|
||
| function DMV:InfoHandle(msg, color) | ||
| local resourceName = GetCurrentResourceName() | ||
| local c = ({green=2, red=1, blue=4})[color] or 3 | ||
| print(("[^9INFO^7] ^3%s^7: ^" .. c .. "%s^7"):format(resourceName, msg)) | ||
| end | ||
|
|
||
| local function normalizeSemver(v) | ||
| if type(v) ~= "string" then return nil end | ||
| local three = v:match("%d+%.%d+%.%d+") | ||
| if three then return three end | ||
| local two = v:match("^%d+%.%d+$") | ||
| if two then return (two .. ".0") end | ||
| local one = v:match("^%d+$") | ||
| if one then return (one .. ".0.0") end | ||
| return nil | ||
| end | ||
|
|
||
| VERSION = { | ||
| Check = function(err, response, headers) | ||
| local resourceName = GetCurrentResourceName() | ||
| local currentVersion = GetResourceMetadata(resourceName, "version", 0) | ||
| if not currentVersion then return end | ||
|
|
||
| local manifestURL = DMV.VersionCheckBaseURL .. resourceName .. "/fxmanifest.lua" | ||
| DMV:InfoHandle(("Checking manifest from %s"):format(manifestURL), "blue") | ||
|
|
||
| if err ~= 200 or not response then | ||
| DMV:ErrorHandle(Translate("errorGetCurrentVersion")) | ||
| return | ||
| end | ||
|
|
||
| local remoteVersion = response:match("version%s+'([%d%.]+)'") | ||
| if not remoteVersion then | ||
| DMV:ErrorHandle(Translate("errorGetRemoteVersion")) | ||
| return | ||
| end | ||
|
|
||
| local latestVersion = normalizeSemver(remoteVersion) | ||
| currentVersion = normalizeSemver(currentVersion) | ||
|
|
||
| if not latestVersion or not currentVersion then | ||
| DMV:ErrorHandle(Translate("invalidVersion")) | ||
| return | ||
| end | ||
|
|
||
| if currentVersion == latestVersion then | ||
| DMV:InfoHandle(Translate("latestVersion"), "green") | ||
| DMV:InfoHandle(("Up to date version (%s)"):format(currentVersion), "green") | ||
| return | ||
| end | ||
|
|
||
| local currentVersionSplitted = { string.strsplit(".", currentVersion) } | ||
| local latestVersionSplitted = { string.strsplit(".", latestVersion) } | ||
|
|
||
| DMV:InfoHandle(Translate("currentVersion") .. latestVersion, "green") | ||
| DMV:InfoHandle(Translate("yourVersion") .. currentVersion, "blue") | ||
| DMV:InfoHandle(("Update available: remote %s > local %s"):format(latestVersion, currentVersion), "red") | ||
|
|
||
| for i = 1, #currentVersionSplitted do | ||
| local current, latest = tonumber(currentVersionSplitted[i]), tonumber(latestVersionSplitted[i]) | ||
| if current ~= latest then | ||
| if not current or not latest then return end | ||
| if current < latest then | ||
| DMV:InfoHandle(Translate("needUpdateResource"), "red") | ||
| end | ||
| break | ||
| end | ||
| end | ||
| end, | ||
|
|
||
| RunVersionChecker = function() | ||
| CreateThread(function() | ||
| local resourceName = GetCurrentResourceName() | ||
| local manifestURL = DMV.VersionCheckBaseURL .. resourceName .. "/fxmanifest.lua" | ||
| PerformHttpRequest(manifestURL, VERSION.Check, "GET") | ||
| end) | ||
| end, | ||
| } | ||
|
|
||
| AddEventHandler("onResourceStart", function(resourceName) | ||
| local currentName = GetCurrentResourceName() | ||
| if resourceName ~= currentName then return end | ||
|
|
||
| Wait(100) | ||
| VERSION:RunVersionChecker() | ||
| end) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thats not german