Initial commit: Unity WordConnect project
This commit is contained in:
@ -0,0 +1,44 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace WordsToolkit.Scripts.Services.BannedWords
|
||||
{
|
||||
[Serializable]
|
||||
public class LanguageBannedWords
|
||||
{
|
||||
public string languageCode;
|
||||
public List<string> bannedWords = new List<string>();
|
||||
}
|
||||
|
||||
public class BannedWordsConfiguration : ScriptableObject
|
||||
{
|
||||
public List<LanguageBannedWords> bannedWordsByLanguage = new List<LanguageBannedWords>();
|
||||
|
||||
public List<string> GetBannedWords(string languageCode)
|
||||
{
|
||||
var languageData = bannedWordsByLanguage.Find(x => x.languageCode == languageCode);
|
||||
return languageData?.bannedWords ?? new List<string>();
|
||||
}
|
||||
|
||||
public void AddBannedWord(string word, string languageCode)
|
||||
{
|
||||
var languageData = bannedWordsByLanguage.Find(x => x.languageCode == languageCode);
|
||||
if (languageData == null)
|
||||
{
|
||||
languageData = new LanguageBannedWords { languageCode = languageCode };
|
||||
bannedWordsByLanguage.Add(languageData);
|
||||
}
|
||||
if (!languageData.bannedWords.Contains(word))
|
||||
{
|
||||
languageData.bannedWords.Add(word);
|
||||
}
|
||||
}
|
||||
|
||||
public void RemoveBannedWord(string word, string languageCode)
|
||||
{
|
||||
var languageData = bannedWordsByLanguage.Find(x => x.languageCode == languageCode);
|
||||
languageData?.bannedWords.Remove(word);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 889b087cffdd548cc9d3e4d3adefdebc
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -0,0 +1,55 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using VContainer;
|
||||
#if UNITY_EDITOR
|
||||
using UnityEditor;
|
||||
#endif
|
||||
|
||||
namespace WordsToolkit.Scripts.Services.BannedWords
|
||||
{
|
||||
public class BannedWordsService : IBannedWordsService
|
||||
{
|
||||
private readonly BannedWordsConfiguration configuration;
|
||||
|
||||
[Inject]
|
||||
public BannedWordsService(BannedWordsConfiguration configuration)
|
||||
{
|
||||
this.configuration = configuration;
|
||||
}
|
||||
|
||||
public List<string> GetBannedWords(string languageCode)
|
||||
{
|
||||
return configuration.GetBannedWords(languageCode);
|
||||
}
|
||||
|
||||
public bool IsWordBanned(string word, string languageCode)
|
||||
{
|
||||
var bannedWords = GetBannedWords(languageCode);
|
||||
return bannedWords.Contains(word.ToLower());
|
||||
}
|
||||
|
||||
public void AddBannedWord(string word, string languageCode)
|
||||
{
|
||||
configuration.AddBannedWord(word.ToLower(), languageCode);
|
||||
SaveConfiguration();
|
||||
}
|
||||
|
||||
public void RemoveBannedWord(string word, string languageCode)
|
||||
{
|
||||
configuration.RemoveBannedWord(word.ToLower(), languageCode);
|
||||
SaveConfiguration();
|
||||
}
|
||||
|
||||
private void SaveConfiguration()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
if (configuration != null)
|
||||
{
|
||||
EditorUtility.SetDirty(configuration);
|
||||
AssetDatabase.SaveAssets();
|
||||
Debug.Log($"Saved BannedWordsConfiguration");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cebba6a642ce346a4a2045f00d26aee9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -0,0 +1,12 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace WordsToolkit.Scripts.Services.BannedWords
|
||||
{
|
||||
public interface IBannedWordsService
|
||||
{
|
||||
List<string> GetBannedWords(string languageCode);
|
||||
bool IsWordBanned(string word, string languageCode);
|
||||
void AddBannedWord(string word, string languageCode);
|
||||
void RemoveBannedWord(string word, string languageCode);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0bac5fa11daa34c1494f453f2252f6e6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user