var editId=0; var counter=0; var pawnsRotationStorage=[]; var pdfPage; $( function() { $("#OpenMenuSideBar, #headerMenuCloseButton").click(function(event) { event.preventDefault(); $("#nav").toggleClass("openedSideMenu"); }); }); String.prototype.replaceAll = function(search, replacement) { var target = this; return target.replace(new RegExp(search, 'g'), replacement); }; function deleteScenario(id) { if(confirm("Etes vous sur de vouloir supprimer ce scénario?")) { //location.href="index.php?my=1&del="+id; fillListScenarios(id,listParams.pageNr); } } function addHeroes(type,target,nr) { if ($('#heroSelector_'+nr).length==0){ var htmlToAppend='
'; htmlToAppend+='edit_page_hero : '; htmlToAppend+='
'; htmlToAppend+=' edit_page_equipped_with '; htmlToAppend+=' edit_page_and $'; htmlToAppend+=' edit_page_and '; htmlToAppend+=' edit_page_and '; htmlToAppend+='
'; htmlToAppend+='
edit_page_spells '; htmlToAppend+=' '; htmlToAppend+=' edit_page_and '; htmlToAppend+=' edit_page_and '; htmlToAppend+=' edit_page_and '; htmlToAppend+='
'; htmlToAppend+='
edit_page_notes :
'; htmlToAppend+='

'; $(target).append(htmlToAppend); } } function addLeaderHealth(id,img,health,name) { if(!$( '#leaderHealth_'+id ).length) { var htmlToAppend='
' htmlToAppend+='
scripts_boss_start_hp_1 scripts_boss_start_hp_2
'; htmlToAppend+='
'; htmlToAppend+='
'; htmlToAppend+='edit_page_equipped_with edit_page_and edit_page_and edit_page_and '; htmlToAppend+='
'; htmlToAppend+='
'; htmlToAppend+='edit_page_spells edit_page_and edit_page_and edit_page_and '; htmlToAppend+='
'; htmlToAppend+='
edit_page_notes :
'; htmlToAppend+='
'; htmlToAppend+="" htmlToAppend+="
" $("#leadersHealth").append(htmlToAppend); } } function addEventsToList(title,description) { if(editId==0) { var newId="event_"+counter; $("#eventsListUl").append("
  • "+title+" : "+description+"
  • "); counter++; } else { $("#"+editId+" .eventTitle").html($('#eventTitleField').val()); $("#"+editId+" .eventDesc").html(description); editId=0; } $('#eventTitleField').val(""); //$('#eventTextField').val(""); tinyMCE.get('eventTextField').setContent(""); return false } function addRulesToList(title,description,mapId) { if(editId==0) { var newId="rule_"+counter; $("#rulesListUl").append("
  • "+title+" : "+description+"
  • "); counter++; } else { $("#"+editId+" .ruleTitle").html($('#ruleTitleField').val()); $("#"+editId+" .ruleDesc").html(description); $("#"+editId).attr('data-map-id','-1'); editId=0; } $("#ruleTitleField").val(""); tinyMCE.get('ruleTextField').setContent(""); return false; } function setNumberOfHeroes(number) { $(".heroSelector, .toHide_1, .toHide_2, #overlordToHide").hide(); var tabHeroesNbr=number.split("-"); var i=0; $("#heroSelector_0").show(); while(i<(tabHeroesNbr[0])) { $("#heroSelector_"+i).show(); i++; } if(tabHeroesNbr.length>1) { console.log(tabHeroesNbr[1]+" "+i); $(".toHide_1 span").html(tabHeroesNbr[0]); $(".toHide_2 span").html(tabHeroesNbr[1]); $(".toHide_1, .toHide_2").show(); $("#heroSelector_7").show(); $("#overlordToHide").show(); } } function changeMap(id,img,init) { var newWidth=$("#Map_"+id).attr("data-map-width")+"px";; var newHeight=$("#Map_"+id).attr("data-map-height")+"px"; $("#mapImg").css("background","url('images/plans/editor/"+img+"') no-repeat"); $("#mapImg").css("background-size","100% 100%"); $("#containment-wrapper").attr("current-map-id",id); $("#containment-wrapper").attr("current-map-img",img); /*if (window.matchMedia('(max-width: 950px)').matches) { $("#mapChoice .descriptionHeaderPart3").click(); $("#mapEdition .descriptionHeaderPart3").click(); var ratio=$("#mapEditionBlock").width()/$("#Map_"+id).attr("data-map-width"); newWidth=$("#mapEditionBlock").width()+"px"; newHeight=($("#Map_"+id).attr("data-map-height")*ratio)+"px"; console.log(newHeight+" "+newWidth+" "+ratio); }*/ $("#containment-wrapper").css("width",newWidth); $("#containment-wrapper").css("height",newHeight); $("#mapImg").css("width",newWidth); $("#mapImg").css("height",newHeight); $("#mapDescriptionHeaderForClick").click(); $("#rulesListUl li[data-map-id!='-1']").remove(); if(!init) { $( "mapRules[data-default-rule-map-id='"+id+"']" ).each(function(index, el) { addRulesToList($(this).attr('data-default-rule-title'),$(this).attr('data-default-rule-description'),id); }); } } function getPawnsList() { var pawnsList=new Array(); $(".pawn").each(function() { var pawn=new Object(); var pawnPos=$(this).position(); var wrapperPos=$("#containment-wrapper").position(); pawn.rotationAngle=pawnsRotationStorage[$(this).attr("id")]; pawn.img=$(this).attr('pawn-img'); pawn.circleColor=$(this).attr('pawn-color'); pawn.rotation=$(this).attr('pawn-rotation'); pawn.posTop=pawnPos.top; pawn.posLeft=pawnPos.left; pawn.id=$(this).attr('pawn-id'); pawn.width=$(this).attr('pawn-width'); pawn.height=$(this).attr('pawn-height'); console.log(pawn); pawnsList.push(pawn); }); return pawnsList; } function getRiverList() { var riverList=new Array(); $(".riverItem").each(function(index, el) { var riverItem=new Object(); riverItem.id=$(this).attr("tile-id"); riverItem.isHurt=$(this).attr("tile-is-hurt"); riverItem.color=$(this).attr("tile-color"); riverItem.img=$(this).attr("tile-img"); riverItem.type=$(this).attr("tile-type"); riverItem.name=$(this).attr("item-name"); riverList.push(riverItem); }); return riverList; } function griddraggReset(contener){ $(".griddragg" ).draggable({ grid: [ 10, 10 ], containment: contener, scroll: false , handle: ".pawnHandle"}); } function addPawn(contener,id,img,posTop,posLeft,pawnWidth, pawnHeight, color,rotation,rotationAngle) { var colorDiv=""; if(color!="") colorDiv="
    "; var newId="pawnOnMap_"+id+"_"+counter; var rotationLink=""; if(rotation==1) rotationLink=""; $(contener).append("
    "+colorDiv+"
    "+rotationLink+"
    "); $("#pawnOnMap_"+id+"_"+counter).css("top",posTop); $("#pawnOnMap_"+id+"_"+counter).css("left",posLeft); if(rotationAngle!=0) { rotate(newId,rotationAngle); } counter++; } function rotate(target,angle) { if(isNaN(pawnsRotationStorage[target])) pawnsRotationStorage[target]=0; pawnsRotationStorage[target]+=angle; $("#"+target+" #divPawnImage").css({'transform' : 'rotate('+ pawnsRotationStorage[target]+'deg)'}); } function removeSomething(id) { $("#"+id).remove(); isTooMuchChar("descriptionTextarea"); isTooMuchChar("eventTextField"); isTooMuchChar("ruleTextField"); } function editSomething(id,type) { $('#'+type+'TitleField').val(br2nl (displayBBcode($("#"+id+" ."+type+"Title").html()))); //$('#'+type+'TextField').val(br2nl (displayBBcode($("#"+id+" ."+type+"Desc").html()))); tinyMCE.get(type+'TextField').setContent($("#"+id+" ."+type+"Desc").html()); editId=id; } function addTile(contener,id,img,type,name,color,fromSave,hurt) { var hurtLayer=""; var isHurt=0; if(hurt) { hurtLayer="
    "; isHurt=1; } var colorDiv=hurtLayer; if(color!="") colorDiv="
    "+hurtLayer+"
    "; console.log($(".riverItem").size()); if($(".riverItem").size()<8) { var newId="tileInRiver_"+id+"_"+counter; $(contener).append("
    "+colorDiv+"
    "); if(type=="Leaders"&&!fromSave) { var img=$(".pawnsItem[pawn-id="+id+"]").attr("pawn-img"); addLeaderHealth(id,img,1,name); } counter++; } } function saveMission(callBack,createPdf) { if(createPdf) { $(".darkClass").show(); } if (window.matchMedia('(max-width: 950px)').matches) { $( "#main" ).accordion( "option", "active", 2 ); } var jsonString=getJsonText(); console.log(jsonString); var data={createPdf:createPdf,JsonText:jsonString,MissionId:$("#MissionId").val(),Title:$("#title").val(),Difficulty:$("#difficulty").val(),PlayersNbr:$("#playersNbr").val(),Displayed:$("#displayed").val(),Language:$("#scenarioLanguage").val()}; var random=Math.random() * (0 - 10000000) + 10000000; var jqxhr = $.post( "msaver.php?rand="+random, data) .done(function(data) { //alert(data.indexOf("ERROR")); if(data.indexOf("ERROR") >= 0) { if(data.indexOf("NOUSERID") >= 0) { displayLogin(null,function(){saveMission(null,true);}); } else { console.log(data); alert("Error 1!"); $(".darkClass").hide(); } } else { console.log( "save finished" ); console.log(data); $("#MissionId").val(data); if(callBack!=null) callBack(); $(".darkClass").hide(); } }) .fail(function() { console.log( "save error" ); }) .always(function() { console.log( "save finished (always???)" ); }); } function loadMission(missionId) { console.log("load mission begin"); var data={MissionId:missionId}; var jqxhr = $.post( "mloader.php", data) .done(function(data) { console.log( data ); if(data.indexOf("ERROR") >= 0) { alert("Error 2!"); console.log(data); } else { fillMission(data); } }) .fail(function() { console.log( "load error" ); }) .always(function() { console.log( "load finished" ); }); } function fillMission(JsonContent) { var JsonObj=JSON.parse(JsonContent); console.log(JsonObj); $("#signature").val(JsonObj.signature); if(JsonObj.language==null) { $("#scenarioLanguage").val("fr"); } else { $("#scenarioLanguage").val(JsonObj.language); } $("#playersNbr").val(JsonObj.playersNbr); setNumberOfHeroes($("#playersNbr").val()); $("#difficulty").val(JsonObj.difficulty); $("#title").val(JsonObj.title); console.log("JsonObj.displayed "+JsonObj.displayed); $("#displayed").val(JsonObj.displayed); /*if(JsonObj.displayed==1) { $("#displayed").prop('checked', true); }*/ tinyMCE.get('descriptionTextarea').settings.init_instance_callback = function(editor) { tinyMCE.get('descriptionTextarea').setContent(JsonObj.description); }; tinyMCE.get('heroesObjectives').settings.init_instance_callback = function(editor) { tinyMCE.get('heroesObjectives').setContent(JsonObj.heroesObjectives); }; tinyMCE.get('overlordObjectives').settings.init_instance_callback = function(editor) { tinyMCE.get('overlordObjectives').setContent(JsonObj.overlordObjectives); }; //JsonObj.description=JsonObj.description.replaceAll("
    ","\n"); tinyMCE.get('descriptionTextarea').setContent(JsonObj.description); tinyMCE.get('heroesObjectives').setContent(JsonObj.heroesObjectives); tinyMCE.get('overlordObjectives').setContent(JsonObj.overlordObjectives); $("#startingPlayer").val(JsonObj.startingPlayer); $("#heroGemFatigue").val(JsonObj.heroGemFatigue); var overLordGems1=JsonObj.overLordGems[0]; var overLordGems2=JsonObj.overLordGems[1]; $("#overlordGemDispo_1").val(overLordGems1.overlordGemDispo); $("#overlordGemFatigue_1").val(overLordGems1.overlordGemFatigue); $("#overlordGemRecup_1").val(overLordGems1.overlordGemRecup); $("#overlordGemDispo_2").val(overLordGems2.overlordGemDispo); $("#overlordGemFatigue_2").val(overLordGems2.overlordGemFatigue); $("#overlordGemRecup_2").val(overLordGems2.overlordGemRecup); var map=JsonObj.map; changeMap(map.Id,map.Img,true); var leaders=JsonObj.leaders; for(var i=0;i'; text = text.split(val.bbcode).join(imageTag); console.log(text); }); return text; } function displayBBcode(text) { $.each( JsonPictosData.Pictos, function( key, val ) { $("body").append("
    "+text+"
    "); $("#tmpBB").find('.pictos_'+val.pictoId).replaceWith(val.bbcode); text=$("#tmpBB").html(); $("#tmpBB").remove(); }); return text; } function nl2br(str) { str = str.split("\n").join("
    "); return str; } function br2nl (str) { str = str.split("
    ").join("\n"); return str; } function stripSlashes(str) { str=str.replace(new RegExp("\\\\", "g"), ""); console.log("stripSlashes : "+str); return str; } function displaySpinner() { $(".darkClass").show(); $("#subandlogBlock").hide(); $("#imgSpinner").show(); } function ratings(missionId,setRating,type,rating, targetId) { var data={MissionId:missionId,SetRating:setRating,Type:type,Rating:rating}; var jqxhr = $.post( "inc/_ratings.php", data) .done(function(data) { console.log( data ); if(data.indexOf("ERROR") >= 0) { if(data.indexOf("NOUSERID") >= 0) { $(".darkClass").show(); displayLogin(null,function(){ ratings(missionId,true,type,rating); }); } else { alert("Error!"); console.log(data); $(".darkClass").hide(); } } else { var JsonObj=JSON.parse(data); console.log(JsonObj.total); if(targetId==null) { $("#TotalRating").barrating('destroy'); $("#Fun").barrating('destroy'); $("#Equilibre").barrating('destroy'); $("#Rejouabilite").barrating('destroy'); $("#Originalite").barrating('destroy'); $("#ratingContener").show(); /*if(JsonObj.total>0) { $("#ratingContener").show(); $("#novote").hide(); } else { $("#novote").show(); $("#ratingContener").hide(); }*/ $('#totalTextValue').html(JsonObj.total); $('#funTextValue').html(JsonObj.fun); $('#equilibreTextValue').html(JsonObj.equilibre); $('#rejouabiliteTextValue').html(JsonObj.rejouabilite); $('#originaliteTextValue').html(JsonObj.originalite); $("#nrVotes").html("("+JsonObj.nrVotes+" vote"); if(JsonObj.nrVotes>1) { $("#nrVotes").append("s"); } $("#nrVotes").append(")"); createRatings(JsonObj,missionId); } else { $("#totalTextValue_"+targetId).html(JsonObj.total); $("#TotalRating_"+targetId).barrating({ theme: 'fontawesome-stars-o', readonly: true, initialRating:JsonObj.total }); $("#ratingContener_"+targetId).show(); $("#novote_"+targetId).hide(); $("#nrVotes_"+targetId).html("("+JsonObj.nrVotes+" vote"); if(JsonObj.nrVotes>1) { $("#nrVotes_"+targetId).append("s"); } $("#nrVotes_"+targetId).append(")"); /*if(JsonObj.total>0) { $("#totalTextValue_"+targetId).html(JsonObj.total); $("#TotalRating_"+targetId).barrating({ theme: 'fontawesome-stars-o', readonly: true, initialRating:JsonObj.total }); $("#ratingContener_"+targetId).show(); $("#novote_"+targetId).hide(); $("#nrVotes_"+targetId).html("("+JsonObj.nrVotes+" vote"); if(JsonObj.nrVotes>1) { $("#nrVotes_"+targetId).append("s"); } $("#nrVotes_"+targetId).append(")"); } else { $("#novote_"+targetId).show(); $("#ratingContener_"+targetId).hide(); }*/ } } }) .fail(function() { console.log( "load error" ); }) .always(function() { console.log( "ratings finished" ); }); } function createRatings(JsonObj,missionId) { $('#TotalRating').barrating({ theme: 'fontawesome-stars-o', readonly: true, initialRating:JsonObj.total }); $('#Fun').barrating({ theme: 'fontawesome-stars-o', initialRating:JsonObj.fun, onSelect: function(value, text, event) { if (typeof(event) !== 'undefined') { var type="Fun" // rating was selected by a user ratings(missionId,true,type,value); } else { // rating was selected programmatically // by calling `set` method } } }); $('#Equilibre').barrating({ theme: 'fontawesome-stars-o', initialRating:JsonObj.equilibre, onSelect: function(value, text, event) { if (typeof(event) !== 'undefined') { var type="Equilibre" // rating was selected by a user ratings(missionId,true,type,value); } else { // rating was selected programmatically // by calling `set` method } } }); $('#Rejouabilite').barrating({ theme: 'fontawesome-stars-o', initialRating:JsonObj.rejouabilite, onSelect: function(value, text, event) { if (typeof(event) !== 'undefined') { var type="Rejouabilite" // rating was selected by a user ratings(missionId,true,type,value); } else { // rating was selected programmatically // by calling `set` method } } }); $('#Originalite').barrating({ theme: 'fontawesome-stars-o', initialRating:JsonObj.originalite, onSelect: function(value, text, event) { if (typeof(event) !== 'undefined') { var type="Originalite" // rating was selected by a user ratings(missionId,true,type,value); } else { // rating was selected programmatically // by calling `set` method } } }); } function displayAsList(asList) { var reload=false; if(localStorage.getItem('asList')!==null&&JSON.parse(localStorage.getItem('asList'))!=asList) { reload=true; } if(asList) { $("#listScenarios").addClass("listFormat"); } else { $("#listScenarios").removeClass("listFormat"); } localStorage.setItem('asList', asList); if(reload) fillListScenarios("",0); } function CountCharacters(id) { console.log("count! "+id); var body = tinymce.get(id).getBody(); var content = tinymce.trim(body.innerText || body.textContent); return content.length; } function isTooMuchChar(targetId) { var messageTmp=""; var maxCharTmp=0; if(targetId=="descriptionTextarea") { countChar = CountCharacters(targetId); maxCharTmp=maxCharDesc; messageTmp=" edit_page_how_much_char"; } else if(targetId=="eventTextField"||targetId=="ruleTextField") { countChar=0; var countTarget=""; if(targetId=="eventTextField") { countTarget=$(".eventsLi"); maxCharTmp=maxCharEvent; messageTmp=" edit_page_how_much_char_event"; } if(targetId=="ruleTextField") { countTarget=$(".rulesLi"); maxCharTmp=maxCharRules; messageTmp=" edit_page_how_much_char_rules"; } var countCharTmp=0; countTarget.each(function(index, el) { countCharTmp+=$(this).text().length; }); countChar=(CountCharacters(targetId)+countCharTmp); } $("#"+targetId+"_charCount").css({"color":"black", "font-weight":"none"}); $("#"+targetId+"_charCount").html(countChar+"/"+maxCharTmp+messageTmp); if(countChar>maxCharTmp) { $("#"+targetId+"_charCount").css({"color":"red", "font-weight":"bold"}); $("#"+targetId+"_charCount").html(countChar+"/"+maxCharTmp+messageTmp+" edit_page_too_much_char"); } } function verifcontactForm() { $("#contactErrorMsg").hide(); var error=0; $(".contactMandatory").each(function(index, val) { $(this).css("background-color","#000000"); if($(this).val()=="") { $(this).css("background-color","#c90000"); error=1; } }); if(error==1) { $("#contactErrorMsg").show(); return false; } else { return true; } }