/
type-lib.ts
149 lines (127 loc) · 3.43 KB
/
type-lib.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
import { Interface } from "readline"
import { createReadStream } from "fs"
//The library for types to be included in every build
//These will be useful data structure types and
//other such structures and classes
//Currently excluded due to glitchiness
if (finished === false || finished === undefined)
{
const Global = window || global
//Vector 2 (position x and y + magnitude)
class Vec2
{
/**
* A vector 2, which is a vector in 2 dimensional space
* and can be a coordinate or a direction
*
*
* NOT READY FOR USE YET
*/
x : number
y : number
magnitude : number
constructor(x, y, magnitude?) {
this.x = x
this.y = y
if (magnitude)
{
this.magnitude = magnitude
}
}
//Makes all values on a 0 to 1 scale
//by dividing by the magnitude
Normalize()
{
if (this.magnitude === undefined)
{
console.error("MissingMagnitudeError: Magnitude is undefined, thus normalization is impossible for this vector.")
}
this.x = this.x / this.magnitude
this.y = this.y / this.magnitude
}
}
class LinkedListNode
{
/*
* A node for the Linked List data structure
*/
next : LinkedListNode
previous : LinkedListNode
data : any
constructor(next, previous, data?) {
this.next = next
this.previous = previous
if (data != null)
{
this.data = data
}
}
}
(Global as any).LinkedListNode = LinkedListNode
class LinkedList
{
/**
* A class for the Linked List data structure
*/
nodes : LinkedListNode[] = []
constructor(initialState? : LinkedListNode[]) {
//Need to check if it's an array else unshift won't work
if (initialState != null)
{
this.nodes = initialState
}
}
InsertAtHead(node : LinkedListNode)
{
this.nodes.unshift(node)
this.Update()
}
DeleteAtHead()
{
this.nodes.shift()
this.Update()
}
InsertAtEnd(node : LinkedListNode)
{
this.nodes.push(node)
this.Update()
}
DeleteAtEnd()
{
this.nodes.pop()
this.Update()
}
Search(data : any) : LinkedListNode
{
return this.nodes.find(data)
}
IsEmpty() : boolean
{
if (this.nodes.length === 0)
{
return true
}
else
{
return false
}
}
//Updates next and previous values for nodes
Update()
{
for (let i = 0; i < this.nodes.length; i++)
{
if (this.nodes[i-1] != undefined && this.nodes[i-1] != null)
{
this.nodes[i].previous = this.nodes[i-1]
}
if (this.nodes[i+1] != undefined && this.nodes[i+1] != null)
{
this.nodes[i].next = this.nodes[i+1]
}
}
}
}
(Global as any).LinkedList = LinkedList
}
var finished = true