-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathCharacterStats.tsx
More file actions
154 lines (132 loc) · 3.96 KB
/
Copy pathCharacterStats.tsx
File metadata and controls
154 lines (132 loc) · 3.96 KB
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
150
151
152
153
154
import { parseColor } from "onejs/utils/color-parser"
import { h } from "preact"
import { useEffect, useState } from "preact/hooks"
import { Style } from "preact/jsx"
//#region Stylings
const panelStyle: Style = {
width: 580,
height: 80,
borderRadius: 6,
position: "Absolute",
bottom: 80,
left: 80,
backgroundColor: "rgba(0, 0, 0, 0.2)",
padding: 10,
flexDirection: "Row"
}
const leftSideStyle: Style = {
flexGrow: 1,
flexShrink: 1,
}
const rightSideStyle: Style = {
width: "20%",
height: "100%",
flexDirection: "Row",
justifyContent: "SpaceAround",
alignItems: "Center",
}
const armorRowStyle: Style = {
display: "Flex",
height: "30%",
flexDirection: "Row",
justifyContent: "SpaceBetween",
alignItems: "Center"
}
const armorBarStyle: Style = {
backgroundColor: "rgba(0, 0, 0, 0.2)",
width: 356,
height: "100%"
}
const healthRowStyle: Style = {
display: "Flex",
height: "60%",
flexDirection: "Row",
justifyContent: "SpaceBetween",
alignItems: "Center"
}
const healthBarStyle: Style = {
backgroundColor: "rgba(0, 0, 0, 0.2)",
width: 356,
height: "100%"
}
const healthBarMaskStyle: Style = {
height: "100%",
overflow: "Hidden",
width: "100%"
}
const healthBarGradientStyle: Style = {
width: 356,
height: "100%"
}
const iconStyle: Style = {
unityFontDefinition: __dirname + "/resources/rpgawesome.ttf",
color: "white",
fontSize: 20,
height: "100%",
justifyContent: "Center",
unityTextAlign: "MiddleCenter",
width: 40
}
const numberStyle: Style = {
color: "white",
fontSize: 20,
unityFontStyleAndWeight: "Bold",
height: "100%",
justifyContent: "Center",
unityTextAlign: "MiddleCenter",
width: 50
}
const shieldStyle: Style = {
unityFontDefinition: __dirname + "/resources/rpgawesome.ttf",
color: "#89FFFF",
fontSize: 60,
height: "100%"
}
const shieldNumberStyle: Style = {
color: "white",
fontSize: 30,
unityFontStyleAndWeight: "Bold",
unityTextAlign: "MiddleCenter",
}
//#endregion
const CharacterStats = () => {
var charman = require("charman") as FortniteSample.CharacterManager
const [health, setHealth] = useState(charman.GetHealth())
useEffect(() => {
// Good practice to always clean up event handler to prevent leaks during Live Reload
charman.remove_OnHealthChanged(onHealthChanged)
charman.add_OnHealthChanged(onHealthChanged)
onEngineReload(() => {
charman.remove_OnHealthChanged(onHealthChanged)
})
}, [])
function onHealthChanged(hp: number): void {
setHealth(hp)
}
return (
<div style={panelStyle}>
<div style={leftSideStyle}>
<div style={armorRowStyle}>
<div style={iconStyle}></div>
<div style={armorBarStyle}><gradientrect colors={[parseColor("#007CCC"), parseColor("#00A0E6")]} style={{ width: "50%", height: "100%" }} /></div>
<div style={numberStyle}>50</div>
</div>
<div style={{ height: "10%" }}></div>
<div style={healthRowStyle}>
<div style={iconStyle}></div>
<div style={healthBarStyle}>
<div style={{ ...healthBarMaskStyle, width: `${health}%`, transitionProperty: ["width"], transitionDuration: [0.5], transitionTimingFunction: ["EaseInOut"] }}>
<gradientrect colors={[parseColor("#02BC23"), parseColor("#48E025")]} style={healthBarGradientStyle} />
</div>
</div>
<div style={numberStyle}>{health}</div>
</div>
</div>
<div style={rightSideStyle}>
<div style={shieldStyle}></div>
<div style={shieldNumberStyle}>50</div>
</div>
</div >
)
}
export default CharacterStats