forked from badicsalex/stickman-warfare
-
Notifications
You must be signed in to change notification settings - Fork 2
Basic storage and process modernization, basic API, basic bot kills, basic Sentry, scripts unit #10
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
dagoddamnlazysnake
wants to merge
15
commits into
develop
Choose a base branch
from
feature/thread_handler
base: develop
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 6 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
a2b14fc
Script handling moved to separate unit
dagoddamnlazysnake e28f286
MutableObject, DynamicArray, Redux
dagoddamnlazysnake 8e51075
Sentry w/ save to local file
dagoddamnlazysnake bb39e36
ThreadHandler base, WIP
dagoddamnlazysnake 9de7c9a
stickAPI reworked with ThreadHandler
dagoddamnlazysnake 2ef3a15
stickAPI POST, botkill reporting
strxs-farkaszoltan d61a1d4
translated comments
strxs-farkaszoltan 65e6cd9
pr fixes
strxs-farkaszoltan ff531e2
remove unnecessary files
strxs-farkaszoltan 17e374c
Replace 'dotenv' for Defines.inc
wasweb 59d1d0c
Fix warnings and remove unused variables
wasweb 20a120a
Merge pull request #11 from StickmanWarfare/feature/thread_handler-fix
dagoddamnlazysnake 8c0713e
added explicit default returns to new units functions
strxs-farkaszoltan 3585329
ThreadHandler comment transations
strxs-farkaszoltan af20e69
Merge branch 'develop' into feature/thread_handler
dagoddamnlazysnake 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,235 @@ | ||
| unit DynamicArray; | ||
|
|
||
| interface | ||
| uses | ||
| SysUtils, | ||
| // | ||
| Typestuff; | ||
|
|
||
| type TVariantArray = array of Variant; | ||
|
|
||
| type TDynamicArray = class (TObject) | ||
| private | ||
| _items: TVariantArray; | ||
| _isFrozen: boolean; | ||
| _isPermaFrozen: boolean; | ||
| public | ||
| constructor Create(); overload; | ||
| constructor Create(items: TVariantArray); overload; | ||
| procedure init; | ||
| // | ||
| function push(item: Variant): Integer; //index | ||
| function pop: Variant; | ||
| function items: TVariantArray; | ||
| function at(index: Integer): Variant; | ||
| function head: Variant; | ||
| function tail: TVariantArray; | ||
| function size: Integer; | ||
| function isEmpty: boolean; | ||
| function isFrozen: boolean; | ||
| function isPermaFrozen: boolean; | ||
| function find(comparator: TComparatorFunction): Variant; | ||
| function findIndex(comparator: TComparatorFunction): Integer; | ||
| function difference(other: TDynamicArray): TDynamicArray; | ||
| procedure clear; | ||
| procedure map(mutator: TMutatorFunction); | ||
| procedure merge(other: TDynamicArray); | ||
| procedure freeze(isPermanent: boolean = false); | ||
| procedure unFreeze; | ||
| function toJSON(): string; | ||
| end; | ||
|
|
||
| implementation | ||
|
|
||
| procedure TDynamicArray.init; | ||
| begin | ||
| setlength(_items, 0); | ||
| _isFrozen := false; | ||
| _isPermaFrozen := false; | ||
| end; | ||
|
|
||
| constructor TDynamicArray.Create; | ||
| begin | ||
| inherited Create; | ||
|
|
||
| init; | ||
| end; | ||
|
|
||
| constructor TDynamicArray.Create(items: TVariantArray); | ||
| begin | ||
| inherited Create; | ||
|
|
||
| init; | ||
|
|
||
| setlength(_items, length(items)); | ||
| _items := copy(items, low(items), length(items)); | ||
| end; | ||
|
|
||
| function TDynamicArray.push(item: Variant): Integer; //index | ||
| begin | ||
| result := -1; | ||
|
|
||
| if _isFrozen or _isPermaFrozen then exit; | ||
|
|
||
| setlength(_items, succ(length(_items))); | ||
| _items[high(_items)] := item; | ||
|
|
||
| result := high(_items); | ||
| end; | ||
|
|
||
| function TDynamicArray.pop: Variant; | ||
| begin | ||
| if _isFrozen or _isPermaFrozen then exit; | ||
|
|
||
| if length(_items) <= 0 then exit; | ||
|
|
||
| result := _items[high(_items)]; | ||
| setlength(_items, pred(length(_items))); | ||
| end; | ||
|
|
||
| function TDynamicArray.items: TVariantArray; | ||
| begin | ||
| result := _items; | ||
| end; | ||
|
|
||
| function TDynamicArray.at(index: Integer): Variant; | ||
| begin | ||
| if length(_items) <= 0 then exit; | ||
| if index >= length(_items) then exit; | ||
| if index <= 0 then exit; | ||
|
|
||
| result := _items[index]; | ||
| end; | ||
|
|
||
| function TDynamicArray.head: Variant; | ||
| begin | ||
| if length(_items) <= 0 then exit; | ||
|
|
||
| result := _items[low(_items)]; | ||
| end; | ||
|
|
||
| function TDynamicArray.tail: TVariantArray; | ||
| begin | ||
| if length(_items) <= 1 then exit; | ||
|
|
||
| result := copy(_items, 1, length(_items) - 1); | ||
| end; | ||
|
|
||
| function TDynamicArray.size: Integer; | ||
| begin | ||
| result := length(_items); | ||
| end; | ||
|
|
||
| function TDynamicArray.isEmpty: boolean; | ||
| begin | ||
| result := length(_items) <= 0; | ||
| end; | ||
|
|
||
| function TDynamicArray.isFrozen: boolean; | ||
| begin | ||
| result := _isFrozen = true; | ||
| end; | ||
|
|
||
| function TDynamicArray.isPermaFrozen: boolean; | ||
| begin | ||
| result := _isPermaFrozen = true; | ||
| end; | ||
|
|
||
| function TDynamicArray.find(comparator: TComparatorFunction): Variant; | ||
| var | ||
| i: Integer; | ||
| begin | ||
| if length(_items) <= 1 then exit; | ||
|
|
||
| for i := low(_items) to high(_items) do | ||
| begin | ||
| if comparator(_items[i], intToStr(i)) then | ||
| begin | ||
| result := _items[i]; | ||
| exit; | ||
| end; | ||
| end; | ||
|
|
||
| end; | ||
|
|
||
| function TDynamicArray.findIndex(comparator: TComparatorFunction): Integer; | ||
| var | ||
| i: Integer; | ||
| begin | ||
| if length(_items) <= 1 then result := -1; | ||
|
|
||
| for i := low(_items) to high(_items) do | ||
| begin | ||
| if comparator(_items[i], intToStr(i)) then | ||
| begin | ||
| result := i; | ||
| exit; | ||
| end; | ||
| end; | ||
|
|
||
| end; | ||
|
|
||
| function TDynamicArray.difference(other: TDynamicArray): TDynamicArray; | ||
| begin | ||
| result := TDynamicArray.Create; | ||
|
|
||
| if length(_items) <= 1 then exit; | ||
|
|
||
| //TODO: return items in self but not in other | ||
| end; | ||
|
|
||
| procedure TDynamicArray.clear; | ||
| begin | ||
| if _isFrozen or _isPermaFrozen then exit; | ||
|
|
||
| setlength(_items, 0); | ||
| end; | ||
|
|
||
| procedure TDynamicArray.map(mutator: TMutatorFunction); | ||
| var | ||
| i: Integer; | ||
| begin | ||
| if _isFrozen or _isPermaFrozen then exit; | ||
|
|
||
| for i := low(_items) to high(_items) do | ||
| _items[i] := mutator(_items[i], intToStr(i)); | ||
|
|
||
| end; | ||
|
|
||
| procedure TDynamicArray.merge(other: TDynamicArray); | ||
| begin | ||
| if _isFrozen or _isPermaFrozen then exit; | ||
|
|
||
| //TODO: append items to end | ||
| end; | ||
|
|
||
| procedure TDynamicArray.freeze(isPermanent: boolean = false); | ||
| begin | ||
| _isFrozen := true; | ||
| _isPermaFrozen := _isPermaFrozen or isPermanent; | ||
| end; | ||
|
|
||
| procedure TDynamicArray.unFreeze; | ||
| begin | ||
| if _isPermaFrozen then exit; | ||
|
|
||
| _isFrozen := false; | ||
| end; | ||
|
|
||
| function TDynamicArray.toJSON(): string; | ||
| var | ||
| i: Integer; | ||
| begin | ||
| result := '['; | ||
|
|
||
| for i := low(_items) to high(_items) do | ||
| begin | ||
| if i > low(_items) then result := result + ', '; | ||
|
|
||
| result := result + variantToStr(_items[i]); | ||
| end; | ||
|
|
||
| result := result + ']'; | ||
| end; | ||
|
|
||
| end. | ||
Oops, something went wrong.
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.
Ezt még át akarom pakolni privátba, csak elfelejtettem.