diff --git a/src/components/elements/EncounterVotingComponent.vue b/src/components/elements/EncounterVotingComponent.vue index e35e4fed..44e8e9bc 100644 --- a/src/components/elements/EncounterVotingComponent.vue +++ b/src/components/elements/EncounterVotingComponent.vue @@ -10,7 +10,7 @@
{ console.log("res", res); - let parsedCard = this.$cardChain.cardObjectToWebModel(res); + let parsedCard = res console.log("currentCard", parsedCard); if (parsedCard) { this.cards.push(parsedCard); diff --git a/src/components/elements/VotingComponents/InfoComponent.vue b/src/components/elements/VotingComponents/InfoComponent.vue index 6279ccf0..1e15ea0f 100644 --- a/src/components/elements/VotingComponents/InfoComponent.vue +++ b/src/components/elements/VotingComponents/InfoComponent.vue @@ -1,21 +1,21 @@ @@ -23,40 +23,19 @@ diff --git a/src/components/utils/sampleCards.js b/src/components/utils/sampleCards.js index 8899fe9e..15944114 100644 --- a/src/components/utils/sampleCards.js +++ b/src/components/utils/sampleCards.js @@ -18,6 +18,7 @@ import drDollyImg from './cardfiles/drDollyCard.jpg' import belloImg from './cardfiles/bello.jpg' import timeDeviceImg from './cardfiles/timeDeviceCard.jpg' import sampleGradient from './cardfiles/sampleGradient.jpg' +import { Card, CardClass } from "@/model/Card"; export const sampleGradientImg = sampleGradient @@ -41,7 +42,7 @@ export const cardJpgs = { timeDeviceImg: timeDeviceImg } -export const sampleCard = R.merge(emptyCard, { +export const sampleCard = Card.from({ CardName: 'Sample Card', FlavourText: 'Whenever you play CrowdControl your happiness increases by 1.', abilities: [], @@ -62,97 +63,55 @@ export const sampleCard = R.merge(emptyCard, { Health: 5, Attack: 3 }) -export const daisyData = R.merge(emptyCard, { +export const daisyData = Card.from({ CardName: 'Saint Daisy, Triplet', FlavourText: 'ETB - Create a 1/1 pet for each human you control', - abilities: [], - Notes: '', type: 'Entity', Tags: ['HUMAN'], - tagDummy: '', - Class: { - Nature: false, - Culture: true, - Technology: false, - Mysticism: true, - - }, + Class: CardClass.culture(), CastingCost: 7, Health: 3, Attack: 3 }) -export const daisyPetData = R.merge(emptyCard, { +export const daisyPetData = Card.from({ CardName: 'Saint Daisy, Triplet', FlavourText: 'PET', - abilities: [], - Notes: '', type: 'Entity', Tags: ['PET'], - tagDummy: '', - Class: { - Nature: false, - Culture: true, - Technology: false, - Mysticism: true, - - }, + Class: CardClass.mysticism(), CastingCost: 7, Health: 1, Attack: 1 }) -export const richardData = R.merge(emptyCard, { +export const richardData = Card.from({ CardName: 'Richard, Bot Commander', FlavourText: 'When Richard is attacking, create a 1/1 Bot token that is also attacking. When Richard blocks, all Bots gain +0/+1.', - abilities: [], - Notes: '', type: 'Entity', Tags: ['TECHNOCRAT'], tagDummy: 'TECHNOCRAT', - Class: { - Nature: false, - Culture: true, - Technology: true, - Mysticism: false, - - }, + Class: CardClass.technology(), CastingCost: 7, Health: 8, Attack: 5 }) -export const richardBotData = R.merge(emptyCard, { +export const richardBotData = Card.from({ CardName: 'Richard, Bot Commander', FlavourText: 'BOT', - abilities: [], - Notes: '', type: 'Entity', Tags: ['TECHNOCRAT'], tagDummy: 'TECHNOCRAT', - Class: { - Nature: false, - Culture: true, - Technology: true, - Mysticism: false, - - }, + Class: CardClass.technology(), CastingCost: 7, Health: 1, Attack: 1 }) -export const hurrwigData = R.merge(emptyCard, { +export const hurrwigData = Card.from({ CardName: 'Hurrwig, Bot Manufacturer', FlavourText: 'Whenever an entity with the tag \'Bot\' enters the battlefield, you may deal 2 damage to target entity.', - abilities: [], - Notes: '', type: 'Entity', Tags: ['TECHNOCRAT','HUMAN'], tagDummy: 'TECHNOCRAT', - Class: { - Nature: false, - Culture: true, - Technology: true, - Mysticism: false, - - }, + Class: CardClass.technology(), CastingCost: 8, Health: 5, Attack: 3 @@ -160,18 +119,10 @@ export const hurrwigData = R.merge(emptyCard, { export const assoultHorseData = R.merge(emptyCard, { CardName: 'Assoult Horse', FlavourText: 'Charge!', - abilities: [], - Notes: '', type: 'Entity', Tags: ['BOT'], tagDummy: 'BOT', - Class: { - Nature: false, - Culture: false, - Technology: true, - Mysticism: false, - - }, + Class: CardClass.technology(), CastingCost: 3, Health: 3, Attack: 2 diff --git a/src/model/Card.js b/src/model/Card.js new file mode 100644 index 00000000..0a2574db --- /dev/null +++ b/src/model/Card.js @@ -0,0 +1,117 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.CardClass = exports.Card = exports.ChainCard = void 0; +const Coin_1 = require("./Coin"); +class ChainCard { + static from(json) { + return Object.assign(new ChainCard(), json); + } + toCard() { + let card = new Card(); + if (this.content) { + let content = JSON.parse(this.content); + let cardType = Object.keys(content)[0]; + card.CardName = content[cardType].CardName; + card.FlavourText = content[cardType].FlavourText; + card.Tags = content[cardType].Tags; + card.Class = Object.assign(new CardClass(), content[cardType].Class); + card.CastingCost = parseInt(content[cardType].CastingCost); + card.Abilities = content[cardType].Abilities; + card.AdditionalCost = content[cardType].AdditionalCost; + card.Health = parseInt(content[cardType].Health); + card.Attack = parseInt(content[cardType].Attack); + card.Delay = parseInt(content[cardType].Delay); + card.RulesTexts = content[cardType].RulesTexts; + card.Keywords = []; + content[cardType].Keywords.forEach(keyword => { + card.Keywords.push(JSON.parse(keyword)); + }); + card.type = cardType; + card.owner = this.owner; + card.status = this.status; + card.artist = this.artist; + card.Content = content; + card.image = this.image; + card.fullArt = this.fullArt; + card.nerflevel = parseInt(this.nerflevel); + card.notes = this.notes; + card.fairEnoughVotes = parseInt(this.fairEnoughVotes); + card.inappropriateVotes = parseInt(this.inappropriateVotes); + card.overpoweredVotes = parseInt(this.overpoweredVotes); + card.underpoweredVotes = parseInt(this.underpoweredVotes); + card.votePool = Object.assign(new Coin_1.Coin(), this.votePool); + card.voters = this.voters; + console.log("parsed card: ", card); + } + return card; + } +} +exports.ChainCard = ChainCard; +class Card { + constructor() { + this.notes = ""; + this.type = ""; + this.owner = ""; + this.status = ""; + this.artist = ""; + this.Content = {}; + this.image = ""; + this.voters = []; + this.tagDummy = ""; + this.fullArt = true; + this.nerflevel = 0; + this.fairEnoughVotes = 0; + this.inappropriateVotes = 0; + this.overpoweredVotes = 0; + this.underpoweredVotes = 0; + this.votePool = new Coin_1.Coin(); + this.Abilities = []; + this.CardName = ""; + this.FlavourText = ""; + this.Tags = []; + this.Class = new CardClass(); + this.CastingCost = -1; + this.AdditionalCost = {}; + this.Health = 0; + this.Attack = 0; + this.Delay = 0; + this.RulesTexts = []; + this.Keywords = []; + } + static from(json) { + return Object.assign(new ChainCard(), json); + } +} +exports.Card = Card; +class CardClass { + constructor(type) { + this.Culture = false; + this.Mysticism = false; + this.Technology = false; + this.Nature = false; + if (type) { + this[type] = true; + } + } + static culture() { + let obj = new CardClass(); + obj.Culture = true; + return obj; + } + static mysticism() { + let obj = new CardClass(); + obj.Mysticism = true; + return obj; + } + static technology() { + let obj = new CardClass(); + obj.Technology = true; + return obj; + } + static nature() { + let obj = new CardClass(); + obj.Nature = true; + return obj; + } +} +exports.CardClass = CardClass; diff --git a/src/model/Card.ts b/src/model/Card.ts new file mode 100644 index 00000000..00d810a2 --- /dev/null +++ b/src/model/Card.ts @@ -0,0 +1,138 @@ +import { Coin } from "./Coin"; + +export class ChainCard { + owner: string; + status: string; + artist: string; + content: string; + image: string; + fullArt: boolean; + nerflevel: string; + notes: string; + fairEnoughVotes: string; + inappropriateVotes: string; + overpoweredVotes: string; + underpoweredVotes: string; + votePool: Coin; + voters: Array; + + static from(json) { + return Object.assign(new ChainCard(), json); + } + + toCard(): Card { + let card = new Card(); + if (this.content) { + let content = JSON.parse(this.content); + let cardType = Object.keys(content)[0]; + + card.CardName = content[cardType].CardName; + card.FlavourText = content[cardType].FlavourText; + card.Tags = content[cardType].Tags; + card.Class = Object.assign(new CardClass(), content[cardType].Class); + card.CastingCost = parseInt(content[cardType].CastingCost); + card.Abilities = content[cardType].Abilities; + card.AdditionalCost = content[cardType].AdditionalCost; + card.Health = parseInt(content[cardType].Health); + card.Attack = parseInt(content[cardType].Attack); + card.Delay = parseInt(content[cardType].Delay); + card.RulesTexts = content[cardType].RulesTexts; + card.Keywords = []; + content[cardType].Keywords.forEach(keyword => { + card.Keywords.push(JSON.parse(keyword)); + }); + + card.type = cardType; + card.owner = this.owner; + card.status = this.status; + card.artist = this.artist; + card.Content = content; + card.image = this.image; + card.fullArt = this.fullArt; + card.nerflevel = parseInt(this.nerflevel); + card.notes = this.notes; + card.fairEnoughVotes = parseInt(this.fairEnoughVotes); + card.inappropriateVotes = parseInt(this.inappropriateVotes); + card.overpoweredVotes = parseInt(this.overpoweredVotes); + card.underpoweredVotes = parseInt(this.underpoweredVotes); + card.votePool = Object.assign(new Coin(), this.votePool); + card.voters = this.voters; + + console.log("parsed card: ", card); + } + return card; + } +} + +export class Card { + notes: string = ""; + type: string = ""; + owner: string = ""; + status: string = ""; + artist: string = ""; + Content: any = {}; + image: string = ""; + voters: Array = []; + tagDummy: string = ""; + fullArt: boolean = true; + nerflevel: number = 0; + fairEnoughVotes: number = 0; + inappropriateVotes: number = 0; + overpoweredVotes: number = 0; + underpoweredVotes: number = 0; + votePool: Coin = new Coin(); + + Abilities: Array = []; + CardName: string = ""; + FlavourText: string = ""; + Tags: Array = []; + Class: CardClass = new CardClass(); + CastingCost: number = -1; + AdditionalCost: any = {}; + Health: number = 0; + Attack: number = 0; + Delay: number = 0; + RulesTexts: Array = []; + Keywords: Array> = []; + + static from(json) { + return Object.assign(new ChainCard(), json); + } +} + +export class CardClass { + Culture: boolean = false; + Mysticism: boolean = false; + Technology: boolean = false; + Nature: boolean = false; + + constructor(type?: string) { + if (type) { + this[type] = true; + } + } + + static culture() { + let obj = new CardClass(); + obj.Culture = true; + return obj; + } + + static mysticism() { + let obj = new CardClass(); + obj.Mysticism = true; + return obj; + } + + static technology() { + let obj = new CardClass(); + obj.Technology = true; + return obj; + } + + static nature() { + let obj = new CardClass(); + obj.Nature = true; + return obj; + } +} diff --git a/src/model/Coin.js b/src/model/Coin.js new file mode 100644 index 00000000..2e326d9a --- /dev/null +++ b/src/model/Coin.js @@ -0,0 +1,20 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.Coin = void 0; +class Coin { + constructor(denom = "ucredits", amount = 0) { + this.denom = denom; + this.amount = amount; + } + normalize() { + if (this.denom[0] == "u") { + this.denom = this.denom.slice(1); + this.amount /= 10 ** 6; + } + return this; + } + pretty() { + return this.amount + this.denom; + } +} +exports.Coin = Coin; diff --git a/src/model/Coin.ts b/src/model/Coin.ts new file mode 100644 index 00000000..4273c71b --- /dev/null +++ b/src/model/Coin.ts @@ -0,0 +1,21 @@ +export class Coin { + denom: string; + amount: number; + + constructor(denom: string = "ucredits", amount: number = 0) { + this.denom = denom; + this.amount = amount; + } + + normalize() { + if (this.denom[0] == "u") { + this.denom = this.denom.slice(1); + this.amount /= 10 ** 6; + } + return this; + } + + pretty() { + return this.amount + this.denom; + } +} \ No newline at end of file diff --git a/src/plugins/cardChain.js b/src/plugins/cardChain.js index 7bba41ee..37e220b7 100644 --- a/src/plugins/cardChain.js +++ b/src/plugins/cardChain.js @@ -6,6 +6,7 @@ import { entropyToMnemonic } from 'bip39' // import { Coin } from "../store/generated/cosmos/cosmos-sdk/cosmos.bank.v1beta1/module/types/cosmos/base/v1beta1/coin.js" import { creditsFromCoins, emptyCard } from '../components/utils/utils.js' import {GenericAuthorization} from "../store/generated/cosmos/cosmos-sdk/cosmos.authz.v1beta1/module/types/cosmos/authz/v1beta1/authz.js" +import { Card, ChainCard } from "@/model/Card"; //import {Any} from "../store/generated/cosmos/cosmos-sdk/cosmos.authz.v1beta1/module/types/google/protobuf/any.js" export default { @@ -90,51 +91,6 @@ export default { }) } } - useFaucet() { - this.vue.notifyInfo('Faucet', 'Get Credits from Faucet') - return new Promise((resolve, reject) => { - this.txQueue.enqueue(() => { - return this.vue.$http.post( - process.env.VUE_APP_FAUCET, - { - address: this.vue.$store.getters['common/wallet/address'], - coins: ['0ubpf', '5000ucredits'], - }, - { - headers: { 'Content-Type': 'application/x-www-form-urlencoded' }, - } - ) - .then((res) => { - resolve(res) - }) - .catch(reject) - }) - }) - - } - cardObjectToWebModel (rawCard) { - if (rawCard.content) { - let contentLens = R.lensProp('Content') - let parseContent = item => R.set(contentLens, JSON.parse(item.content), item) - let card = R.merge(emptyCard, parseContent(rawCard)) - let cardType = R.keys(card.Content) - card = R.merge(card, card.Content[cardType[0]]) - - card.nerflevel = parseInt(card.nerflevel) - card.type = cardType[0] - - card.RulesTexts = card.RulesTexts ? card.RulesTexts : [] - card.Keywords = card.Keywords ? R.map(JSON.parse, card.Keywords) : [] - - if (rawCard.fullArt && !R.isNil(rawCard.fullArt)) - card.fullArt = JSON.parse(rawCard.fullArt) - - console.log('parsed card: ', card) - return card - } else { - return emptyCard - } - } cardWebModelToCardobject (webModel, cardImageUrl) { console.log('trying to parse ', webModel) let cardContent = { @@ -398,7 +354,8 @@ export default { this.vue.notifyFail('WTF', 'A card was looked up that does not exist in the blockchain.') throw new Error('Card with ' + cardId + ' does not exist.') } else { - return res.data + //console.log(res.data) + return ChainCard.from(res.data).toCard() } }) handleGetCouncil = R.curry((res, id) => { diff --git a/src/store/generated/DecentralCardGame/Cardchain/DecentralCardGame.cardchain.cardchain/index.js b/src/store/generated/DecentralCardGame/Cardchain/DecentralCardGame.cardchain.cardchain/index.js index 6569bb85..11de016b 100644 --- a/src/store/generated/DecentralCardGame/Cardchain/DecentralCardGame.cardchain.cardchain/index.js +++ b/src/store/generated/DecentralCardGame/Cardchain/DecentralCardGame.cardchain.cardchain/index.js @@ -562,7 +562,7 @@ exports.default = { const txClient = await initTxClient(rootGetters); const msg = await txClient.msgAddArtwork(value); const result = await txClient.signAndBroadcast([msg], { fee: { amount: fee, - gas: "200000000" }, memo }); + gas: "20000000" }, memo }); return result; } catch (e) { diff --git a/src/store/generated/DecentralCardGame/Cardchain/DecentralCardGame.cardchain.cardchain/module/index.js b/src/store/generated/DecentralCardGame/Cardchain/DecentralCardGame.cardchain.cardchain/module/index.js index 1d0b87a1..44a1de79 100644 --- a/src/store/generated/DecentralCardGame/Cardchain/DecentralCardGame.cardchain.cardchain/module/index.js +++ b/src/store/generated/DecentralCardGame/Cardchain/DecentralCardGame.cardchain.cardchain/module/index.js @@ -81,7 +81,6 @@ const defaultFee = { amount: [], gas: "200000", }; -var sequenceInfo = {} const txClient = async (wallet, { addr: addr } = { addr: "http://localhost:26657" }) => { if (!wallet) throw exports.MissingWalletError; @@ -94,43 +93,7 @@ const txClient = async (wallet, { addr: addr } = { addr: "http://localhost:26657 } const { address } = (await wallet.getAccounts())[0]; return { - signAndBroadcast: (msgs, { fee, memo } = { fee: defaultFee, memo: "" }) => { - // code injection to get sequence fast firing working - client.getSequence = async function (address) { - const height = await this.getHeight() - const account = await this.getAccount(address); - - if (!account) { - throw new Error("Account does not exist on chain. Send some tokens there before trying to query sequence."); - } - - // if sequence info is not yet defined, do it here - if (!sequenceInfo.height) { - sequenceInfo = { - height: height, - sequence: account.sequence - } - } - // if the sequence info is outdated, we update it - else if (sequenceInfo.height < height) { - // we don't update the sequence if it is from last block - // this fixes sequence error is tx got into new block and update would reset the sequence - if (sequenceInfo.height + 1 < height) { - sequenceInfo.sequence = account.sequence - } - sequenceInfo.height = height - } - - let returnSequence = sequenceInfo.sequence - sequenceInfo.sequence++ - - return { - accountNumber: account.accountNumber, - sequence: returnSequence, - }; - } - return client.signAndBroadcast(address, msgs, fee, memo) - }, + signAndBroadcast: (msgs, { fee, memo } = { fee: defaultFee, memo: "" }) => client.signAndBroadcast(address, msgs, fee, memo), msgApointMatchReporter: (data) => ({ typeUrl: "/DecentralCardGame.cardchain.cardchain.MsgApointMatchReporter", value: tx_1.MsgApointMatchReporter.fromPartial(data) }), msgSetProfileCard: (data) => ({ typeUrl: "/DecentralCardGame.cardchain.cardchain.MsgSetProfileCard", value: tx_2.MsgSetProfileCard.fromPartial(data) }), msgCreateuser: (data) => ({ typeUrl: "/DecentralCardGame.cardchain.cardchain.MsgCreateuser", value: tx_3.MsgCreateuser.fromPartial(data) }), diff --git a/src/utils/coins.js b/src/utils/coins.js deleted file mode 100644 index fa5d26ee..00000000 --- a/src/utils/coins.js +++ /dev/null @@ -1,18 +0,0 @@ -export class Coin { - constructor(coin) { - this.denom = coin.denom - this.amount = coin.amount - } - - nornalize() { - if (this.denom[0] === "u") { - this.denom = this.denom.slice(1) - this.amount /= 10**6 - } - return this - } - - pretty() { - return this.amount + this.denom - } -} \ No newline at end of file diff --git a/src/views/AdvancedCardViewPage.vue b/src/views/AdvancedCardViewPage.vue index e386873e..dd5b1efb 100644 --- a/src/views/AdvancedCardViewPage.vue +++ b/src/views/AdvancedCardViewPage.vue @@ -34,7 +34,7 @@

Advanced Card Information

- Votepool: {{ votePool }}
+ Votepool: {{ card.votePool.normalize().pretty() }}
Status: {{ card.status }}
Notes: {{ card.notes }}
Owner: @@ -116,7 +116,6 @@ import * as R from 'ramda' import CardComponent from '@/components/elements/CardComponent' import { sampleCard } from "@/components/utils/sampleCards" -import { Coin } from '@/utils/coins' import TransferCardModal from '@/components/modals/TransferCardModal.vue'; import KeywordComponent from '@/components/elements/KeywordComponent.vue'; @@ -130,7 +129,6 @@ export default { isOwner: false, canVote: false, card: sampleCard, - votePool: "", } }, watch: { @@ -145,17 +143,17 @@ export default { if (typeof this.id === 'number' && !isNaN(this.id)) { this.$cardChain.getCard(this.id) .then(res => { - let parsedCard = this.$cardChain.cardObjectToWebModel(res) + let parsedCard = res if (parsedCard) { this.card = parsedCard - this.votePool = new Coin(this.card.votePool).nornalize().pretty() if (this.$store.getters["getLoggedIn"]) { this.loadVotableCards() } } }) - .catch(_ => { + .catch(err => { + console.log(err) this.$router.push({name: "NotFound"}) }) } diff --git a/src/views/GalleryPage.vue b/src/views/GalleryPage.vue index d319ca32..dcf72bf6 100644 --- a/src/views/GalleryPage.vue +++ b/src/views/GalleryPage.vue @@ -341,8 +341,8 @@ export default { .then((res) => { let card = res card.id = cardId - if (card.content) { - let candidate = this.$cardChain.cardObjectToWebModel(card) + if (card.Content) { + let candidate = card this.cards.push(candidate) return candidate } else if (!card.owner) { diff --git a/src/views/UserView.vue b/src/views/UserView.vue index cea6308d..b745bff6 100644 --- a/src/views/UserView.vue +++ b/src/views/UserView.vue @@ -144,7 +144,7 @@ import TransferModal from '../components/modals/TransferModal.vue'; import ChoosePBModal from '../components/modals/ChoosePBModal.vue'; import GrantModal from '../components/modals/GrantModal.vue'; import AirdropsModal from '../components/modals/AirdropsModal.vue'; -import { Coin } from '@/utils/coins' +import { Coin } from '@/model/Coin' export default { name: 'UserView', diff --git a/src/views/VotingResultsPage.vue b/src/views/VotingResultsPage.vue index 7efc5b80..be428580 100644 --- a/src/views/VotingResultsPage.vue +++ b/src/views/VotingResultsPage.vue @@ -180,7 +180,7 @@ export default { let card = res card.id = cardId if (card.content) { - let candidate = this.$cardChain.cardObjectToWebModel(card) + let candidate = card candidate.isNerfed = this.cardList[this.cardList.length - 1 - this.pageId - currentId].result === 'nerf' candidate.isBuffed = this.cardList[this.cardList.length - 1 - this.pageId - currentId].result === 'buff' candidate.isBanned = this.cardList[this.cardList.length - 1 - this.pageId - currentId].result === 'ban'