function initConfig(ctx,config) { var obj = store.get(ctx, "Config",config._id); if(obj) config.value=obj.value; var obj = store.upsert(ctx, "Config", config); return obj; } // Fixures function setFixures() { var ctx = context.new(); // Migration var obj = store.get(ctx, "Config", "version"); console.log("Migration"); if(obj) { console.log(obj); } // Config console.log("Fixtures Config"); var obj = initConfig(ctx, {"_id": "version", "default": "0.0.0","visible":false}); // Card var obj = initCard(ctx, { _id: "lose10", image: "images/cards/loose10.png", title: "Hey ! t'avais pas un billet de 10 ?", description: "Vous perdez 10€", effect: "-10", sound: "looser" }); var obj = initCard(ctx, { _id: "lose20", image: "images/cards/loose20.png", title: "On t'as vu balancer ton papier dans la rue !", description: "Vous perdez 20€", effect: "-20", sound: "looser" }); var obj = initCard(ctx, { _id: "lose30", image: "images/cards/loose30.png", title: "T'as oublié l'anniversaire de ta mère !", description: "Vous perdez 30€", effect: "-30", sound: "looser" }); var obj = initCard(ctx, { _id: "brokenglass", image: "images/cards/borken-glass.png", title: "T'as deux mains gauches ? Attention les verres !", description: "Tu rembourses un verre cassé, valeur 10€", effect: "-10", sound: "looser" }); var obj = initCard(ctx, { _id: "lownight", image: "images/cards/lownight.png", title: "C'est mort ce soir ! Personne dans le rad !", description: "Tu perds 50€", effect: "-50", sound: "looser" }); var obj = initCard(ctx, { _id: "flood", image: "images/cards/flood.png", title: "Soirée piscine ! Enfin soirée plomberie surtout !", description: "Tu perds 40€", effect: "-40", sound: "looser" }); var obj = initCard(ctx, { _id: "robber", image: "images/cards/robber.png", title: "Il a tapé dans la caisse !", description: "On t'as volé 60€", effect: "-60", sound: "looser" }); var obj = initCard(ctx, { _id: "tomuch", image: "images/cards/tomuch.png", title: "Un p'tit dernier pour la route !", description: "Le verre de trop, amande de 80€", effect: "-80", sound: "looser" }); var obj = initCard(ctx, { _id: "somethingiswrong", image: "images/cards/somethingiswrong.png", title: "Tu ne sais pas rendre la monnaie !", description: "Tu rends 20€ de trop a un client chanceux !", effect: "-20", sound: "looser" }); var obj = initCard(ctx, { _id: "rebuild", image: "images/cards/rebuild.png", title: "On refait la déco !", description: "Rénove ton bar pour la modique somme de 50€", effect: "-50", sound: "looser" }); var obj = initCard(ctx, { _id: "shortage", image: "images/cards/shortage.png", title: "Dévalisé !", description: "Tu t'es fait dévaliser, plus rien en stock", effect: "100", sound: "winner" }); var obj = initCard(ctx, { _id: "luckyday", image: "images/cards/luckyday.png", title: "C'est un billet de 10 non ?", description: "Tu trouves 10€ devant ton bar", effect: "10", sound: "winner" }); var obj = initCard(ctx, { _id: "rushhour", image: "images/cards/rushhour.png", title: "C'est la folie dans ton bar !", description: "Tu gagnes 50€ !", effect: "50", sound: "winner" }); var obj = initCard(ctx, { _id: "blindtest", image: "images/cards/blindtest.png", title: "Tu gagnes la soirée blind test !", description: "Premier prix 20€ !", effect: "20", sound: "winner" }); var obj = initCard(ctx, { _id: "bigtip", image: "images/cards/bigtip.png", title: "Tes clients t'adores !", description: "20€ de pourboire !", effect: "20", sound: "winner" }); var obj = initCard(ctx, { _id: "baroftheweek", image: "images/cards/baroftheweek.png", title: "Tu gagnes le concours du bar de la semaine !", description: "Premier prix 50€ !", effect: "50", sound: "winner" }); var obj = initCard(ctx, { _id: "goodnight", image: "images/cards/goodnight.png", title: "On t'en a trop rendus !", description: "Tu gagnes 30€ !", effect: "30", sound: "winner" }); var obj = initCard(ctx, { _id: "yourdadishere", image: "images/cards/yourdadishere.png", title: "Ton père est là ! Paye une tournée de plus !", description: "Payer 30€ de plus !", effect: "-30", sound: "looser" }); var obj = initCard(ctx, { _id: "dontdrive", image: "images/cards/dontdrive.png", title: "Le ballon a dit non !", description: "Paye un taxi pour rentrer 10€ !", effect: "-10", sound: "looser" }); var obj = initCard(ctx, { _id: "flambeur", image: "images/cards/flambeur.png", title: "Tournée générale !", description: "Paye 60€ !", effect: "-60", sound: "looser" }); var obj = initCard(ctx, { _id: "cuteashell", image: "images/cards/cuteashell.png", title: "Tu es de toute beauté !", description: "On t'offres 40€ !", effect: "40", sound: "winner" }); var obj = initCard(ctx, { _id: "loseitall", image: "images/cards/loseitall.png", title: "Tu as oublié ton portefeuille !", description: "Tu perds 50€ !", effect: "-50", sound: "looser" }); // Tiletype var obj = initTiletype(ctx, { _id: "bar", description: "bar" }); var obj = initTiletype(ctx, { _id: "meetup", description: "Rencontre" }); var obj = initTiletype(ctx, { _id: "happyHour", description: "Happy Hour" }); var obj = initTiletype(ctx, { _id: "prison", description: "Cellule de dégrisement"}); var obj = initTiletype(ctx, { _id: "start", description: "Week-end"}); // Titlelevel var obj = initTilelevel(ctx, { _id: "pmu", order: 1, description: "PMU" }); var obj = initTilelevel(ctx, { _id: "bistro", order: 2, description: "Bistro de quartien"}); var obj = initTilelevel(ctx, { _id: "brasserie", order: 3, description: "Brasserie" }); var obj = initTilelevel(ctx, { _id: "barabiere", order: 4, description: "Bar à bières" }); var obj = initTilelevel(ctx, { _id: "baravin", order: 5, description: "Bar à vin" }); var obj = initTilelevel(ctx, { _id: "cocktails", order: 6, description: "Bar a cocktails" }); var obj = initTilelevel(ctx, { _id: "lounge", order: 7, description: "Lounge" }); var obj = initTilelevel(ctx, { _id: "clubprive", order: 8, description: "Club privé" }); // Case var obj = initTile(ctx, { _id: "st", position: 0, tiletype: "start", name: "Week-end", img: "https://static.actu.fr/uploads/2017/05/rue-de-la-soif-Rennes-960x640.jpg" }); var obj = initTile(ctx, { _id: "b1", position: 1, tiletype: "bar", name: "Les hirondelles", prixDeBase: "1", img: "https://media-cdn.tripadvisor.com/media/photo-s/08/99/ef/5a/les-hirondelles.jpg" }); var obj = initTile(ctx, { _id: "b2", position: 2, tiletype: "bar", name: "Le cheval blanc", prixDeBase: "1", img: "https://media-cdn.tripadvisor.com/media/photo-s/14/f4/ed/0f/le-cheval-blanc.jpg" }); var obj = initTile(ctx, { _id: "meetup1", position: 3, tiletype: "meetup", name: "Rencontre", img: "https://hoptodate.com/wp-content/uploads/2022/10/Depositphotos_331369428_XL-scaled.jpg" }); var obj = initTile(ctx, { _id: "b3", position: 4, tiletype: "bar", name: "L'ABC", prixDeBase: "2", img: "https://www.pagesjaunes.fr/media/agc/52/85/77/00/00/d1/00/ab/e8/ca/62bc5285770000d100abe8ca/62bc5285770000d100abe8cc.jpg" }); var obj = initTile(ctx, { _id: "b4", position: 5, tiletype: "bar", name: "La taverne", prixDeBase: "2", img: "https://www.clamecyhautnivernais-tourisme.fr/wp-content/uploads/wpetourisme/Bar-La-Taverne-Clamecy----D.Data-900x535.jpg" }); var obj = initTile(ctx, { _id: "hh1", position: 6, tiletype: "happyHour", name: "Happy hour", img: "https://blog.laddition.com/sites/default/files/2022-03/sans-titre-17_0.png" }); var obj = initTile(ctx, { _id: "b6", position: 7, tiletype: "bar", name: "La fine mousse", prixDeBase: "3", img: "https://cdn.eat-list.fr/establishment/photo/gallery_photo/75011-paris-11/la-fine-mousse_91615_c4c.jpg" }); var obj = initTile(ctx, { _id: "b7", position: 8, tiletype: "bar", name: "Le barboteur", prixDeBase: "3", img: "https://storage.googleapis.com/statics-wp/sites/lebarboteurlille.com/Le-Barboteur-0-1-1.jpg" }); var obj = initTile(ctx, { _id: "b7", position: 9, tiletype: "bar", name: "Le palais de la bière", prixDeBase: "3", img: "https://www.tourisme-pontaudemer-rislenormande.com/wp-content/uploads/2017/03/Palais-de-la-bi%C3%A8re.jpeg" }); var obj = initTile(ctx, { _id: "meetup2", position: 10, tiletype: "meetup", name: "Rencontre", img: "https://www.monpetitdate.fr/wp-content/uploads/2022/01/rencontre-trans-paris.jpg" }); var obj = initTile(ctx, { _id: "b8", position: 11, tiletype: "bar", name: "Le comptoir des bières", prixDeBase: "4", img: "https://lh3.googleusercontent.com/p/AF1QipPRj-YgeXsNxXjkpxill-QMSh20T9jeNl8OLcuj=s1600-w640" }); var obj = initTile(ctx, { _id: "b9", position: 12, tiletype: "bar", name: "Les moulins bleus", prixDeBase: "4", img: "https://www.brunnenbraeu.org/Alben2/MoulinsBleusDijon/album/slides/Les%20Moulins%20Bleus%20%E2%80%93%20Craft%20Beer%20and%20Food%20%281%29.jpg" }); var obj = initTile(ctx, { _id: "b10", position: 13, tiletype: "bar", name: "Le fourquet", prixDeBase: "4", img: "https://media-cdn.tripadvisor.com/media/photo-s/0c/ce/ca/87/le-fourquet.jpg" }); var obj = initTile(ctx, { _id: "prs", position: 14, tiletype: "prison", name: "Cellule de dégrisement", img: "https://lvdneng.rosselcdn.net/sites/default/files/dpistyles_v2/ena_16_9_extra_big/2022/09/05/node_1224621/55601340/public/2022/09/05/B9732002324Z.1_20220905182824_000%2BGBHL6LBT5.1-0.jpg?itok=UqmdxUiM1662450019" }); var obj = initTile(ctx, { _id: "b11", position: 15, tiletype: "bar", name: "Au beaux fûts", prixDeBase: "5", img: "https://because-gus.com/wp-content/uploads/2020/02/Bars-MaryRebeccaElliott.jpg" }); var obj = initTile(ctx, { _id: "b12", position: 16, tiletype: "bar", name: "Le Bacchus", prixDeBase: "5", img: "https://media-cdn.tripadvisor.com/media/photo-s/10/f6/a8/75/facade.jpg" }); var obj = initTile(ctx, { _id: "b13", position: 17, tiletype: "bar", name: "Matusalém", prixDeBase: "5", img: "https://foodforthought.com.my/wp-content/uploads/Franks-Bar-Matusalem-Rum-x-Franks-Food-For-Thought-1024x731.jpeg" }); var obj = initTile(ctx, { _id: "meetup3", position: 18, tiletype: "meetup", name: "Rencontre", img: "https://test.psychologies.com/var/tests/storage/images/2/3/3/1/11332-2-fre-FR/Test-pret-rencontre_thumb_434_265.jpg" }); var obj = initTile(ctx, { _id: "b14", position: 19, tiletype: "bar", name: "Bloody Marianne", prixDeBase: "6", img: "https://lh3.googleusercontent.com/p/AF1QipPAS0edvVXEiY7_ttg_wBIegJs1Nz2lxIXmqmr3=s1600-w640" }); var obj = initTile(ctx, { _id: "b15", position: 20, tiletype: "bar", name: "Shake it up", prixDeBase: "6", img: "https://images.barrons.com/im-839994?width=700&height=466" }); var obj = initTile(ctx, { _id: "b16", position: 21, tiletype: "bar", name: "Le mixologue", prixDeBase: "6", img: "https://www.ciga.fr/img/cms/le-mixologue/mise-en-situation-le-mixologue.jpg" }); var obj = initTile(ctx, { _id: "hh2", position: 22, tiletype: "happyHour", name: "Happy hour", img: "https://img.freepik.com/vecteurs-libre/fond-dessin-anime-happy-hours_52683-81243.jpg" }); var obj = initTile(ctx, { _id: "b17", position: 23, tiletype: "bar", name: "Le senateur", prixDeBase: "7", img: "https://media-cdn.tripadvisor.com/media/photo-s/0f/72/99/b4/montreal-marriott-chateau.jpg" }); var obj = initTile(ctx, { _id: "b18", position: 24, tiletype: "bar", name: "La dame blanche", prixDeBase: "7", img: "https://decibelles-data.media.tourinsoft.eu/upload/dame-jour.jpeg" }); var obj = initTile(ctx, { _id: "meetup4", position: 25, tiletype: "meetup", name: "Rencontre", img: "https://www.commeuncamion.com/content/uploads/2015/08/Rencontre-Couple-Bar.jpg" }); var obj = initTile(ctx, { _id: "b19", position: 26, tiletype: "bar", name: "Le Kube", prixDeBase: "8", img: "https://www.lesbarres.com/media/image/slideshow/726a6f8ea266c7c0cbb72cbc261d3520bf8f90df.jpg" }); var obj = initTile(ctx, { _id: "b20", position: 27, tiletype: "bar", name: "L'amirauté", prixDeBase: "8", img: "https://www.lamiraute-restaurant-saintes-maries-de-la-mer.com/media/cache/resolve/l800/websites/b510beeb640a5dc50a78118b3c8f7ce2/img/restaurant-amiraute-saintes-maries-de-la-mer-04_20210927172840.jpg" }); } // La fonction "onInit()" (si déclarée) est automatiquement // exécutée au démarrage du serveur de votre application. function onInit() { setFixures(); rpc.register("getAuthrole"); rpc.register("getAuthid"); rpc.register("getAuthpseudo"); rpc.register("getAuthisuser"), rpc.register("getConfigs"); rpc.register("getConfig"); rpc.register("upsertConfig"); rpc.register("getCard"); rpc.register("upsertCard"); rpc.register("initCard"); rpc.register("getTile"); rpc.register("getTilebyorder"); rpc.register("upsertTile"); rpc.register("initTile"); rpc.register("getTiletype"); rpc.register("upsertTiletype"); rpc.register("initTiletype"); rpc.register("getTilelevel"); rpc.register("upsertTilelevel"); rpc.register("initTilelevel"); rpc.register("getPartys"); rpc.register("getPartyswait"); rpc.register("getParty"); rpc.register("upsertParty"); rpc.register("deleteParty"); rpc.register("getPartyplayers"); rpc.register("getPlayer"); rpc.register("initPlayer"); rpc.register("upsertPlayer"); rpc.register("getPlayerParty"); rpc.register("upsertPlayerParty"); rpc.register("getPlayerPartyTile"); rpc.register("upsertlayerPartyTile"); } // Repository Auth async function getAuthrole(ctx,id) { var obj = await auth.getClaim(ctx, auth.CLAIM_ROLE); return obj; } async function getAuthid(ctx,id) { var obj = await auth.getClaim(ctx, auth.CLAIM_SUBJECT); if(!obj) { obj = await context.get(ctx, context.SESSION_ID); } return obj; } async function getAuthpseudo(ctx,id) { var obj = await auth.getClaim(ctx, auth.CLAIM_PREFERRED_USERNAME); if(!obj) { obj = await context.get(ctx, context.SESSION_ID); } return obj; } async function getAuthisuser(ctx,id) { var obj = await auth.getClaim(ctx, auth.CLAIM_ISSUER); if(!obj) { obj = false; } return obj; } // Repository Config async function getConfigs(ctx) { var obj = await store.query(ctx, "Config",{"eq":{ "visible": true }},); return obj; } async function getConfig(ctx,id) { var obj = await store.get(ctx, "Config",id); if(obj&&!obj.value) obj.value=obj.default; return obj; } async function upsertConfig(ctx,config) { var obj = await store.upsert(ctx, "Config", config); return obj; } // Repository Card async function getCard(ctx,id) { var obj = await store.get(ctx, "Card",id); if(obj&&!obj.value) obj.value=obj.default; return obj; } async function upsertCard(ctx,card) { var obj = await store.upsert(ctx, "Card", config); return obj; } function initCard(ctx,card) { var obj = store.get(ctx, "Card",card._id); if(obj) card.value=obj.value; var obj = store.upsert(ctx, "Card", card); return obj; } // Repository Tile async function getTile(ctx,id) { var obj = await store.get(ctx, "Tile",id); if(obj&&!obj.value) obj.value=obj.default; return obj; } async function getTilebyorder(ctx,position) { var obj = await store.query(ctx, "Tile",{"eq":{ "position": position }},); return obj[0]; } async function upsertTile(ctx,tile) { var obj = await store.upsert(ctx, "Tile", tile); return obj; } function initTile(ctx,tile) { var obj = store.get(ctx, "Tile",tile._id); if(obj) tile.value=obj.value; var obj = store.upsert(ctx, "Tile", tile); } // Repository TileType async function getTiletype(ctx,id) { var obj = await store.get(ctx, "Tiletype",id); if(obj&&!obj.value) obj.value=obj.default; return obj; } async function upsertTiletype(ctx,card) { var obj = await store.upsert(ctx, "Tiletype", config); return obj; } function initTiletype(ctx,tiletype) { var obj = store.get(ctx, "Tiletype",tiletype._id); if(obj) tiletype.value=obj.value; var obj = store.upsert(ctx, "Tiletype", tiletype); } // Repository Tilelevel async function getTilelevel(ctx,id) { var obj = await store.get(ctx, "Tilelevel",id); if(obj&&!obj.value) obj.value=obj.default; return obj; } async function upsertTilelevel(ctx,titlelevel) { var obj = await store.upsert(ctx, "Tilelevel", titlelevel); return obj; } function initTilelevel(ctx,tilelevel) { var obj = store.get(ctx, "Tilelevel",tilelevel._id); if(obj) tilelevel.value=obj.value; var obj = store.upsert(ctx, "Tilelevel", tilelevel); } // Repository Party async function getPartys(ctx) { var obj = await store.query(ctx, "Party"); return obj; } async function getPartyswait(ctx) { var obj = await store.query(ctx, "Party",{"eq":{ "status": "playerwait" }},); return obj; } async function getParty(ctx,id) { var obj = await store.get(ctx, "Party",id); if(obj&&!obj.value) obj.value=obj.default; return obj; } async function upsertParty(ctx,party) { var obj = await store.upsert(ctx, "Party", party); return obj; } async function deleteParty(ctx,id) { // Supprimer le media des Partyplayer var obj = await store.query(ctx, "Player", { "eq":{ "partyid": id }, }); obj.forEach(async(player) => { player.partyid=null; var obj = await store.upsert(ctx, "Player", player); }); // Supprimer le media var obj = await store.delete(ctx, "Party", id); return obj; } async function getPartyplayers(ctx,id) { var obj = await store.query(ctx, "Player",{"eq":{ "partyid": id }},); return obj; } // Repository Player async function getPlayer(ctx,id) { var obj = await store.get(ctx, "Player",id); if(obj&&!obj.value) obj.value=obj.default; return obj; } async function initPlayer(ctx,player) { if(!player.isuser) player.name=player.name.replace("Anon ",""); var obj = await store.get(ctx, "Player",player._id); if(!obj) obj = await store.upsert(ctx, "Player", player); return obj; } async function upsertPlayer(ctx,player) { var obj = await store.upsert(ctx, "Player", player); return obj; } // Repository PlayerParty async function getPlayerParty(ctx,ids) { var obj = await store.query(ctx, "PlayerParty", { "and": [ {"eq":{ "playerid": ids.playerid }}, {"eq":{ "partyid": ids.partyid }} ] } ); return obj[0]; } async function upsertPlayerParty(ctx,playerparty) { var obj = await store.upsert(ctx, "PlayerParty", playerparty); return obj; } // Repository PlayerPartyCase async function getPlayerPartyTile(ctx,ids) { var obj = await store.query(ctx, "PlayerPartyTile", { "and": [ {"eq":{ "playerid": ids.playerid }}, {"eq":{ "partyid": ids.partyid }}, {"eq":{ "tileid": ids.tileid }} ] } ); return obj[0]; } async function upsertPlayerPartyCase(ctx,playerpartycase) { var obj = await store.upsert(ctx, "PlayerPartyCase", playerpartycase); return obj; } // La fonction "onClientMessage(ctx, message)" est automatiquement // exécutée quand le serveur de votre application reçoit un // message en provenance du client. async function onClientMessage(ctx, message) { await net.broadcast(message); }