From de463a28b8eb60975da1a349b3ba8a9a421bc457 Mon Sep 17 00:00:00 2001 From: Guillaume Meinesz <guillaume.meinesz@gmail.com> Date: Tue, 24 Oct 2023 10:17:12 +0200 Subject: [PATCH] =?UTF-8?q?fix=20ticket#=20+=20ce=20sont=20maintenant=20le?= =?UTF-8?q?s=20choix.id=20qui=20sont=20enregistr=C3=A9s=20dans=20le=20fich?= =?UTF-8?q?ier=20traces=20et=20s'il=20n'y=20a=20pas=20de=20choix.id,=20le?= =?UTF-8?q?=20choix.son?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/ChargementJSONStructure.cs | 26 ++++++++ Assets/GD_manager.cs | 98 +++++++++++++++++++++---------- Assets/QCM_manager.cs | 31 +++++++--- Assets/mainManager.cs | 29 ++++++--- 4 files changed, 136 insertions(+), 48 deletions(-) diff --git a/Assets/ChargementJSONStructure.cs b/Assets/ChargementJSONStructure.cs index 6387cbb3..55d280b5 100644 --- a/Assets/ChargementJSONStructure.cs +++ b/Assets/ChargementJSONStructure.cs @@ -78,6 +78,32 @@ public class ChargementJSONStructure : MonoBehaviour public List<Session> sessions; } + public bool checkifitemexists(string assetname, bool checkofimgpath) + { + if (data.assets.ContainsKey(assetname)) + { + if (checkofimgpath && data.assets[assetname].img_path != null) + { + Sprite image = Resources.Load<Sprite>(data.assets[assetname].img_path); + if(image != null) + { + return true; + } + + } + else if(data.assets[assetname].snd_path != null) + { + AudioClip aud = Resources.Load<AudioClip>(data.assets[assetname].snd_path); + if(aud != null) + { + return true; + } + + } + } + return false; + } + public void chargeJsonStructure() { // Chargement du fichier JSON depuis le dossier "Assets" diff --git a/Assets/GD_manager.cs b/Assets/GD_manager.cs index f3536b03..bf21d4b0 100644 --- a/Assets/GD_manager.cs +++ b/Assets/GD_manager.cs @@ -107,7 +107,7 @@ public class GD_manager : MonoBehaviour oneElementIsMoving.dropZOneWhereItsCurrentlyPlaced = currentLandingZoneRolledOver; currentLandingZoneRolledOver.elementgdActuellementOnIt = oneElementIsMoving; currentLandingZoneRolledOver.occupied = true; - if (currentLandingZoneRolledOver.choix.son == oneElementIsMoving.choix.son) + if ((currentLandingZoneRolledOver.choix.id != null && oneElementIsMoving.choix.id != null && currentLandingZoneRolledOver.choix.id == oneElementIsMoving.choix.id) || (currentLandingZoneRolledOver.choix.son!=null && oneElementIsMoving.choix.son!=null && currentLandingZoneRolledOver.choix.son == oneElementIsMoving.choix.son)) { // bonne réponse les sons sont les mêmes oneElementIsMoving.transform.localPosition = currentLandingZoneRolledOver.transform.localPosition; @@ -199,9 +199,16 @@ public class GD_manager : MonoBehaviour //Debug.Log("suite pas encore terminée et non reussie!"); } mM.playerTurn = false; - mM.user_choix = mM.c.son; + if(mM.c.id != null) + { + mM.user_choix = mM.c.id; + } + else if (mM.c.son != null) + { + mM.user_choix = mM.c.son; + } + - //Debug.Log("playSteps final GD"); mM.playSteps(); // on lance le feedback @@ -303,12 +310,11 @@ public class GD_manager : MonoBehaviour mM.list_choix_associed_with_prefabs = new List<groupemementChoixEtPrefabBoutonQCM>(); foreach (Choix ccc in mM.i.choix) { - if (ccc.son != null && ccc.son.Length > 0) + if (((ccc.id != null && ccc.id.Length > 0) || (ccc.son != null && ccc.son.Length > 0)) && mM.jsonStructureScript.checkifitemexists(ccc.image,true)) { groupemementChoixEtPrefabBoutonQCM q = new groupemementChoixEtPrefabBoutonQCM(); q.choix = ccc; mM.list_choix_associed_with_prefabs.Add(q); - } else { @@ -316,37 +322,48 @@ public class GD_manager : MonoBehaviour } } - if (mM.i.randomiser) - { - mM.list_choix_associed_with_prefabs.Sort((a, b) => UnityEngine.Random.Range(-1, 2)); - } - mM.posScript.CalculateAlignment(mM.list_choix_associed_with_prefabs); - int indexdropzone = 0; - int indexgdel = 0; - foreach (groupemementChoixEtPrefabBoutonQCM gcpq in mM.list_choix_associed_with_prefabs) + if (mM.list_choix_associed_with_prefabs.Count > 0) { - gcpq.boutonqcmAssocied = gcpq.elementGDAssocied = mM.posScript.placeImages(indexgdel, gcpq.choix).GetComponent<elementGD>(); - if (gcpq.choix.numZone > 0) + + if (mM.i.randomiser) { - gcpq.elementDropZoneAssocied = mM.posScript.placeImages(indexdropzone, gcpq.choix, true).GetComponent<dropZoneGD>(); - indexdropzone++; + mM.list_choix_associed_with_prefabs.Sort((a, b) => UnityEngine.Random.Range(-1, 2)); + } + mM.posScript.CalculateAlignment(mM.list_choix_associed_with_prefabs); + + int indexdropzone = 0; + int indexgdel = 0; + foreach (groupemementChoixEtPrefabBoutonQCM gcpq in mM.list_choix_associed_with_prefabs) + { + gcpq.boutonqcmAssocied = gcpq.elementGDAssocied = mM.posScript.placeImages(indexgdel, gcpq.choix).GetComponent<elementGD>(); + if (gcpq.choix.numZone > 0) + { + gcpq.elementDropZoneAssocied = mM.posScript.placeImages(indexdropzone, gcpq.choix, true).GetComponent<dropZoneGD>(); + indexdropzone++; + } + indexgdel++; + } + if (indexdropzone == 0) + { + enditemToBeLaunched = true; + // probleme, cet item est invalide car aucune dropzone ne peut etre placee + } + else + { + // c'est bon on continue + if (mM.i.type == "tuto") + { + mM.executeAsset(mM.i.toucherLesChoix, toucherLesChoix, false); // consigne de l'item (présent dans le déroulement) + } + else { playswitch = true; } } - indexgdel++; - } - if (indexdropzone == 0) - { - enditemToBeLaunched = true; - // probleme, cet item est invalide car aucune dropzone ne peut etre placee } else { - // c'est bon on continue - if (mM.i.type == "tuto") - { - mM.executeAsset(mM.i.toucherLesChoix, toucherLesChoix, false); // consigne de l'item (présent dans le déroulement) - } - else { playswitch = true; } + Debug.Log("GD error no image to display this item, lets go to the next one"); + + mM.current_step = 10; } break; case 4: // EXPLICATION (présent dans le déroulement) equivalent au step 5 dans item_gd @@ -360,7 +377,7 @@ public class GD_manager : MonoBehaviour { foreach (groupemementChoixEtPrefabBoutonQCM b2 in mM.list_choix_associed_with_prefabs) { - if (b2.elementGDAssocied != null && b2.choix.son == b.choix.son) + if (b2.elementGDAssocied != null && ((b2.choix.id!=null && b.choix.id !=null && b2.choix.id == b.choix.id) || (b2.choix.son!=null && b.choix.son!=null && b2.choix.son == b.choix.son))) { Debug.Log("mouvement commence"); StartCoroutine(b2.elementGDAssocied.GoingToDropZone(1.0f, b.trans.position, b2.choix.numZone, explanationGDDemoFinished)); @@ -397,7 +414,16 @@ public class GD_manager : MonoBehaviour mM.user_choixPossibles = new string[mM.i.choix.Count]; for (int indexi = 0; indexi < mM.i.choix.Count; indexi++) { - mM.user_choixPossibles[indexi] = mM.i.choix[indexi].son; + if (mM.i.choix[indexi].id != null) + { + mM.user_choixPossibles[indexi] = mM.i.choix[indexi].id; + + } + else if (mM.i.choix[indexi].son != null) + { + mM.user_choixPossibles[indexi] = mM.i.choix[indexi].son; + + } } if (mM.i.type == "tuto" && mM.i.miseEnAction != null && mM.i.miseEnAction.Length > 0) { mM.executeAsset(mM.i.miseEnAction, mM.playerturnnow, false); } @@ -444,7 +470,15 @@ public class GD_manager : MonoBehaviour { if (cc.elementDropZoneAssocied != null) { - mM.user_choix_ChoisiDansLordre[indexzone] = cc.choix.son; + if (cc.choix.id != null) + { + mM.user_choix_ChoisiDansLordre[indexzone] = cc.choix.id; + } + else if (cc.choix.son != null) + { + mM.user_choix_ChoisiDansLordre[indexzone] = cc.choix.son; + } + indexzone++; } } diff --git a/Assets/QCM_manager.cs b/Assets/QCM_manager.cs index 262e9d0e..291f8471 100644 --- a/Assets/QCM_manager.cs +++ b/Assets/QCM_manager.cs @@ -86,7 +86,7 @@ public class QCM_manager : MonoBehaviour mM.list_choix_associed_with_prefabs = new List<groupemementChoixEtPrefabBoutonQCM>(); foreach (Choix ccc in mM.i.choix) { - if (ccc.son != null && ccc.son.Length > 0) + if (((ccc.id != null && ccc.id.Length > 0) || (ccc.son != null && ccc.son.Length > 0))&& mM.jsonStructureScript.checkifitemexists(ccc.image,true)) { groupemementChoixEtPrefabBoutonQCM q = new groupemementChoixEtPrefabBoutonQCM(); q.choix = ccc; @@ -99,14 +99,21 @@ public class QCM_manager : MonoBehaviour } } - if (mM.i.randomiser) + + if(mM.list_choix_associed_with_prefabs.Count > 0) { - mM.list_choix_associed_with_prefabs.Sort((a, b) => UnityEngine.Random.Range(-1, 2)); + if (mM.i.randomiser) + { + mM.list_choix_associed_with_prefabs.Sort((a, b) => UnityEngine.Random.Range(-1, 2)); + } + mM.posScript.CalculateAlignment(mM.list_choix_associed_with_prefabs); + mM.instancieAndPlayCHoix(); + } + else + { + Debug.Log("QCM error no image to display this item, lets go to the next one"); + mM.current_step = 10; } - mM.posScript.CalculateAlignment(mM.list_choix_associed_with_prefabs); - mM.instancieAndPlayCHoix(); - - break; case 4: // EXPLICATION (présent dans le déroulement) if (mM.i.type == "tuto" && mM.i.explication != null && mM.i.explication.Length > 0) @@ -134,7 +141,15 @@ public class QCM_manager : MonoBehaviour mM.user_choixPossibles = new string[mM.i.choix.Count]; for (int indexi = 0; indexi < mM.i.choix.Count; indexi++) { - mM.user_choixPossibles[indexi] = mM.i.choix[indexi].son; + if (mM.i.choix[indexi].id != null) + { + mM.user_choixPossibles[indexi] = mM.i.choix[indexi].id; + + } + else if (mM.i.choix[indexi].son!=null) + { + mM.user_choixPossibles[indexi] = mM.i.choix[indexi].son; + } } if (mM.i.type == "tuto" && mM.i.miseEnAction != null && mM.i.miseEnAction.Length > 0) { mM.executeAsset(mM.i.miseEnAction, mM.playerturnnow,false); } diff --git a/Assets/mainManager.cs b/Assets/mainManager.cs index 57288e87..900d2eb0 100644 --- a/Assets/mainManager.cs +++ b/Assets/mainManager.cs @@ -119,6 +119,7 @@ public class mainManager : MonoBehaviour private ChargementJSONStructure.Asset checkAssetValidity(string id) { + Debug.Log("checkAssetValidity"); if (id != null && id.Length > 0) { ChargementJSONStructure.Asset a = returnA(id); @@ -132,6 +133,7 @@ public class mainManager : MonoBehaviour public bool executeAsset(string id, Action mafonction, bool img=false) { + Debug.Log("executeAsset " + id); bool anAssetSoundExists = false; if(id!=null && id.Length>0) { @@ -180,10 +182,19 @@ public class mainManager : MonoBehaviour public void flecheReadyDisplayed() { - playerTurn = true; - posScript.currentlyInstanciatedprefabImagePrincipale.gameObject.SetActive(true); - Debug.Log("flecheReadyDisplayed playerTurn=" + playerTurn); - // le son ready a bien été joué, on attends que le joueur clic sur la fleche ready. + if (posScript.currentlyInstanciatedprefabImagePrincipale != null) + { + playerTurn = true; + + // le son ready a bien été joué, on attends que le joueur clic sur la fleche ready. + + posScript.currentlyInstanciatedprefabImagePrincipale.gameObject.SetActive(true); + + } + else + { + flecheReadyBeenClicked(); + } } public void flecheReadyBeenClicked() { @@ -357,13 +368,14 @@ public class mainManager : MonoBehaviour else { groupemementChoixEtPrefabBoutonQCM groupe = list_choix_associed_with_prefabs[currentChoix]; + GameObject ggg = posScript.placeImages(currentChoix, groupe.choix); if (e.modalite == "GD") { - groupe.boutonqcmAssocied = groupe.elementGDAssocied = posScript.placeImages(currentChoix, groupe.choix).GetComponent<elementGD>(); + groupe.boutonqcmAssocied = groupe.elementGDAssocied = ggg.GetComponent<elementGD>(); } else { - boutonQCM b = posScript.placeImages(currentChoix, groupe.choix).GetComponent<boutonQCM>(); + boutonQCM b = ggg.GetComponent<boutonQCM>(); list_choix_associed_with_prefabs[currentChoix].boutonqcmAssocied = b; } @@ -379,11 +391,11 @@ public class mainManager : MonoBehaviour if (currentChoix == (list_choix_associed_with_prefabs.Count - 1)) { dernierChoixAudioclip = groupe.choix.son; - executeAsset(i.separateurChoix, lireDernierChoix,false); + executeAsset(i.separateurChoix, lireDernierChoix, false); } else { - executeAsset(groupe.choix.son, instancieAndPlayCHoix,false); + executeAsset(groupe.choix.son, instancieAndPlayCHoix, false); } } @@ -391,6 +403,7 @@ public class mainManager : MonoBehaviour { StartCoroutine(justWaitOneFrameBeforeLaunchingFunction(instancieAndPlayCHoix)); } + } else { -- GitLab