From f4d433e74e9990f6f96a5af0db93d28d18a42bdc Mon Sep 17 00:00:00 2001 From: Patrick Date: Fri, 14 Jun 2024 11:39:37 +0200 Subject: [PATCH 1/4] first fun of rulestext --- package-lock.json | 1 - package.json | 1 - src/components/elements/CardComponent.vue | 12 ++++++++++-- src/views/Discord.vue | 2 -- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/package-lock.json b/package-lock.json index edba94ac..ee7d3ef3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -33,7 +33,6 @@ "pinia": "^2.1.7", "process": "^0.11.10", "qrcode": "^1.5.3", - "query-string": "^9.0.0", "ramda": "^0.29.1", "vue": "^3.4.21", "vue-advanced-cropper": "^2.8.8", diff --git a/package.json b/package.json index f010bfc6..4170f93a 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,6 @@ "pinia": "^2.1.7", "process": "^0.11.10", "qrcode": "^1.5.3", - "query-string": "^9.0.0", "ramda": "^0.29.1", "vue": "^3.4.21", "vue-advanced-cropper": "^2.8.8", diff --git a/src/components/elements/CardComponent.vue b/src/components/elements/CardComponent.vue index 809bbe49..0f29b917 100644 --- a/src/components/elements/CardComponent.vue +++ b/src/components/elements/CardComponent.vue @@ -23214,9 +23214,8 @@ export default { }, methods: { update() { - //console.log("model", this.model.CardName, this.model) + console.log("cardcomponent model", this.model.CardName, this.model) this.FullArt = this.model.fullArt - //console.log("this.FullArt updated:", this.FullArt) let FullArtfilter = x => this.FullArt ? x : R.map(() => false, x) let EntityFullArtfilter = x => this.FullArt || cardType.Entity ? x : R.map(() => false, x) @@ -23321,6 +23320,7 @@ export default { this.attackFrame = cardType.Entity this.healthFrame = NonActionFilter(frameType) + this.generateRulesText() }, cardmouseleave() { if (this.hoverBehavior === 'none') return @@ -23385,6 +23385,14 @@ export default { getTags() { return this.model.Tags.join(' - ').toUpperCase() || '' }, + generateRulesText() { + console.log("this.model.abilities:", this.model.Abilities) + let rulesText = "" + this.model.Abilities.forEach(ability => { + rulesText = R.append(R.keys(ability), rulesText) + }) + console.log("rulestext:", rulesText) + }, abilitiesLength() { if (this.model.abilities) { if (R.isEmpty(this.model.abilities)) { diff --git a/src/views/Discord.vue b/src/views/Discord.vue index eaf02c9c..1931c904 100644 --- a/src/views/Discord.vue +++ b/src/views/Discord.vue @@ -129,8 +129,6 @@ import { CouncilStatus } from "decentralcardgame-cardchain-client-ts/DecentralCa import axios from "axios"; import { useUrlSearchParams } from '@vueuse/core' import { createReusableTemplate } from '@vueuse/core' -import queryString from 'query-string'; - const [DefineRewardItem, RewardItem] = createReusableTemplate(); From 3d27cbc8909a5b345394395595a06f2655da4a1d Mon Sep 17 00:00:00 2001 From: Patrick Date: Sun, 16 Jun 2024 21:38:58 +0200 Subject: [PATCH 2/4] implemented this funny stuff --- src/components/elements/CardComponent.vue | 108 ++++++++++++++++++++-- src/model/Card.ts | 3 +- 2 files changed, 102 insertions(+), 9 deletions(-) diff --git a/src/components/elements/CardComponent.vue b/src/components/elements/CardComponent.vue index 0f29b917..d40aea4a 100644 --- a/src/components/elements/CardComponent.vue +++ b/src/components/elements/CardComponent.vue @@ -23208,6 +23208,8 @@ export default { this.update() this.textVisible = false + this.model.RulesTexts = this.generateRulesText() + console.log("rulestext", this.model.RulesTexts) }, mounted() { this.textVisible = true @@ -23319,8 +23321,6 @@ export default { this.framed = colorType this.attackFrame = cardType.Entity this.healthFrame = NonActionFilter(frameType) - - this.generateRulesText() }, cardmouseleave() { if (this.hoverBehavior === 'none') return @@ -23386,12 +23386,106 @@ export default { return this.model.Tags.join(' - ').toUpperCase() || '' }, generateRulesText() { - console.log("this.model.abilities:", this.model.Abilities) + let deeper = element => { + if (typeof element === "object") + return element[R.keys(element)[0]] + else + return false + } + let decapital = x => { + return R.join("", R.over(R.lensIndex(0), R.toLower, x)) + } + let effectsToText = Effects => { + let effectText = [] + Effects.forEach(effect => { + let effectKeyword = R.keys(effect)[0] + let interaction = getInteractionText(effectKeyword) + + let interactionBlock = [] + interaction.forEach(element => { + if (R.includes("§", element)) { + let pure = R.join("", R.without(["§", "."], element)) + + let interactionNode = effect[effectKeyword][pure] + + if (getRule(pure)) { + if (getRule(pure).type == "interface") { + let picked = R.keys(interactionNode)[0] + interactionBlock.push(getRule(picked).interactionText) + } + else + console.log("pure interaction?", getInteractionText(pure)) + } + else { + let nextNode = deeper(interactionNode) + + if (nextNode) { + interactionBlock.push(nextNode) + } + else { + interactionBlock.push(interactionNode) + } + } + } + else + interactionBlock.push(element) + }) + effectText.push(R.join(" ", interactionBlock)) + }) + return effectText + } + + let rules = this.cardRules.definitions + let getRule = key => this.cardRules.definitions[decapital(key)] + let getInteractionText = key => R.split(" ", rules[decapital(key)].interactionText) + let rulesText = "" - this.model.Abilities.forEach(ability => { - rulesText = R.append(R.keys(ability), rulesText) - }) - console.log("rulestext:", rulesText) + if (this.model.AdditionalCost) { + let costType = R.keys(this.model.AdditionalCost)[0] + let amount = this.model.AdditionalCost[costType].Amount + let costText = "Extra Cost - " + costText += R.replace("§Amount", amount, rules.AdditionalCost.children[costType].interactionText) + if (costType === "SacrificeCost") + costText = R.replace("card", amount > 1 ? "Entities." : "Entity.", costText) + else + costText += amount > 1 ? "s." : "." + + rulesText = R.append(costText, rulesText) + } + if (this.model.Abilities) { + this.model.Abilities.forEach(ability => { + let keyword = R.keys(ability)[0] + let abilityText = getInteractionText(keyword) + + abilityText.forEach((block, index) => { + // Effects can be nested a bit, so this needs more handling + if (R.includes("§Effects", block)) { + let effectText = effectsToText(ability[keyword].Effects) + abilityText[index] = R.replace("§Effects", R.join(". ", effectText), abilityText[index]) + } + // Not effects, but something else that needs to be replaced with variable. + else if (R.includes("§", block)) { + let pure = R.join("", R.without(["§", ".", ":"], block)) + let node = ability[keyword][pure] + if (deeper(node)) { + abilityText[index] = R.replace("§"+pure, deeper(node), abilityText[index]) + } + else { + abilityText[index] = R.replace("§"+pure, node, abilityText[index]) + } + } + else { + console.log("block else", block) + } + }) + rulesText = R.append(R.join(" ", abilityText), rulesText) + }) + } + else { + let effecttext = effectsToText(this.model.Effects) + rulesText = R.append(R.join(". ", effecttext), rulesText) + } + return rulesText }, abilitiesLength() { if (this.model.abilities) { diff --git a/src/model/Card.ts b/src/model/Card.ts index 4d6ba902..57ab040e 100644 --- a/src/model/Card.ts +++ b/src/model/Card.ts @@ -39,7 +39,7 @@ export class ChainCard { card.Health = parseInt(content[cardType].Health); card.Attack = parseInt(content[cardType].Attack); card.Delay = parseInt(content[cardType].Delay); - card.RulesTexts = content[cardType].RulesTexts; + card.RulesTexts = []; card.Effects = content[cardType].Effects; card.Keywords = []; content[cardType].Keywords.forEach((keyword: string) => { @@ -143,7 +143,6 @@ export class Card { FlavourText: this.FlavourText, Class: this.Class, Keywords: [], - RulesTexts: this.RulesTexts, }); this.Keywords.forEach((keyword) => { cardContent.Keywords.push(JSON.stringify(keyword)); From 346b9242ae5aebf71caa04d8a3cad2f0c99da7c2 Mon Sep 17 00:00:00 2001 From: Patrick Wieth Date: Fri, 28 Jun 2024 12:36:00 +0200 Subject: [PATCH 3/4] Update src/components/elements/CardComponent.vue Co-authored-by: lxgr-linux <64218491+lxgr-linux@users.noreply.github.com> --- src/components/elements/CardComponent.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/elements/CardComponent.vue b/src/components/elements/CardComponent.vue index d40aea4a..ce67fc96 100644 --- a/src/components/elements/CardComponent.vue +++ b/src/components/elements/CardComponent.vue @@ -23439,7 +23439,7 @@ export default { let getRule = key => this.cardRules.definitions[decapital(key)] let getInteractionText = key => R.split(" ", rules[decapital(key)].interactionText) - let rulesText = "" + let rulesText = [] if (this.model.AdditionalCost) { let costType = R.keys(this.model.AdditionalCost)[0] let amount = this.model.AdditionalCost[costType].Amount From a00209380592bf5ab64731c2aa4f146598634f3e Mon Sep 17 00:00:00 2001 From: Patrick Date: Sat, 29 Jun 2024 00:02:45 +0200 Subject: [PATCH 4/4] fix keyword descriptions, update cardobject --- src/components/elements/CardComponent.vue | 50 +------- src/components/elements/KeywordComponent.vue | 53 ++++++-- src/components/modals/CardviewModal.vue | 4 +- src/def-composables/cardRules.json | 122 +++---------------- src/views/CardCreatorPage.vue | 1 + 5 files changed, 68 insertions(+), 162 deletions(-) diff --git a/src/components/elements/CardComponent.vue b/src/components/elements/CardComponent.vue index ce67fc96..fdbb0e4c 100644 --- a/src/components/elements/CardComponent.vue +++ b/src/components/elements/CardComponent.vue @@ -23195,28 +23195,15 @@ export default { } }, created() { - let firstLetterToLower = (string: String) => { - return string[0].toLowerCase() + string.substring(1) - } - this.model.Keywords.forEach((ability: Array) => { - ability.forEach((keyword: String) => { - this.keywordDescriptions = R.concat(this.keywordDescriptions, - keyword + " - " + this.cardRules.definitions[firstLetterToLower(keyword)].description + " \\n " - ) - }) - }) - this.update() this.textVisible = false this.model.RulesTexts = this.generateRulesText() - console.log("rulestext", this.model.RulesTexts) }, mounted() { this.textVisible = true }, methods: { update() { - console.log("cardcomponent model", this.model.CardName, this.model) this.FullArt = this.model.fullArt let FullArtfilter = x => this.FullArt ? x : R.map(() => false, x) @@ -23283,11 +23270,6 @@ export default { } } - //console.log("frameType", frameType) - //console.log("cardClass", cardClass) - //console.log("cardType", cardType) - //console.log("colorType", colorType) - // here begins the part where the components are activated this.Class = cardClass this.Classes = R.countBy(x => x === true)(R.values(this.model.Class)).true @@ -23296,9 +23278,6 @@ export default { this.SecondaryColor = R.last(classTrueKeys ? classTrueKeys : []) this.PrimaryColor = R.head(classTrueKeys ? classTrueKeys : []) - //console.log("primary color:", this.PrimaryColor) - //console.log("secondary color:", this.SecondaryColor) - this.OBG = (this.Classes === 2 && !cardType.HQ) ? cardClass : frameType this.GoldSquare = true this.Border = frameType @@ -23440,8 +23419,8 @@ export default { let getInteractionText = key => R.split(" ", rules[decapital(key)].interactionText) let rulesText = [] - if (this.model.AdditionalCost) { - let costType = R.keys(this.model.AdditionalCost)[0] + if (this.model.AdditionalCost && !R.isEmpty(this.model.AdditionalCost)) { + let costType = R.keys(this.model.AdditionalCost) let amount = this.model.AdditionalCost[costType].Amount let costText = "Extra Cost - " costText += R.replace("§Amount", amount, rules.AdditionalCost.children[costType].interactionText) @@ -23452,7 +23431,7 @@ export default { rulesText = R.append(costText, rulesText) } - if (this.model.Abilities) { + if (this.model.Abilities && !R.isEmpty(this.model.Abilities)) { this.model.Abilities.forEach(ability => { let keyword = R.keys(ability)[0] let abilityText = getInteractionText(keyword) @@ -23475,15 +23454,15 @@ export default { } } else { - console.log("block else", block) + //console.log("block else", block) } }) rulesText = R.append(R.join(" ", abilityText), rulesText) }) } else { - let effecttext = effectsToText(this.model.Effects) - rulesText = R.append(R.join(". ", effecttext), rulesText) + let effectText = effectsToText(this.model.Effects) + rulesText = R.append(R.join(". ", effectText), rulesText) } return rulesText }, @@ -23566,23 +23545,6 @@ export default { return colors[this.SecondaryColor] } }, - getKeywords() { - let additionalCostPseudoKeyword = [[]] - - if (this.model.AdditionalCost) { - if (this.model.AdditionalCost.SacrificeCost) { - additionalCostPseudoKeyword[0].push("Tribute") - } else if (this.model.AdditionalCost.DiscardCost) { - additionalCostPseudoKeyword[0].push("DiscardPay") - } else if (this.model.AdditionalCost.VoidCost) { - additionalCostPseudoKeyword[0].push("Dissolve") - } - } - - return additionalCostPseudoKeyword[0].length > 0 ? - R.concat(additionalCostPseudoKeyword, this.model.Keywords) : - this.model.Keywords - }, fontSize(rawText) { let text = R.type(rawText) === "String" ? rawText : R.join(" ", rawText) if (text.length < 100) diff --git a/src/components/elements/KeywordComponent.vue b/src/components/elements/KeywordComponent.vue index ee78d41b..f3c7fd50 100644 --- a/src/components/elements/KeywordComponent.vue +++ b/src/components/elements/KeywordComponent.vue @@ -17,15 +17,16 @@ import * as R from "ramda"; import { useCardsRules } from "@/def-composables/useCardRules"; import { onMounted, reactive, watch } from "vue"; +import { Card } from "@/model/Card"; const { rules } = useCardsRules(); const props = withDefaults( defineProps<{ - keywords: Array>; + card: Card; }>(), { - keywords: () => [], + card: new Card(), } ); @@ -38,21 +39,49 @@ const initialState: { const state = reactive(initialState); const init = () => { - state.keywordDescriptions = R.map( + let decapital = x => { + return R.join("", R.over(R.lensIndex(0), R.toLower, x)) + } + let getInteractionText = key => R.split(" ", rules.value.definitions[decapital(key)].interactionText) + + let card = props.card + let keywords = [] + if (card.AdditionalCost && !R.isEmpty(card.AdditionalCost)) { + let costType = R.keys(card.AdditionalCost)[0] + state.keywordDescriptions = [costType, + rules.value.definitions[costType].description] + } + if (card.Abilities) { + card.Abilities.forEach(ability => { + let keyword = R.keys(ability)[0] + keywords.push(keyword) + let abilityText = getInteractionText(keyword) + abilityText.forEach((block, index) => { + if (R.includes("§Effects", block)) { + ability[keyword].Effects.forEach(effect => { + keywords.push(R.keys(effect)[0]) + }) + } + }) + }) + } + if (card.Effects) { + card.Effects.forEach(effect => { + let effectKeyword = R.keys(effect)[0] + keywords.push(effectKeyword) + }) + } + keywords = R.uniq(R.flatten(keywords)) + + state.keywordDescriptions = R.prepend(state.keywordDescriptions, R.map( (keyword) => [ keyword, - rules.value.definitions[firstLetterToLower(keyword as String)] - .description, + rules.value.definitions[decapital(keyword)].description, ], - R.uniq(R.flatten(props.keywords)) - ); -}; - -const firstLetterToLower = (string: String) => { - return string[0].toLowerCase() + string.substring(1); + keywords)) }; watch(props, init); onMounted(init); - + \ No newline at end of file diff --git a/src/components/modals/CardviewModal.vue b/src/components/modals/CardviewModal.vue index 4b2d67ec..809ca4f4 100644 --- a/src/components/modals/CardviewModal.vue +++ b/src/components/modals/CardviewModal.vue @@ -56,7 +56,7 @@ Used Keywords


- +
props.id, checkAndLoadCard); const loadCard = async () => { - state.card = await getCard(props.id); + state.card = await getCard(props.id) }; const edit = () => { diff --git a/src/def-composables/cardRules.json b/src/def-composables/cardRules.json index b888f354..65a56932 100644 --- a/src/def-composables/cardRules.json +++ b/src/def-composables/cardRules.json @@ -201,23 +201,6 @@ "Z" ] }, - "Keyword":{ - "type":"string", - "name":"Keyword", - "max":10000 - }, - "Keywords":{ - "type":"array", - "name":"Keywords", - "description":"Add some Keywords", - "children":{ - "Keyword":{ - "$ref":"#/definitions/Keyword" - } - }, - "max":3, - "min":1 - }, "Mysticism":{ "type":"bool", "name":"Mysticism" @@ -264,22 +247,6 @@ "RARE" ] }, - "RulesText":{ - "type":"string", - "name":"Rules Text", - "max":1000 - }, - "RulesTexts":{ - "type":"array", - "name":"Rules Texts", - "description":"Add some Rules Texts", - "children":{ - "RulesText":{ - "$ref":"#/definitions/RulesText" - } - }, - "max":4 - }, "SacrificeCost":{ "type":"struct", "name":"Sacrifice Cost", @@ -458,12 +425,6 @@ "Tags":{ "$ref":"#/definitions/Tags" }, - "Keywords":{ - "$ref":"#/definitions/Keywords" - }, - "RulesTexts":{ - "$ref":"#/definitions/RulesTexts" - }, "Rarity":{ "$ref":"#/definitions/Rarity" } @@ -474,9 +435,7 @@ "Class", "Effects", "FlavourText", - "Tags", - "Keywords", - "RulesTexts" + "Tags" ], "interactionText":"§CardName §CastingCost §AdditionalCost §Class §Effects §FlavourText §Tags §Keywords §RulesTexts §Rarity" }, @@ -569,7 +528,7 @@ "children":{ }, - "interactionText":"X/X avatar" + "interactionText":"X/X Avatar" }, "avenge":{ "type":"struct", @@ -609,7 +568,7 @@ "classes":[ "NATURE" ], - "interactionText":"3/3 beast" + "interactionText":"3/3 Beast" }, "bot":{ "type":"struct", @@ -708,23 +667,19 @@ ], "interactionText":"Count §Tag." }, - "countForces":{ + "countDust":{ "type":"struct", - "name":"Count Forces", - "description":"Count your Entities with Attack greater or equal to selected Attack and save this number to X.", + "name":"Count Dust", + "description":"Count all cards of a given type in your Dustpile.", "children":{ - "Power":{ - "$ref":"#/definitions/SimpleIntValue" + "CardType":{ + "$ref":"#/definitions/CardType" } }, "classes":[ - "CULTURE", - "NATURE" - ], - "required":[ - "Power" + "MYSTICISM" ], - "interactionText":"Count Forces §Power." + "interactionText":"Count §CardType." }, "countPower":{ "type":"struct", @@ -746,20 +701,6 @@ ], "interactionText":"CountPower of §Target." }, - "dice":{ - "type":"struct", - "name":"Dice", - "description":"Set X to a random number.", - "children":{ - "Amount":{ - "$ref":"#/definitions/IntValue" - } - }, - "required":[ - "Amount" - ], - "interactionText":"Dice §Amount." - }, "discard":{ "type":"struct", "name":"Discard", @@ -953,15 +894,12 @@ "Count":{ "$ref":"#/definitions/count" }, - "CountForces":{ - "$ref":"#/definitions/countForces" + "CountDust":{ + "$ref":"#/definitions/countDust" }, "CountPower":{ "$ref":"#/definitions/countPower" }, - "Dice":{ - "$ref":"#/definitions/dice" - }, "Discard":{ "$ref":"#/definitions/discard" }, @@ -1072,7 +1010,7 @@ "$ref":"#/definitions/effect" } }, - "max":3 + "max":8 }, "enrage":{ "type":"struct", @@ -1120,12 +1058,6 @@ "Tags":{ "$ref":"#/definitions/Tags" }, - "Keywords":{ - "$ref":"#/definitions/Keywords" - }, - "RulesTexts":{ - "$ref":"#/definitions/RulesTexts" - }, "Rarity":{ "$ref":"#/definitions/Rarity" } @@ -1138,9 +1070,7 @@ "Attack", "Health", "FlavourText", - "Tags", - "Keywords", - "RulesTexts" + "Tags" ], "interactionText":"§CardName §CastingCost §AdditionalCost §Class §Abilities §Attack §Health §FlavourText §Tags §Keywords §RulesTexts §Rarity" }, @@ -1277,12 +1207,6 @@ "Tags":{ "$ref":"#/definitions/Tags" }, - "Keywords":{ - "$ref":"#/definitions/Keywords" - }, - "RulesTexts":{ - "$ref":"#/definitions/RulesTexts" - }, "Rarity":{ "$ref":"#/definitions/Rarity" } @@ -1294,9 +1218,7 @@ "Abilities", "Health", "FlavourText", - "Tags", - "Keywords", - "RulesTexts" + "Tags" ], "interactionText":"§CardName §Class §Delay §Abilities §Health §Growth §StartingHandSize §Wisdom §FlavourText §Tags §Keywords §RulesTexts §Rarity" }, @@ -1513,12 +1435,6 @@ "Tags":{ "$ref":"#/definitions/Tags" }, - "Keywords":{ - "$ref":"#/definitions/Keywords" - }, - "RulesTexts":{ - "$ref":"#/definitions/RulesTexts" - }, "Rarity":{ "$ref":"#/definitions/Rarity" } @@ -1530,9 +1446,7 @@ "Abilities", "Health", "FlavourText", - "Tags", - "Keywords", - "RulesTexts" + "Tags" ], "interactionText":"§CardName §CastingCost §AdditionalCost §Class §Abilities §Health §FlavourText §Tags §Keywords §RulesTexts §Rarity" }, @@ -1737,7 +1651,7 @@ "classes":[ "MYSTICISM" ], - "interactionText":"1/1 spirit" + "interactionText":"1/1 Spirit" }, "strengthen":{ "type":"struct", @@ -1752,7 +1666,7 @@ } }, "classes":[ - "CULTURE", + "MYSTICISM", "NATURE" ], "types":[ diff --git a/src/views/CardCreatorPage.vue b/src/views/CardCreatorPage.vue index 666fb882..e0565655 100644 --- a/src/views/CardCreatorPage.vue +++ b/src/views/CardCreatorPage.vue @@ -1303,6 +1303,7 @@ export default { } console.log("abilities after update", this.abilities); + // keep in mind this works for action cards, because effects are temporarily stored in this.abilities let keywordCount = R.length( R.flatten(R.pluck("keywords", this.abilities)), );