/// <summary> /// Convert a Moonsharp table to portrait options /// If the table returns a null for any of the parameters, it should keep the defaults /// </summary> /// <param name="table">Moonsharp Table</param> /// <param name="stage">Stage</param> /// <returns></returns> public static PortraitOptions ConvertTableToPortraitOptions(Table table, Stage stage) { PortraitOptions options = new PortraitOptions(true); // If the table supplies a nil, keep the default options.character = table.Get("character").ToObject <Character>() ?? options.character; options.replacedCharacter = table.Get("replacedCharacter").ToObject <Character>() ?? options.replacedCharacter; if (!table.Get("portrait").IsNil()) { options.portrait = options.character.GetPortrait(table.Get("portrait").CastToString()); } if (!table.Get("display").IsNil()) { options.display = table.Get("display").ToObject <DisplayType>(); } if (!table.Get("offset").IsNil()) { options.offset = table.Get("offset").ToObject <PositionOffset>(); } if (!table.Get("fromPosition").IsNil()) { options.fromPosition = stage.GetPosition(table.Get("fromPosition").CastToString()); } if (!table.Get("toPosition").IsNil()) { options.toPosition = stage.GetPosition(table.Get("toPosition").CastToString()); } if (!table.Get("facing").IsNil()) { options.facing = table.Get("facing").ToObject <FacingDirection>(); } if (!table.Get("useDefaultSettings").IsNil()) { options.useDefaultSettings = table.Get("useDefaultSettings").CastToBool(); } if (!table.Get("fadeDuration").IsNil()) { options.fadeDuration = table.Get("fadeDuration").ToObject <float>(); } if (!table.Get("moveDuration").IsNil()) { options.moveDuration = table.Get("moveDuration").ToObject <float>(); } if (!table.Get("move").IsNil()) { options.move = table.Get("move").CastToBool(); } else if (options.fromPosition != options.toPosition) { options.move = true; } if (!table.Get("shiftIntoPlace").IsNil()) { options.shiftIntoPlace = table.Get("shiftIntoPlace").CastToBool(); } if (!table.Get("waitUntilFinished").IsNil()) { options.waitUntilFinished = table.Get("waitUntilFinished").CastToBool(); } return(options); }
public IEnumerator DoConversation(string conv) { if (string.IsNullOrEmpty(conv)) { yield break; } var conversationItems = Parse(conv); if (conversationItems.Count == 0) { yield break; } // Track the current and previous parameter values Character currentCharacter = null; Sprite currentPortrait = null; RectTransform currentPosition = null; Character previousCharacter = null; // Play the conversation for (int i = 0; i < conversationItems.Count; ++i) { ConversationItem item = conversationItems[i]; if (item.Character != null) { currentCharacter = item.Character; } currentPortrait = item.Portrait; currentPosition = item.Position; ISayDialog sayDialog = GetSayDialog(currentCharacter); if (sayDialog == null) { // Should never happen yield break; } sayDialog.SetActive(true); if (currentCharacter != null && currentCharacter != previousCharacter) { sayDialog.SetCharacter(currentCharacter); } var stage = Stage.GetActiveStage(); if (stage != null && currentCharacter != null && (currentPortrait != currentCharacter.State.portrait || currentPosition != currentCharacter.State.position)) { var portraitOptions = new PortraitOptions(true); portraitOptions.display = item.Hide ? DisplayType.Hide : DisplayType.Show; portraitOptions.character = currentCharacter; portraitOptions.fromPosition = currentCharacter.State.position; portraitOptions.toPosition = currentPosition; portraitOptions.portrait = currentPortrait; //Flip option - Flip the opposite direction the character is currently facing if (item.Flip) { portraitOptions.facing = item.FacingDirection; } // Do a move tween if the character is already on screen and not yet at the specified position if (currentCharacter.State.onScreen && currentPosition != currentCharacter.State.position) { portraitOptions.move = true; } if (item.Hide) { stage.Hide(portraitOptions); } else { stage.Show(portraitOptions); } } if (stage == null && currentPortrait != null) { sayDialog.SetCharacterImage(currentPortrait); } previousCharacter = currentCharacter; if (!string.IsNullOrEmpty(item.Text)) { exitSayWait = false; sayDialog.Say(item.Text, true, true, true, false, null, () => { exitSayWait = true; }); while (!exitSayWait) { yield return(null); } exitSayWait = false; } } }