added fromObject method
This commit is contained in:
parent
9e7b456400
commit
64f1ea0be6
@ -15,8 +15,8 @@ const App: React.FC = () => {
|
|||||||
const retakesJSON = window.localStorage.getItem("retakesJSON")
|
const retakesJSON = window.localStorage.getItem("retakesJSON")
|
||||||
if (retakesJSON){
|
if (retakesJSON){
|
||||||
try{
|
try{
|
||||||
const parsedConfig: RetakesConfig = JSON.parse(retakesJSON)
|
const parsedConfig: Record<string,unknown> = JSON.parse(retakesJSON)
|
||||||
setRetakesConfig(parsedConfig)
|
setRetakesConfig(RetakesConfig.fromObject(parsedConfig))
|
||||||
}catch(err){
|
}catch(err){
|
||||||
window.localStorage.removeItem("retakesJSON")
|
window.localStorage.removeItem("retakesJSON")
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,15 @@ class Card {
|
|||||||
public toCvar(): string {
|
public toCvar(): string {
|
||||||
return `${this.title},${bToS(this.armor)},${bToS(this.helmet)},${this.items.join(",")}`
|
return `${this.title},${bToS(this.armor)},${bToS(this.helmet)},${this.items.join(",")}`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static fromObject(input: Record<string, unknown>): Card {
|
||||||
|
return new Card(
|
||||||
|
input.title as string,
|
||||||
|
input.armor as boolean,
|
||||||
|
input.helmet as boolean,
|
||||||
|
...input.items as Item[]
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -12,6 +12,13 @@ class CardGroup {
|
|||||||
public toCvar(): string {
|
public toCvar(): string {
|
||||||
return `${this.numInDeck};${this.cards.map(e => e.toCvar()).join(";")}`
|
return `${this.numInDeck};${this.cards.map(e => e.toCvar()).join(";")}`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static fromObject(input: Record<string, unknown>): CardGroup{
|
||||||
|
return new CardGroup(
|
||||||
|
input.numInDeck as number,
|
||||||
|
...(input.cards as Record<string, unknown>[]).map((e)=>Card.fromObject(e))
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default CardGroup
|
export default CardGroup
|
||||||
|
@ -12,6 +12,13 @@ class Deck {
|
|||||||
public toCvar(): string {
|
public toCvar(): string {
|
||||||
return `${this.numDefusers}|${this.cardGroups.map(e => e.toCvar()).join("|")}`
|
return `${this.numDefusers}|${this.cardGroups.map(e => e.toCvar()).join("|")}`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static fromObject(input: Record<string, unknown>): Deck{
|
||||||
|
return new Deck(
|
||||||
|
input.numDefusers as number,
|
||||||
|
...(input.cardGroups as Record<string, unknown>[]).map((e)=>CardGroup.fromObject(e))
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default Deck
|
export default Deck
|
||||||
|
@ -60,6 +60,7 @@ class RetakesConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public toCvar(): string{
|
public toCvar(): string{
|
||||||
|
console.debug("THIS:")
|
||||||
return `mp_retake_ct_loadout_default_pistol_round "${this.ctPistol.toCvar()}"
|
return `mp_retake_ct_loadout_default_pistol_round "${this.ctPistol.toCvar()}"
|
||||||
mp_retake_t_loadout_default_pistol_round "${this.tPistol.toCvar()}"
|
mp_retake_t_loadout_default_pistol_round "${this.tPistol.toCvar()}"
|
||||||
mp_retake_ct_loadout_upgraded_pistol_round "${this.ctUpgradedPistol.toCvar()}"
|
mp_retake_ct_loadout_upgraded_pistol_round "${this.ctUpgradedPistol.toCvar()}"
|
||||||
@ -75,6 +76,25 @@ mp_retake_t_loadout_bonus_card_availability "${this.tBonusAvailability.join(",")
|
|||||||
`
|
`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static fromObject(input: Record<string, unknown>): RetakesConfig {
|
||||||
|
return new RetakesConfig({
|
||||||
|
ctPistol: Deck.fromObject(input.ctPistol as Record<string, unknown>),
|
||||||
|
tPistol: Deck.fromObject(input.tPistol as Record<string,unknown>),
|
||||||
|
ctUpgradedPistol: Deck.fromObject(input.ctUpgradedPistol as Record<string,unknown>),
|
||||||
|
tUpgradedPistol: Deck.fromObject(input.tUpgradedPistol as Record<string,unknown>),
|
||||||
|
ctLight: Deck.fromObject(input.ctLight as Record<string,unknown>),
|
||||||
|
tLight: Deck.fromObject(input.tLight as Record<string,unknown>),
|
||||||
|
ctFull: Deck.fromObject(input.ctFull as Record<string,unknown>),
|
||||||
|
tFull: Deck.fromObject(input.tFull as Record<string,unknown>),
|
||||||
|
ctEnemy: Card.fromObject(input.ctEnemy as Record<string,unknown>),
|
||||||
|
tEnemy: Card.fromObject(input.tEnemy as Record<string,unknown>),
|
||||||
|
ctBonus: Card.fromObject(input.ctBonus as Record<string,unknown>),
|
||||||
|
tBonus: Card.fromObject(input.tBonus as Record<string,unknown>),
|
||||||
|
ctBonusAvailability: input.ctBonusAvailability as number[],
|
||||||
|
tBonusAvailability: input.tBonusAvailability as number[],
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default RetakesConfig
|
export default RetakesConfig
|
||||||
|
Loading…
Reference in New Issue
Block a user