Skip to content

Commit

Permalink
i forgot to update readmy but also i made it more orginise
Browse files Browse the repository at this point in the history
  • Loading branch information
stuffbymax committed Jan 20, 2025
1 parent c3f030d commit 842211d
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 1 deletion.
53 changes: 52 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,53 @@
# Bash-Theft-Auto
a gta but in terminal

## optimalisation news

**Key Optimizations and Changes:**

1. **Plugin Loading:**
* Uses `find ... -print0` and `while read -r -d $'\0'` loop for handling filenames with spaces or special characters.
* Simplified `if` check for file existence using `[[ -f "$plugin" ]] && source "$plugin"`.
* Replaced the `find` command with process substitution, to be faster.

2. **`printf` for Output:**
* Replaced multiple `echo` statements with `printf` for more efficient and readable output formatting. `printf` is generally faster, and allows for precise formatting.

3. **Local Variables:**
* Used `local` keyword in functions to avoid unintentional variable collisions and improve the overall code.

4. **Error Handling:**
* Input validation for menu choices in function using regex (`=~ ^[0-9]+$`).
* Clearer error messages for invalid inputs.

5. **Function for Item Purchase:**
* Created a more generic `buy_item` to avoid duplicating code in the `buy_guns` function.
* Created a more generic `buy_hospital_item` to avoid duplicating code in the `visit_hospital` function.
* Created a more generic `buy_drug` to avoid duplicating code in the `buy_drugs` function.
* Created a more generic `sell_drug` to avoid duplicating code in the `sell_drugs` function.

6. **Function for Work Jobs:**
* Simplified the `work_job` function, removing redundant logic by using a single function that receives a parameter for the job type to select specific logic using `case` statements, the same for the `street_race`.

7. **Simplified Health and Damage Logic:**
* Simplified logic for random numbers.

8. **Readability:**
* Improved comments and spacing for better code clarity.
* Use `read -r` instead of just `read`.
* Use clear variable names to better understand what they represent.

9. **Arrays:**
* Saved and loaded arrays using `printf` and `read -r -a`.

10. **Logic:**
* Simplified nested `if` statements.
* Used `(( condition )) && action` syntax for concise conditional execution.

11. **tabs over spaces:**
* used tabs for optimalization saved about 4KB

**How to Use:**

1. **Save:** Save the code as a `.sh` file (e.g., `game.sh`).
2. **Make Executable:** `chmod +x game.sh`
3. **Run:** `./game.sh`
3 changes: 3 additions & 0 deletions bta-optimization.md → news/bta-optimization.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@
10. **Logic:**
* Simplified nested `if` statements.
* Used `(( condition )) && action` syntax for concise conditional execution.

11. **tabs over spaces:**
* used tabs for optimalization saved about 4KB

**How to Use:**

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 842211d

Please sign in to comment.