# HG changeset patch # User Alys Brooks # Date 2021-08-28 10:13:40 # Node ID ab75bb171839656d27630c32eaaaa292a5ac9f86 # Parent 30a64479cbbaf250413824f22dae2bb60eb5b7bf Add profanity settings. diff --git a/isometric-park-fna/Components/OptionsComponent.cs b/isometric-park-fna/Components/OptionsComponent.cs new file mode 100644 --- /dev/null +++ b/isometric-park-fna/Components/OptionsComponent.cs @@ -0,0 +1,9 @@ +using Encompass; + +namespace isometricparkfna.Components { + + public struct OptionsComponent : IComponent { + public ProfanityLevel ProfanitySetting; + + } +} diff --git a/isometric-park-fna/Content/dialog.ink b/isometric-park-fna/Content/dialog.ink --- a/isometric-park-fna/Content/dialog.ink +++ b/isometric-park-fna/Content/dialog.ink @@ -47,6 +47,8 @@ \#assistantName\#: Hello. I'm \#assistantName\#. * [Nice to meet you.] You can use the mouse or arrow keys to move around, and the plus and minus keys to zoom in and out. B opens the budget and F lets you adjust Forest Policy. + + -> BadNewsReact -> * * [Got it, thanks.] diff --git a/isometric-park-fna/Content/dialog.json b/isometric-park-fna/Content/dialog.json --- a/isometric-park-fna/Content/dialog.json +++ b/isometric-park-fna/Content/dialog.json @@ -1,1 +1,1 @@ -{"inkVersion":20,"root":[[["done",{"#f":5,"#n":"g-0"}],null],"done",{"placeholder":["end",{"#f":1}],"Once":[["^Once upon a time...","\n",["ev",{"^->":"Once.0.2.$r1"},{"temp=":"$r"},"str",{"->":".^.s"},[{"#n":"$r1"}],"/str","/ev",{"*":".^.^.c-0","flg":18},{"s":["^There were two choices.",{"->":"$r","var":true},null]}],["ev",{"^->":"Once.0.3.$r1"},{"temp=":"$r"},"str",{"->":".^.s"},[{"#n":"$r1"}],"/str","/ev",{"*":".^.^.c-1","flg":18},{"s":["^There were four lines of content.",{"->":"$r","var":true},null]}],{"c-0":["ev",{"^->":"Once.0.c-0.$r2"},"/ev",{"temp=":"$r"},{"->":".^.^.2.s"},[{"#n":"$r2"}],"\n",{"->":".^.^.g-0"},{"#f":5}],"c-1":["ev",{"^->":"Once.0.c-1.$r2"},"/ev",{"temp=":"$r"},{"->":".^.^.3.s"},[{"#n":"$r2"}],"\n",{"->":".^.^.g-0"},{"#f":5}],"g-0":["^They lived happily ever after.","\n","end",{"#f":5}]}],{"#f":1}],"IntroGovernor":[["^Governor: Welcome to your new park, director!","\n","ev","str","^Okay","/str","/ev",{"*":".^.c-0","flg":20},{"c-0":["\n","^Governor: Make sure that you keep visitors happy and the budget in the black! You're currently getting an annual grant out of my budget—it'd sure be nice if you park were self-sufficient so we could drop that expense!","\n",["ev","str","^And I need to keep the forest healthy, too, right?","/str","/ev",{"*":".^.c-0","flg":20},"ev","str","^Sounds good!","/str","/ev",{"*":".^.c-1","flg":20},{"c-0":["^ ","\n","ev",{"VAR?":"GovernorOpinion"},1,"-","/ev",{"VAR=":"GovernorOpinion","re":true},"^Governor: Ummm, yeah","\n",["ev","str","^...","/str","/ev",{"*":".^.c-0","flg":20},{"c-0":["\n","end",{"#f":5}]}],{"#f":5}],"c-1":["\n","ev",{"VAR?":"GovernorOpinion"},1,"+","/ev",{"VAR=":"GovernorOpinion","re":true},"^Governor: I'll check in soon.","\n","end",{"#f":5}]}],{"#f":5}]}],{"#f":1}],"IntroAssistant":[["^#assistantName#: Hello. I'm #assistantName#.","\n","ev","str","^Nice to meet you.","/str","/ev",{"*":".^.c-0","flg":20},{"c-0":["\n","^You can use the mouse or arrow keys to move around, and the plus and minus keys to zoom in and out. B opens the budget and F lets you adjust Forest Policy.","\n",["ev","str","^Got it, thanks.","/str","/ev",{"*":".^.c-0","flg":20},"ev","str","^How are you?","/str","/ev",{"*":".^.c-1","flg":20},{"c-0":["\n","^#assistantName#: Bye","\n","end",{"#f":5}],"c-1":["\n","^#assistantName#: #howdoing#","\n","end",{"#f":5}]}],{"#f":5}]}],{"#f":1}],"BadNewsReact":[["ev","str","^Damn.","/str","/ev",{"*":".^.c-0","flg":20},"ev","str","^Fuck.","/str","/ev",{"*":".^.c-1","flg":20},"ev","str","^Shoot.","/str","/ev",{"*":".^.c-2","flg":20},{"c-0":["\n","ev","void","/ev","->->",{"#f":5}],"c-1":["\n","ev","void","/ev","->->",{"#f":5}],"c-2":["\n","ev","void","/ev","->->",{"#f":5}]}],{"#f":1}],"global decl":["ev",0,{"VAR=":"GovernorOpinion"},"/ev","end",null],"#f":1}],"listDefs":{}} \ No newline at end of file +{"inkVersion":20,"root":[[["done",{"#f":5,"#n":"g-0"}],null],"done",{"placeholder":["end",{"#f":1}],"Once":[["^Once upon a time...","\n",["ev",{"^->":"Once.0.2.$r1"},{"temp=":"$r"},"str",{"->":".^.s"},[{"#n":"$r1"}],"/str","/ev",{"*":".^.^.c-0","flg":18},{"s":["^There were two choices.",{"->":"$r","var":true},null]}],["ev",{"^->":"Once.0.3.$r1"},{"temp=":"$r"},"str",{"->":".^.s"},[{"#n":"$r1"}],"/str","/ev",{"*":".^.^.c-1","flg":18},{"s":["^There were four lines of content.",{"->":"$r","var":true},null]}],{"c-0":["ev",{"^->":"Once.0.c-0.$r2"},"/ev",{"temp=":"$r"},{"->":".^.^.2.s"},[{"#n":"$r2"}],"\n",{"->":".^.^.g-0"},{"#f":5}],"c-1":["ev",{"^->":"Once.0.c-1.$r2"},"/ev",{"temp=":"$r"},{"->":".^.^.3.s"},[{"#n":"$r2"}],"\n",{"->":".^.^.g-0"},{"#f":5}],"g-0":["^They lived happily ever after.","\n","end",{"#f":5}]}],{"#f":1}],"IntroGovernor":[["^Governor: Welcome to your new park, director!","\n","ev","str","^Okay","/str","/ev",{"*":".^.c-0","flg":20},{"c-0":["\n","^Governor: Make sure that you keep visitors happy and the budget in the black! You're currently getting an annual grant out of my budget—it'd sure be nice if you park were self-sufficient so we could drop that expense!","\n",["ev","str","^And I need to keep the forest healthy, too, right?","/str","/ev",{"*":".^.c-0","flg":20},"ev","str","^Sounds good!","/str","/ev",{"*":".^.c-1","flg":20},{"c-0":["^ ","\n","ev",{"VAR?":"GovernorOpinion"},1,"-","/ev",{"VAR=":"GovernorOpinion","re":true},"^Governor: Ummm, yeah","\n",["ev","str","^...","/str","/ev",{"*":".^.c-0","flg":20},{"c-0":["\n","end",{"#f":5}]}],{"#f":5}],"c-1":["\n","ev",{"VAR?":"GovernorOpinion"},1,"+","/ev",{"VAR=":"GovernorOpinion","re":true},"^Governor: I'll check in soon.","\n","end",{"#f":5}]}],{"#f":5}]}],{"#f":1}],"IntroAssistant":[["^#assistantName#: Hello. I'm #assistantName#.","\n","ev","str","^Nice to meet you.","/str","/ev",{"*":".^.c-0","flg":20},{"c-0":["\n","^You can use the mouse or arrow keys to move around, and the plus and minus keys to zoom in and out. B opens the budget and F lets you adjust Forest Policy.","\n",{"->t->":"BadNewsReact"},["ev","str","^Got it, thanks.","/str","/ev",{"*":".^.c-0","flg":20},"ev","str","^How are you?","/str","/ev",{"*":".^.c-1","flg":20},{"c-0":["\n","^#assistantName#: Bye","\n","end",{"#f":5}],"c-1":["\n","^#assistantName#: #howdoing#","\n","end",{"#f":5}]}],{"#f":5}]}],{"#f":1}],"BadNewsReact":[["ev","str","^Damn.","/str","/ev",{"*":".^.c-0","flg":20},"ev","str","^Fuck.","/str","/ev",{"*":".^.c-1","flg":20},"ev","str","^Shoot.","/str","/ev",{"*":".^.c-2","flg":20},{"c-0":["\n","ev","void","/ev","->->",{"#f":5}],"c-1":["\n","ev","void","/ev","->->",{"#f":5}],"c-2":["\n","ev","void","/ev","->->",{"#f":5}]}],{"#f":1}],"global decl":["ev",0,{"VAR=":"GovernorOpinion"},"/ev","end",null],"#f":1}],"listDefs":{}} \ No newline at end of file diff --git a/isometric-park-fna/Engines/DialogEngine.cs b/isometric-park-fna/Engines/DialogEngine.cs --- a/isometric-park-fna/Engines/DialogEngine.cs +++ b/isometric-park-fna/Engines/DialogEngine.cs @@ -1,6 +1,7 @@ using System; using System.Text.RegularExpressions; using System.Linq; +using System.Collections.Generic; using Encompass; using Ink.Runtime; @@ -14,10 +15,18 @@ [Receives(typeof(SetDialogMessage), typeof(DialogChoiceMessage))] - [Reads(typeof(DialogComponent)) ] + [Reads(typeof(DialogComponent), + typeof(OptionsComponent)) ] [Writes( typeof(DialogComponent))] class DialogEngine : Engine { + public static Dictionary replacements = new Dictionary{{"Damn", "Drat"}, + {"Fuck", "Fork"}, //Ty michael shur + {"Motherfucker", "Motherforker"}, + {"Shit", "Shitake mushrooms"}, + {"Hell", "Heck"}, + {"Oh my God", "Oh my Glob"}, //Ty Pendleton Ward + {"Bastard", "Bollocks"}}; public Story Story; public Grammar Grammar; @@ -27,9 +36,38 @@ this.Grammar = grammar; } + public string BleepString(string s, ProfanityLevel setting) + { + switch (setting) + { + case ProfanityLevel.Uncensored: + return s; + break; + case ProfanityLevel.Minced: + foreach (var item in replacements) + { + s = s.Replace(item.Key, item.Value); + } + return s; + break; + case ProfanityLevel.Removed: + return Regex.Replace(s, "(?i)((?<=d)amn|(?<=f)uck|(?<=D)amn|(?<=F)uck)", "------"); + } + return s; + } + public override void Update(double dt) { + ProfanityLevel profanity_setting = default; + + foreach (ref readonly var entity in ReadEntities()) + { + var option_component = GetComponent(entity); + + profanity_setting = option_component.ProfanitySetting; + } + foreach (ref readonly var dialogMessage in ReadMessages()) { if (dialogMessage.newOption != null) @@ -60,7 +98,8 @@ CurrentDialog = dialog, CurrentSpeaker = speaker, Options = this.Story.currentChoices - .Select(option => option.text) + .Select(option => BleepString(option.text, + profanity_setting )) .ToList()});} else { diff --git a/isometric-park-fna/Engines/GameBridgeEngine.cs b/isometric-park-fna/Engines/GameBridgeEngine.cs --- a/isometric-park-fna/Engines/GameBridgeEngine.cs +++ b/isometric-park-fna/Engines/GameBridgeEngine.cs @@ -18,7 +18,8 @@ typeof(SetResolutionMessage), typeof(SetFontMessage))] [Reads(typeof(AreaComponent), - typeof(ContractStatusComponent))] + typeof(ContractStatusComponent), + typeof(OptionsComponent))] class GameBridgeEngine : Engine { @@ -32,6 +33,8 @@ public override void Update(double dt) { + ProfanityLevel profanity_setting = default; + foreach (ref readonly var windowMessage in ReadMessages()) { switch (windowMessage.Window) @@ -74,10 +77,17 @@ resolutionMessage.fullscreen); } + foreach (ref readonly var entity in ReadEntities()) + { + var component = GetComponent(entity); + + profanity_setting = component.ProfanitySetting; + } foreach (ref readonly var fontMessage in ReadMessages()) { game.setFont(fontMessage.fontName, fontMessage.fontSize); - Options.writeOptions(fontMessage.fontName, fontMessage.fontSize); + Options.writeOptions(fontMessage.fontName, fontMessage.fontSize, + profanity_setting); } @@ -102,4 +112,4 @@ } } -} \ No newline at end of file +} diff --git a/isometric-park-fna/Engines/ImGuiWindowBridgeEngine.cs b/isometric-park-fna/Engines/ImGuiWindowBridgeEngine.cs --- a/isometric-park-fna/Engines/ImGuiWindowBridgeEngine.cs +++ b/isometric-park-fna/Engines/ImGuiWindowBridgeEngine.cs @@ -24,18 +24,18 @@ typeof(SpawnGameMessage), typeof(SetTextVariableMessage), typeof(SetDialogMessage), - typeof(DialogChoiceMessage))] + typeof(DialogChoiceMessage), + typeof(SetOptionMessage))] [Reads(typeof(VisibilityComponent), typeof(WindowTypeComponent), typeof(TrespassingPolicyComponent), typeof(ContractStatusComponent), typeof(RelatedOrganizationComponent), - typeof(NameAndDescriptionComponent) - )] - // [Writes(typeof(SelectedComponent))] + typeof(NameAndDescriptionComponent), + typeof(OptionsComponent))] + [Writes(typeof(OptionsComponent))] public class ImGuiWindowBridgeEngine : Engine { - public List messages; public List typeMessages; public List contractStatusMessages; @@ -49,6 +49,7 @@ public List setTextVariableMessages; public List setDialogMessages; public List dialogChoiceMessages; + public List setOptionMessages; bool showBudget {get;} bool showForest {get;} @@ -88,6 +89,7 @@ this.setTextVariableMessages = new List(); this.setDialogMessages = new List(); this.dialogChoiceMessages = new List(); + this.setOptionMessages = new List(); this.windowStatuses = new Dictionary(); this.showContractIndicator = false; @@ -166,12 +168,12 @@ { SendMessage(message); } - + foreach (var message in this.spawnGameMessages) { SendMessage(message); } - + foreach (var message in this.setDialogMessages) { @@ -182,6 +184,17 @@ SendMessage(message); } + foreach(var message in this.setOptionMessages) + { + foreach(var entity in ReadEntities()) + { + + SetComponent(entity, new OptionsComponent { + ProfanitySetting = message.NewProfanitySetting}); + } + + } + @@ -230,6 +243,7 @@ this.setTextVariableMessages.Clear(); this.setDialogMessages.Clear(); this.dialogChoiceMessages.Clear(); + this.setOptionMessages.Clear(); } } } diff --git a/isometric-park-fna/FNAGame.cs b/isometric-park-fna/FNAGame.cs --- a/isometric-park-fna/FNAGame.cs +++ b/isometric-park-fna/FNAGame.cs @@ -198,7 +198,6 @@ Quad.Initialize(GraphicsDevice, texture); Logging.Success("Initialized Quad texture."); ContractWindow.LoadContent(this._imGuiRenderer, this.imageMap); - OptionsWindow.Initialize(new Vector2(FNAGame.width, FNAGame.height), gdm.IsFullScreen); //Must be done before SetFontMessage is sent var bakedMono = TtfFontBaker.Bake(File.OpenRead(@"Content/iosevka-term-extendedmedium.ttf"), @@ -320,7 +319,12 @@ this.imGuiWindowBridgeEngine.fontMessages.Add(new SetFontMessage{ fontSize = options.fontSize, fontName = options.fontName}); + + WorldBuilder.SetComponent(gameEntity, new OptionsComponent {ProfanitySetting = options.profanitySetting}); + + OptionsWindow.Initialize(new Vector2(FNAGame.width, FNAGame.height), gdm.IsFullScreen, options.profanitySetting); Logging.Success("Loaded options."); + } catch (FileNotFoundException e) { diff --git a/isometric-park-fna/Messages/SetOptionMessage.cs b/isometric-park-fna/Messages/SetOptionMessage.cs new file mode 100644 --- /dev/null +++ b/isometric-park-fna/Messages/SetOptionMessage.cs @@ -0,0 +1,10 @@ +using Microsoft.Xna.Framework; +using Encompass; + +namespace isometricparkfna.Messages +{ + public struct SetOptionMessage : IMessage + { + public ProfanityLevel NewProfanitySetting; + } +} diff --git a/isometric-park-fna/Options.cs b/isometric-park-fna/Options.cs --- a/isometric-park-fna/Options.cs +++ b/isometric-park-fna/Options.cs @@ -4,22 +4,34 @@ namespace isometricparkfna { + + public enum ProfanityLevel + { + Uncensored, + Minced, + Removed + + } + public class Options { public string fontName; public int fontSize; + public ProfanityLevel profanitySetting; - public Options(string fontName, int fontSize) + public Options(string fontName, int fontSize, ProfanityLevel profanitySetting) { this.fontName = fontName; this.fontSize = fontSize; + this.profanitySetting = profanitySetting; + } - public static void writeOptions(string fontName, int fontSize) + public static void writeOptions(string fontName, int fontSize, ProfanityLevel profanitySetting) { - var options = new Options(fontName, fontSize); + var options = new Options(fontName, fontSize, profanitySetting); string json = JsonConvert.SerializeObject(options, Formatting.Indented); diff --git a/isometric-park-fna/Renderers/ImGuiWindowRenderer.cs b/isometric-park-fna/Renderers/ImGuiWindowRenderer.cs --- a/isometric-park-fna/Renderers/ImGuiWindowRenderer.cs +++ b/isometric-park-fna/Renderers/ImGuiWindowRenderer.cs @@ -54,6 +54,7 @@ var area_size = GetComponent(entity).squares.Length; + if (HasComponent(entity)) { var related_organization = GetComponent(entity).Entity; @@ -88,6 +89,12 @@ Entity dialogEntity = default; DialogComponent dialogNode = default; + ProfanityLevel profanityLevel = default; + + foreach (ref readonly var entity in ReadEntities()) + { + profanityLevel = GetComponent(entity).ProfanitySetting; + } foreach (ref readonly var entity in ReadEntities()) @@ -127,7 +134,7 @@ InGameMenu.Render(this.BridgeEngine.font, this.BridgeEngine, width); break; case Window.Options: - OptionsWindow.Render(this.BridgeEngine.font, this.BridgeEngine.italicFont, this.BridgeEngine, width); + OptionsWindow.Render(this.BridgeEngine.font, this.BridgeEngine.italicFont, this.BridgeEngine, width, profanityLevel); break; case Window.NewGame: NewGameWindow.Render(this.BridgeEngine.font, this.BridgeEngine.italicFont, this.BridgeEngine); diff --git a/isometric-park-fna/UI/OptionsWindow.cs b/isometric-park-fna/UI/OptionsWindow.cs --- a/isometric-park-fna/UI/OptionsWindow.cs +++ b/isometric-park-fna/UI/OptionsWindow.cs @@ -21,31 +21,27 @@ private static string fontName = "Iosevka"; private static int fontSize = 15; + private static ProfanityLevel profanityLevel = default; - public static void Initialize(Vector2 resolution, bool fullscreen) + public static void Initialize(Vector2 resolution, bool fullscreen, ProfanityLevel profanityLevel) { - newFullscreen = fullscreen; - newResolution = resolution; + OptionsWindow.newFullscreen = fullscreen; + OptionsWindow.newResolution = resolution; + OptionsWindow.profanityLevel = profanityLevel; } - public static void Render(ImFontPtr font, ImFontPtr italicFont, ImGuiWindowBridgeEngine bridgeEngine, int width) + public static void Render(ImFontPtr font, ImFontPtr italicFont, ImGuiWindowBridgeEngine bridgeEngine, int width, ProfanityLevel profanityLevel) { ImGui.GetStyle().WindowMenuButtonPosition = ImGuiDir.None; bool newShow = true; - // Num.Vector2 button_size = new Num.Vector2(120, 20); - StyleSets.defaultSet.push(); - // ImGui.SetNextWindowPos(new Num.Vector2(width/2, 200)); + ImGui.PushFont(font); - ImGui.PushFont(font); - // ImGui.PushFont(smallFont); - // - // ImGui.SetNextWindowSize(new Num.Vector2(320, 320)); if(OptionsWindow.hadFocus) { ImGui.PushStyleColor(ImGuiCol.Text, StyleSets.white); @@ -137,6 +133,31 @@ ImGui.Separator(); + ImGui.PushFont(italicFont); + ImGui.Text("Text:"); + ImGui.PopFont(); + + ImGui.Text("Profanity:"); + ImGui.SameLine(); + if (ImGui.BeginCombo("##Profanity", profanityLevel.ToString())) + { + + foreach(var level in Enum.GetValues(typeof(ProfanityLevel))) + { + if(ImGui.Selectable(level.ToString())) + { + bridgeEngine.setOptionMessages.Add(new SetOptionMessage{ NewProfanitySetting = (ProfanityLevel)level}); + OptionsWindow.profanityLevel = (ProfanityLevel)level; + } + + } + + ImGui.EndCombo(); + } + + + + ImGui.Separator(); if (ImGui.Button("Okay")) {