Merge pull request #201 from jedmund/fix-weapon-conflicts

Fix weapon conflicts
This commit is contained in:
Justin Edmund 2023-01-29 23:39:14 -08:00 committed by GitHub
commit 7a87b066ff
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -152,6 +152,24 @@ const WeaponGrid = (props: Props) => {
if (weapon.uncap.ulb) uncapLevel = 5 if (weapon.uncap.ulb) uncapLevel = 5
else if (weapon.uncap.flb) uncapLevel = 4 else if (weapon.uncap.flb) uncapLevel = 4
let post = false
if (
position === -1 &&
(!appState.grid.weapons.mainWeapon ||
(appState.grid.weapons.mainWeapon &&
appState.grid.weapons.mainWeapon.object.id !== weapon.id))
) {
post = true
} else if (
position !== -1 &&
(!appState.grid.weapons.allWeapons[position] ||
(appState.grid.weapons.allWeapons[position] &&
appState.grid.weapons.allWeapons[position]?.object.id !== weapon.id))
) {
post = true
}
if (post) {
return await api.endpoints.weapons.create({ return await api.endpoints.weapons.create({
weapon: { weapon: {
party_id: partyId, party_id: partyId,
@ -162,9 +180,10 @@ const WeaponGrid = (props: Props) => {
}, },
}) })
} }
}
function storeGridWeapon(gridWeapon: GridWeapon) { function storeGridWeapon(gridWeapon: GridWeapon) {
if (gridWeapon.position == -1) { if (gridWeapon.position === -1) {
appState.grid.weapons.mainWeapon = gridWeapon appState.grid.weapons.mainWeapon = gridWeapon
appState.party.element = gridWeapon.object.element appState.party.element = gridWeapon.object.element
} else { } else {
@ -183,9 +202,6 @@ const WeaponGrid = (props: Props) => {
position: position, position: position,
}) })
.then((response) => { .then((response) => {
// Store new character in state
storeGridWeapon(response.data)
// Remove conflicting characters from state // Remove conflicting characters from state
conflicts.forEach((c) => { conflicts.forEach((c) => {
if (appState.grid.weapons.mainWeapon?.object.id === c.id) { if (appState.grid.weapons.mainWeapon?.object.id === c.id) {
@ -196,6 +212,9 @@ const WeaponGrid = (props: Props) => {
} }
}) })
// Store new character in state
storeGridWeapon(response.data.grid_weapon)
// Reset conflict // Reset conflict
resetConflict() resetConflict()