Skip to content

Commit

Permalink
Prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
reyronald committed Feb 2, 2024
1 parent b7e396a commit aa0c844
Show file tree
Hide file tree
Showing 12 changed files with 418 additions and 411 deletions.
18 changes: 9 additions & 9 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
version: 2
updates:
- package-ecosystem: npm
directory: "/"
schedule:
interval: daily
open-pull-requests-limit: 10
ignore:
- dependency-name: react-scripts
versions:
- 4.0.2
- package-ecosystem: npm
directory: "/"
schedule:
interval: daily
open-pull-requests-limit: 10
ignore:
- dependency-name: react-scripts
versions:
- 4.0.2
1 change: 0 additions & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"useTabs": true,
"semi": false,
"trailingComma": "all"
}
2 changes: 1 addition & 1 deletion public/index.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!DOCTYPE html>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
Expand Down
59 changes: 30 additions & 29 deletions src/ACTListener.js
Original file line number Diff line number Diff line change
@@ -1,43 +1,44 @@
const getHost = () => /[?&]HOST_PORT=(wss?:\/\/[^&/]+)/.exec(window.location.search)
const getHost = () =>
/[?&]HOST_PORT=(wss?:\/\/[^&/]+)/.exec(window.location.search)

export default function listenToACT(callback) {
if (!getHost()) return listenOverlayPlugin(callback)
return listenActWebSocket(callback)
if (!getHost()) return listenOverlayPlugin(callback)
return listenActWebSocket(callback)
}

// https://github.com/OverlayPlugin/cactbot/blob/main/docs/LogGuide.md
function listenActWebSocket(callback) {
const wsUri = `${getHost()[1]}/BeforeLogLineRead` || undefined
const ws = new WebSocket(wsUri)
ws.onerror = () => ws.close()
ws.onclose = () =>
setTimeout(() => {
listenActWebSocket(callback)
}, 1000)
ws.onmessage = function(e, m) {
if (e.data === ".") return ws.send(".")
const wsUri = `${getHost()[1]}/BeforeLogLineRead` || undefined
const ws = new WebSocket(wsUri)
ws.onerror = () => ws.close()
ws.onclose = () =>
setTimeout(() => {
listenActWebSocket(callback)
}, 1000)
ws.onmessage = function (e, m) {
if (e.data === ".") return ws.send(".")

const obj = JSON.parse(e.data)
if (obj.msgtype === "SendCharName") {
return callback(obj.msg)
} else if (obj.msgtype === "Chat") {
return callback(...obj.msg.split("|"))
}
}
const obj = JSON.parse(e.data)
if (obj.msgtype === "SendCharName") {
return callback(obj.msg)
} else if (obj.msgtype === "Chat") {
return callback(...obj.msg.split("|"))
}
}

return () => {
ws.close()
}
return () => {
ws.close()
}
}

function listenOverlayPlugin(callback) {
const listener = e => {
callback(...e.detail)
}
const listener = (e) => {
callback(...e.detail)
}

document.addEventListener("onLogLine", listener)
document.addEventListener("onLogLine", listener)

return () => {
document.removeEventListener("onLogLine", listener)
}
return () => {
document.removeEventListener("onLogLine", listener)
}
}
236 changes: 118 additions & 118 deletions src/Action.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,140 +3,140 @@ import "./css/Action.css"
import { SPRINT_ACTION_ID } from "./constants"

const gcdOverrides = new Set([
15997, //standard step
15998, //technical step
15999,
16000,
16001,
16002, //step actions
16003, //standard finish
16004, //technical finish
16191, //single standard finish
16192, //double standard finish (WHY IS IT LIKE THIS)
16193, //single technical finish
16194, //double technical finish
16195, //triple technical finish
16196, //quadruple technical finish
7418, //flamethrower
16484, //kaeshi higanbana
16485, //kaeshi goken
16486, //kaeshi setsugekka
2259, //ten
18805,
2261, //chi
18806,
2263, //jin
18807,
2265, //fuma shurikan
18873,
18874,
18875,
2267, //raiton
18877,
2266, //katon
18876,
2268, //hyoton
18878,
16492, //hyosho ranryu
16471, //goka meykakku
16491, //goka meykakku (16471 is the PvP version, 16491 is the PvE version)
2270, //doton
18880,
2269, //huton
18879,
2271, //suiton
18881,
2272, //rabbit medium
15997, //standard step
15998, //technical step
15999,
16000,
16001,
16002, //step actions
16003, //standard finish
16004, //technical finish
16191, //single standard finish
16192, //double standard finish (WHY IS IT LIKE THIS)
16193, //single technical finish
16194, //double technical finish
16195, //triple technical finish
16196, //quadruple technical finish
7418, //flamethrower
16484, //kaeshi higanbana
16485, //kaeshi goken
16486, //kaeshi setsugekka
2259, //ten
18805,
2261, //chi
18806,
2263, //jin
18807,
2265, //fuma shurikan
18873,
18874,
18875,
2267, //raiton
18877,
2266, //katon
18876,
2268, //hyoton
18878,
16492, //hyosho ranryu
16471, //goka meykakku
16491, //goka meykakku (16471 is the PvP version, 16491 is the PvE version)
2270, //doton
18880,
2269, //huton
18879,
2271, //suiton
18881,
2272, //rabbit medium
])

const ogcdOverrides = new Set([
3559, //bard WM
116, //bard AP
114, //bard MB
SPRINT_ACTION_ID, // Sprint
3559, //bard WM
116, //bard AP
114, //bard MB
SPRINT_ACTION_ID, // Sprint
])

const actionOverrides = new Map([
// Sprint's actual api data has an innaccurate icon.
// https://xivapi.com/Action/3?columns=Icon,Name,ActionCategoryTargetID
// https://xivapi.com/i/000000/000405.png
[
SPRINT_ACTION_ID,
{
ActionCategoryTargetID: 10,
Icon: "/i/000000/000104.png",
Name: "Sprint",
},
],
// Sprint's actual api data has an innaccurate icon.
// https://xivapi.com/Action/3?columns=Icon,Name,ActionCategoryTargetID
// https://xivapi.com/i/000000/000405.png
[
SPRINT_ACTION_ID,
{
ActionCategoryTargetID: 10,
Icon: "/i/000000/000104.png",
Name: "Sprint",
},
],
])

const actionMap = new Map()

export default function Action({ actionId, ability, additionalClasses }) {
const [apiData, setApiData] = React.useState()

React.useEffect(() => {
const mapData = actionMap.get(actionId)
if (mapData != null) {
setApiData(mapData)
return
}

let current = true
void (async () => {
const itemId = getItemId(ability)
const url =
itemId == null
? `https://xivapi.com/Action/${actionId}?columns=Icon,Name,ActionCategoryTargetID`
: `https://xivapi.com/Item/${itemId}?columns=Name,Icon,IconHD,IconID`

const localData = actionOverrides.get(actionId)
const data =
localData || (await (await fetch(url, { mode: "cors" })).json())

if (current) {
actionMap.set(actionId, data)
setApiData(data)
}
})()

return () => {
current = false
}
}, [actionId, ability])

if (apiData === undefined || !apiData.Icon) {
return null
}

const isItem = getIsItem(ability)
const isGCD =
!isItem &&
(gcdOverrides.has(actionId) ||
(!ogcdOverrides.has(actionId) && apiData.ActionCategoryTargetID !== 4))

return (
<img
className={
isGCD ? `gcd ${additionalClasses}` : `ogcd ${additionalClasses}`
}
src={`https://xivapi.com/${apiData.Icon}`}
alt={apiData.Name || ""}
/>
)
const [apiData, setApiData] = React.useState()

React.useEffect(() => {
const mapData = actionMap.get(actionId)
if (mapData != null) {
setApiData(mapData)
return
}

let current = true
void (async () => {
const itemId = getItemId(ability)
const url =
itemId == null
? `https://xivapi.com/Action/${actionId}?columns=Icon,Name,ActionCategoryTargetID`
: `https://xivapi.com/Item/${itemId}?columns=Name,Icon,IconHD,IconID`

const localData = actionOverrides.get(actionId)
const data =
localData || (await (await fetch(url, { mode: "cors" })).json())

if (current) {
actionMap.set(actionId, data)
setApiData(data)
}
})()

return () => {
current = false
}
}, [actionId, ability])

if (apiData === undefined || !apiData.Icon) {
return null
}

const isItem = getIsItem(ability)
const isGCD =
!isItem &&
(gcdOverrides.has(actionId) ||
(!ogcdOverrides.has(actionId) && apiData.ActionCategoryTargetID !== 4))

return (
<img
className={
isGCD ? `gcd ${additionalClasses}` : `ogcd ${additionalClasses}`
}
src={`https://xivapi.com/${apiData.Icon}`}
alt={apiData.Name || ""}
/>
)
}

function getIsItem(ability) {
const isIt = ability.startsWith("item_")
return isIt
const isIt = ability.startsWith("item_")
return isIt
}

function getItemId(ability) {
const isItem = getIsItem(ability)
if (!isItem) return null
const isItem = getIsItem(ability)
if (!isItem) return null

const hex = ability.replace("item_", "")
const bigId = parseInt(hex, 16)
const itemId = bigId > 1000000 ? bigId - 1000000 : bigId
return itemId
const hex = ability.replace("item_", "")
const bigId = parseInt(hex, 16)
const itemId = bigId > 1000000 ? bigId - 1000000 : bigId
return itemId
}
Loading

0 comments on commit aa0c844

Please sign in to comment.