twitch addon

This commit is contained in:
Tabby 2025-04-21 00:17:07 +10:00
parent 2cd7af98a1
commit 07de7179c9
254 changed files with 18420 additions and 1 deletions

View file

@ -0,0 +1,32 @@
# Errors
## Information
This page is to explain the use and implementation of errors in VST. Errors have 3 parameters for code, description and extra information.
* error_code (enum @see VST_Error.VST_Code_Error) -> This parameter groups the types of errors in a general way.
* description (String) -> The description of the error is a general description of the general grouping in human language.
* info (String) -> The information is the particular description of the error. It should be used to add extra information about the particular error.
## New errors
To add new errors you must first ask yourself if it is necessary to add a new code or not. If necessary add the code in the VST_Error.VST_Code_Error enumeration.
To illustrate the error let's imagine that we have a function that updates the area of a triangle given a base and a height. This function updates an area parameter only if it is possible to calculate the area (the base or the height is greater than 0).
```GDScript
func calculateArea(base:int, heigth:int):
if base <= 0:
var error:VST_Error = VST_Error.new(VST_Error.VST_Code_Error.PARAM_ERROR, "base can't be less than or equals 0")
push_warning(str(error))
area = 0
elif height <= 0:
var error:VST_Error = VST_Error.new(VST_Error.VST_Code_Error.PARAM_ERROR, "height can't be less than or equals 0")
push_warning(str(error))
area = 0
else
area = (base*height)/2
```
## Error Codes
* PARAM_ERROR Use this code for errors that have to do with invalid parameters. An int that should be a String or a String that cannot be empty.
* TIMEOUT_ERROR Use this code when a timer runs out or there is no response from a system.
* NETWORK_ERROR Use this code when there is a network error ( > 400 and < 500)
* SERVER_ERROR Use this code when, in a network communication, the server is down or has a problem ( > 500 ).

View file

@ -0,0 +1,46 @@
# Network
## Information
The motivation for using this wrapper is to make easier the call APIs and gather responses and errors from the server. The idea is to make it as verbose as possible using a builder pattern so the request can be read at first glance.
Before making the network call, the wrapper will check a number of conditions within the "check_request_data" method which will throw a number of errors or warnings if the request is not well built. The wrapper is permissive with the definition of REST APIs, so you can have a GET call with body or a POST with GET parameters in the url (TBD).
Note: To achieve this effect, it is necessary to call new() and pass a node to the "launch_request" method, which will self manage all that's necessary for it to work.
## Usage
To use the wrapper for network requests simply build a Network_Call object and start configuring it with the to, with, etc... methods.
* to (String) -> url destination
* with (String) -> request body
* add_get_param (String,String) y add_all_get_param(Dictionary) -> add get params to request
* add_header(String,String) y add_all_header(Dictionary) -> add headers to request
* verb(Http_Method) -> set the method for REST request
* in_time(int) -> set the timeout time to the request
* set_on_call_success (Callable) -> call this function if the request was ok (200)
* set_on_call_fail (Callable) -> call this function if the request was fail (>400)
* no_cache -> set no cache for request ( only used in GET requests )
## Example
```GDScript
func _onReady():
Network_Call.new().to("https://catfact.ninja/fact").set_on_call_success(on_cat_fact).set_on_call_fail(on_error).launch_request(self)
func on_cat_fact(result):
$Label.text = str(result)
func on_error(error):
$Label.text = "Error requesting fact about cats :("
```
## Cache
The network module has a cache for GET requests to save time and bandwidth for similar requests in 'short' time spans.
Since nodes are ephemeral (network requests are nodes that disappear) the cache is stored on disk and not in memory (this resposability was left for the upper layers).
The cache works as follows:
* 1. The request is hashed ( using the url )
* 2. A file with the specific name ( the hash ) is searched for on disk.
* 3.a If it exists and it has not passed 300 seconds ( arbitrary and improvable time using an etag? ) the request is resolved and returns the file content.
* 3.b If the file does not exist or it has been more than 300 seconds, the request is made and cached using the same hash.
The time validity of this cache is on CACHE_TIME_IN_SECONDS constant in network_call.gd
The cached content is an array of bytes due to the heterogeneous nature of the possible requests (text, images, sound...).

View file

@ -0,0 +1,21 @@
# Testing
## Adding test
Use "assert_eq" for "primitive" values and "assert_eq_deep" for complex data
For add some test be sure:
1. Your test are inside /test folder
2. Your test file starts with test name
3. Your test script extends from "GutTest"
4. Your test methods starts also with test
You can use some useful methods for testing like:
* before_all -> Excecuted before all tests in the script
* before_each -> Excecuted before each test in the script
* after_each -> Excecuted after each test in the script
* after_all -> Excecuted after all tests in the script
## GUT Documentation
https://gut.readthedocs.io/en/latest/

View file

@ -0,0 +1,32 @@
# Develop
## GDLint
The idea behind installing a linter in this plugin is mainly code readability. That can make collaboration easier for other developers. Using the same consistent coding style makes it easier to collaborate with others and easier to understand what the plugin is doing.
### Installation
There are a few steps before you can use GDLint. You can consult the official documentation, but here's a summary
1. GDLinter is installed on addons folders. You don't need do nothing with it.
2. Deactivate GDLint from pluggins ( project -> configuration -> plugins )
3. Check your python version using 'python --version' or 'py --version'
- no version installed?
- Check windows store for windows ( best option in my opinion )
- On Mac 'brew install python' using Homebrew
- On Linux, you can use APT 'sudo apt install python3'
4. Install godot toolkit using 'pip3 install "gdtoolkit==4.*"'
- No pip installed? Download the script, from https://bootstrap.pypa.io/get-pip.py and type 'python get-pip.py' to install it.
5. Check gdlint version with 'gdlint --version'
- Nothing or error showed? try repeating the steps from 2
6. Activate GdLint again.
- If GDLint menu at the bottom doesnt appear, relaunch godot.
GDScript Toolkit Documentation -> https://github.com/Scony/godot-gdscript-toolkit
GDLinter Addon Documentation -> https://github.com/el-falso/gdlinter/
### Usage
As soon as you install the plugin and the toolkit you will see a menu at the bottom called GDLint. There it will show the problems with the code :)
![](img/gdlint-usage-1.png?raw=true)

Binary file not shown.

After

Width:  |  Height:  |  Size: 176 KiB

View file

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://beqmxv0pbk5dp"
path="res://.godot/imported/gdlint-usage-1.png-06a3e1d7a5f85d1fd83e80b21ea14d73.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://addons/very-simple-twitch/doc/img/gdlint-usage-1.png"
dest_files=["res://.godot/imported/gdlint-usage-1.png-06a3e1d7a5f85d1fd83e80b21ea14d73.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1