X-Git-Url: https://git.auder.net/variants/Baroque/current/gitweb.js?a=blobdiff_plain;f=public%2Fjavascripts%2Fcomponents%2Frules.js;h=1a597878b8d8dbe25bea004cb371834153511f83;hb=1b61a94dbd13f6a37a89e62216615d2496c760a2;hp=fd05d44defd62f80646d22453678544653d93cfd;hpb=9234226104764b91df9d677fb360ad538b98510c;p=vchess.git
diff --git a/public/javascripts/components/rules.js b/public/javascripts/components/rules.js
index fd05d44d..1a597878 100644
--- a/public/javascripts/components/rules.js
+++ b/public/javascripts/components/rules.js
@@ -3,69 +3,30 @@ Vue.component('my-rules', {
data: function() {
return { content: "" };
},
- template: `
`,
+ template: `
+
+ `,
mounted: function() {
// AJAX request to get rules content (plain text, HTML)
- let xhr = new XMLHttpRequest();
- let self = this;
- xhr.onreadystatechange = function() {
- if (this.readyState == 4 && this.status == 200)
- {
- let replaceByDiag = (match, p1, p2) => { return self.drawDiag(p2); };
- self.content = xhr.responseText.replace(/(fen:)([^:]*):/g, replaceByDiag);
- }
- };
- xhr.open("GET", "/rules/" + variant, true);
- xhr.setRequestHeader('X-Requested-With', "XMLHttpRequest");
- xhr.send();
+ ajax("/rules/" + variant, "GET", response => {
+ let replaceByDiag = (match, p1, p2) => {
+ const args = this.parseFen(p2);
+ return getDiagram(args);
+ };
+ this.content = response.replace(/(fen:)([^:]*):/g, replaceByDiag);
+ });
},
methods: {
- drawDiag: function(fen) {
- let [sizeX,sizeY] = VariantRules.size;
- let fenParts = fen.split(" ");
- // Obtain array of pieces images names
- let board = VariantRules.GetBoard(fenParts[0]);
- let orientation = "w";
- if (fenParts.length >= 2)
- orientation = fenParts[1];
- let markArray = [];
- if (fenParts.length >= 3)
- {
- let marks_str = fenParts[2];
- // Turn (human) marks into coordinates
- markArray = doubleArray(sizeX, sizeY, false);
- let marks = marks_str.split(",");
- for (let i=0; i=0 && i";
- for (let j=startY; j>=0 && j";
- if (markArray.length>0 && markArray[i][j])
- boardDiv += "
";
- if (board[i][j] != VariantRules.EMPTY)
- {
- boardDiv += "
";
- }
- boardDiv += "";
- }
- boardDiv += "";
- }
- return boardDiv;
+ parseFen(fen) {
+ const fenParts = fen.split(" ");
+ return {
+ position: fenParts[0],
+ marks: fenParts[1],
+ orientation: fenParts[2],
+ shadow: fenParts[3],
+ };
},
},
})