mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-04-27 07:48:01 -07:00
Webatrice: card import wizard (#4397)
This commit is contained in:
parent
dde0f568d9
commit
36e5a399d5
41 changed files with 1479 additions and 35 deletions
93
webclient/src/types/cards.ts
Normal file
93
webclient/src/types/cards.ts
Normal file
|
|
@ -0,0 +1,93 @@
|
|||
export class Card {
|
||||
artist: string;
|
||||
availability: string[];
|
||||
borderColor: string;
|
||||
colorIdentity: string[];
|
||||
colors: string[];
|
||||
convertedManaCost: number;
|
||||
edhrecRank: number;
|
||||
flavorText: string;
|
||||
identifiers: {
|
||||
cardKingdomId: string;
|
||||
mcmId: string;
|
||||
mcmMetaId: string;
|
||||
mtgjsonV4Id: string;
|
||||
multiverseId: string;
|
||||
scryfallId: string;
|
||||
scryfallIllustrationId: string;
|
||||
scryfallOracleId: string;
|
||||
tcgplayerProductId: string;
|
||||
};
|
||||
isOnlineOnly: boolean;
|
||||
layout: string;
|
||||
legalities: {
|
||||
brawl: string;
|
||||
commander: string;
|
||||
duel: string;
|
||||
future: string;
|
||||
gladiator: string;
|
||||
historic: string;
|
||||
legacy: string;
|
||||
modern: string;
|
||||
pauper: string;
|
||||
penny: string;
|
||||
pioneer: string;
|
||||
premodern: string;
|
||||
standard: string;
|
||||
vintage: string;
|
||||
};
|
||||
manaCost: string;
|
||||
name: string;
|
||||
originalText: string;
|
||||
originalType: string;
|
||||
power: string;
|
||||
printings: string[];
|
||||
rarity: string;
|
||||
rulings: {
|
||||
date: string;
|
||||
text: string;
|
||||
}[];
|
||||
side: string;
|
||||
setCode: string;
|
||||
subtypes: string[];
|
||||
supertypes: string[];
|
||||
text: string;
|
||||
toughness: string;
|
||||
type: string;
|
||||
types: string[];
|
||||
uuid: string;
|
||||
variations: string[];
|
||||
}
|
||||
|
||||
export class Set {
|
||||
baseSetSize: number;
|
||||
block: string;
|
||||
cards: string[];
|
||||
code: string;
|
||||
isOnlineOnly: boolean;
|
||||
name: string;
|
||||
releaseDate: string;
|
||||
totalSetSize: number;
|
||||
type: string;
|
||||
}
|
||||
|
||||
export class Token {
|
||||
name: { value: string };
|
||||
prop: {
|
||||
value: {
|
||||
cmc: { value: string; };
|
||||
colors: { value: string; };
|
||||
maintype: { value: string; };
|
||||
pt: { value: string; };
|
||||
type: { value: string; };
|
||||
};
|
||||
};
|
||||
related: { value: string; }[];
|
||||
'reverse-related': { value: string; }[];
|
||||
set: {
|
||||
value: string;
|
||||
picURL: string;
|
||||
}[];
|
||||
tablerow: { value: string; };
|
||||
text: { value: string; };
|
||||
}
|
||||
84
webclient/src/types/constants.spec.ts
Normal file
84
webclient/src/types/constants.spec.ts
Normal file
|
|
@ -0,0 +1,84 @@
|
|||
import {
|
||||
URL_REGEX,
|
||||
MESSAGE_SENDER_REGEX,
|
||||
MENTION_REGEX,
|
||||
CARD_CALLOUT_REGEX,
|
||||
CALLOUT_BOUNDARY_REGEX,
|
||||
} from './constants';
|
||||
|
||||
describe('RegEx', () => {
|
||||
describe('URL_REGEX', () => {
|
||||
it('should match and capture whole url in main capture group', () => {
|
||||
const test = [
|
||||
'http://example.com',
|
||||
'https://example.com',
|
||||
'https://www.example.com',
|
||||
];
|
||||
|
||||
test.forEach(str => {
|
||||
const match = str.match(URL_REGEX);
|
||||
|
||||
expect(match).toBeDefined();
|
||||
expect(match[0]).toBe(str);
|
||||
});
|
||||
});
|
||||
|
||||
it('should not match bad urls', () => {
|
||||
const test = [
|
||||
'htt://example.com',
|
||||
'https:/example.com',
|
||||
'https//www.example.com',
|
||||
'www.example.com',
|
||||
'example.com',
|
||||
];
|
||||
|
||||
test.forEach(str =>
|
||||
expect(str.match(URL_REGEX)).toBe(null)
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('MESSAGE_SENDER_REGEX', () => {
|
||||
it('should match and capture sender name in second capture group', () => {
|
||||
const sender = 'sender';
|
||||
const match = `${sender}: message`.match(MESSAGE_SENDER_REGEX);
|
||||
|
||||
expect(match).toBeDefined();
|
||||
expect(match[1]).toBe(sender);
|
||||
});
|
||||
|
||||
it('should not match if spaces before :', () => {
|
||||
const test = [
|
||||
' sender: message',
|
||||
'sender : message',
|
||||
' sender : message',
|
||||
];
|
||||
|
||||
test.forEach(str =>
|
||||
expect(str.match(URL_REGEX)).toBe(null)
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('MENTION_REGEX', () => {
|
||||
it('should match and capture user mentions in second capture group', () => {
|
||||
expect('@mention'.match(MENTION_REGEX)[0]).toBe('@mention');
|
||||
expect('@mention '.match(MENTION_REGEX)[0]).toBe('@mention');
|
||||
expect(' @mention'.match(MENTION_REGEX)[0]).toBe(' @mention');
|
||||
expect(' @mention '.match(MENTION_REGEX)[0]).toBe(' @mention');
|
||||
expect('leading @mention'.match(MENTION_REGEX)[0]).toBe(' @mention');
|
||||
expect('leading @mention trailing'.match(MENTION_REGEX)[0]).toBe(' @mention');
|
||||
expect('@mention trailing'.match(MENTION_REGEX)[0]).toBe('@mention');
|
||||
});
|
||||
|
||||
it('should not match preceded by character', () => {
|
||||
const test = [
|
||||
'leading@mention',
|
||||
];
|
||||
|
||||
test.forEach(str =>
|
||||
expect(str.match(MENTION_REGEX)).toBe(null)
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
6
webclient/src/types/constants.ts
Normal file
6
webclient/src/types/constants.ts
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
// eslint-disable-next-line
|
||||
export const URL_REGEX = /(https?:\/\/(?:www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,4}\b(?:[-a-zA-Z0-9@:%_\+.~#?&//=]*))/g;
|
||||
export const MESSAGE_SENDER_REGEX = /(^[^:\s]+):/;
|
||||
export const MENTION_REGEX = /(^|\s)(@\w+)/g;
|
||||
export const CARD_CALLOUT_REGEX = /(\[\[[^\]]+\]\])/g;
|
||||
export const CALLOUT_BOUNDARY_REGEX = /(\[\[|\]\])/g;
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
export enum FormKey {
|
||||
ADD_TO_BUDDIES = "ADD_TO_BUDDIES",
|
||||
ADD_TO_IGNORE = "ADD_TO_IGNORE",
|
||||
CARD_IMPORT = "CARD_IMPORT",
|
||||
CONNECT = "CONNECT",
|
||||
REGISTER = "REGISTER",
|
||||
SEARCH_LOGS = "SEARCH_LOGS",
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
export * from "./cards";
|
||||
export * from "./constants";
|
||||
export * from "./game";
|
||||
export * from "./room";
|
||||
export * from "./server";
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ export enum KnownHost {
|
|||
}
|
||||
|
||||
export const KnownHosts = {
|
||||
[KnownHost.ROOSTER]: { port: 443, host: 'server.cockatrice.us', },
|
||||
[KnownHost.ROOSTER]: { port: 4748, host: 'server.cockatrice.us', },
|
||||
[KnownHost.TETRARCH]: { port: 443, host: 'mtg.tetrarch.co/servatrice'},
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue