public async Task <PlayerPreferences> InitPrefsAsync(NetUserId userId, ICharacterProfile defaultProfile) { await using var db = await GetDb(); var profile = ConvertProfiles((HumanoidCharacterProfile)defaultProfile, 0); var prefs = new Preference { UserId = userId.UserId, SelectedCharacterSlot = 0, AdminOOCColor = Color.Red.ToHex() }; prefs.Profiles.Add(profile); db.DbContext.Preference.Add(prefs); await db.DbContext.SaveChangesAsync(); return(new PlayerPreferences(new[] { new KeyValuePair <int, ICharacterProfile>(0, defaultProfile) }, 0, Color.FromHex(prefs.AdminOOCColor))); }
public PlayerPreferences GetPlayerPreferences(string username) { var prefs = _prefsDb.GetPlayerPreferences(username); if (prefs is null) { return(null); } var profiles = new ICharacterProfile[_maxCharacterSlots]; foreach (var profile in prefs.HumanoidProfiles) { var jobs = profile.Jobs.ToDictionary(j => j.JobName, j => (JobPriority)j.Priority); profiles[profile.Slot] = new HumanoidCharacterProfile( profile.CharacterName, profile.Age, profile.Sex == "Male" ? Male : Female, new HumanoidCharacterAppearance ( profile.HairName, Color.FromHex(profile.HairColor), profile.FacialHairName, Color.FromHex(profile.FacialHairColor), Color.FromHex(profile.EyeColor), Color.FromHex(profile.SkinColor) ), jobs, (PreferenceUnavailableMode)profile.PreferenceUnavailable ); } return(new PlayerPreferences ( profiles, prefs.SelectedCharacterSlot )); }
public void SaveCharacterSlot(string username, ICharacterProfile profile, int slot) { if (slot < 0 || slot >= _maxCharacterSlots) { return; } if (profile is null) { DeleteCharacterSlot(username, slot); return; } if (!(profile is HumanoidCharacterProfile humanoid)) { // TODO: Handle other ICharacterProfile implementations properly throw new NotImplementedException(); } var appearance = (HumanoidCharacterAppearance)humanoid.CharacterAppearance; using (var connection = GetDbConnection()) { connection.Execute(SaveCharacterSlotQuery, new { Name = humanoid.Name, Age = humanoid.Age, Sex = humanoid.Sex.ToString(), HairStyleName = appearance.HairStyleName, HairColor = appearance.HairColor.ToHex(), FacialHairStyleName = appearance.FacialHairStyleName, FacialHairColor = appearance.FacialHairColor.ToHex(), EyeColor = appearance.EyeColor.ToHex(), SkinColor = appearance.SkinColor.ToHex(), Slot = slot, Username = username }); } }
public PlayerPreferences GetPlayerPreferences(string username) { var prefs = _prefsDb.GetPlayerPreferences(username); if (prefs is null) { return(null); } var profiles = new ICharacterProfile[_maxCharacterSlots]; foreach (var profile in prefs.HumanoidProfiles) { profiles[profile.Slot] = new HumanoidCharacterProfile { Name = profile.CharacterName, Age = profile.Age, Sex = profile.Sex == "Male" ? Male : Female, CharacterAppearance = new HumanoidCharacterAppearance { HairStyleName = profile.HairName, HairColor = Color.FromHex(profile.HairColor), FacialHairStyleName = profile.FacialHairName, FacialHairColor = Color.FromHex(profile.FacialHairColor), EyeColor = Color.FromHex(profile.EyeColor), SkinColor = Color.FromHex(profile.SkinColor) } } } ; return(new PlayerPreferences { SelectedCharacterIndex = prefs.SelectedCharacterSlot, Characters = profiles.ToList() }); }
public bool MemberwiseEquals(ICharacterProfile maybeOther) { if (!(maybeOther is HumanoidCharacterProfile other)) { return(false); } if (Name != other.Name) { return(false); } if (Age != other.Age) { return(false); } if (Sex != other.Sex) { return(false); } if (CharacterAppearance is null) { return(other.CharacterAppearance is null); } return(CharacterAppearance.MemberwiseEquals(other.CharacterAppearance)); }
public Task <PlayerPreferences> InitPrefsAsync(NetUserId userId, ICharacterProfile defaultProfile) { return(_db.InitPrefsAsync(userId, defaultProfile)); }
public CharacterPickerButton( IEntityManager entityManager, IClientPreferencesManager preferencesManager, ButtonGroup group, ICharacterProfile profile) { AddStyleClass(StyleClassButton); ToggleMode = true; Group = group; _previewDummy = entityManager.SpawnEntity("HumanMob_Dummy", MapCoordinates.Nullspace); _previewDummy.GetComponent <HumanoidAppearanceComponent>().UpdateFromProfile(profile); var humanoid = profile as HumanoidCharacterProfile; if (humanoid != null) { LobbyCharacterPreviewPanel.GiveDummyJobClothes(_previewDummy, humanoid); } var isSelectedCharacter = profile == preferencesManager.Preferences?.SelectedCharacter; if (isSelectedCharacter) { Pressed = true; } var view = new SpriteView { Sprite = _previewDummy.GetComponent <SpriteComponent>(), Scale = (2, 2), OverrideDirection = Direction.South }; var description = profile.Name; var highPriorityJob = humanoid?.JobPriorities.SingleOrDefault(p => p.Value == JobPriority.High).Key; if (highPriorityJob != null) { var jobName = IoCManager.Resolve <IPrototypeManager>().Index <JobPrototype>(highPriorityJob).Name; description = $"{description}\n{jobName}"; } var descriptionLabel = new Label { Text = description, ClipText = true, HorizontalExpand = true }; var deleteButton = new Button { Text = Loc.GetString("character-setup-gui-character-picker-button-delete-button"), Visible = !isSelectedCharacter, }; deleteButton.OnPressed += _ => { Parent?.RemoveChild(this); preferencesManager.DeleteCharacter(profile); }; var internalHBox = new HBoxContainer { HorizontalExpand = true, SeparationOverride = 0, Children = { view, descriptionLabel, deleteButton } }; AddChild(internalHBox); }
private void ProfileChanged(ICharacterProfile profile, int profileSlot) { _humanoidProfileEditor.UpdateControls(); UpdateUI(); }
public void UpdateFromProfile(EntityUid uid, ICharacterProfile profile) { var humanoid = (HumanoidCharacterProfile)profile; UpdateAppearance(uid, humanoid.Appearance, humanoid.Sex, humanoid.Gender); }
public CharacterPickerButton( IEntityManager entityManager, IClientPreferencesManager preferencesManager, ButtonGroup group, ICharacterProfile profile) { _previewDummy = entityManager.SpawnEntity("HumanMob_Dummy", MapCoordinates.Nullspace); _previewDummy.GetComponent <HumanoidAppearanceComponent>().UpdateFromProfile(profile); var humanoid = profile as HumanoidCharacterProfile; if (humanoid != null) { LobbyCharacterPreviewPanel.GiveDummyJobClothes(_previewDummy, humanoid); } var isSelectedCharacter = profile == preferencesManager.Preferences.SelectedCharacter; ActualButton = new Button { SizeFlagsHorizontal = SizeFlags.FillExpand, SizeFlagsVertical = SizeFlags.FillExpand, ToggleMode = true, Group = group }; if (isSelectedCharacter) { ActualButton.Pressed = true; } AddChild(ActualButton); var view = new SpriteView { Sprite = _previewDummy.GetComponent <SpriteComponent>(), Scale = (2, 2), MouseFilter = MouseFilterMode.Ignore, OverrideDirection = Direction.South }; var description = profile.Name; var highPriorityJob = humanoid?.JobPriorities.SingleOrDefault(p => p.Value == JobPriority.High).Key; if (highPriorityJob != null) { var jobName = IoCManager.Resolve <IPrototypeManager>().Index <JobPrototype>(highPriorityJob).Name; description = $"{description}\n{jobName}"; } var descriptionLabel = new Label { Text = description, ClipText = true, SizeFlagsHorizontal = SizeFlags.FillExpand }; var deleteButton = new Button { Text = "Delete", Visible = !isSelectedCharacter, }; deleteButton.OnPressed += args => { Parent.RemoveChild(this); preferencesManager.DeleteCharacter(profile); }; var internalHBox = new HBoxContainer { SizeFlagsHorizontal = SizeFlags.FillExpand, MouseFilter = MouseFilterMode.Ignore, SeparationOverride = 0, Children = { view, descriptionLabel, deleteButton } }; AddChild(internalHBox); }
public bool TryIndexOfCharacter(ICharacterProfile profile, out int index) { return((index = IndexOfCharacter(profile)) != -1); }
public void CreateCharacter(ICharacterProfile profile) { UpdateCharacter(profile, Preferences.FirstEmptySlot); }
public int IndexOfCharacter(ICharacterProfile profile) { return(_characters.FindIndex(x => x == profile)); }
public Task SaveCharacterSlotAsync(NetUserId userId, ICharacterProfile profile, int slot) { return(_db.SaveCharacterSlotAsync(userId, profile, slot)); }
public void SelectCharacter(ICharacterProfile profile) { SelectCharacter(Preferences.IndexOfCharacter(profile)); }
public int IndexOfCharacter(ICharacterProfile profile) { return(_characters.FirstOrNull(p => p.Value == profile)?.Key ?? -1); }
public void DeleteCharacter(ICharacterProfile profile) { DeleteCharacter(Preferences.IndexOfCharacter(profile)); }
public void UpdateFromProfile(EntityUid uid, ICharacterProfile profile, HumanoidAppearanceComponent?appearance = null) { var humanoid = (HumanoidCharacterProfile)profile; UpdateAppearance(uid, humanoid.Appearance, humanoid.Sex, humanoid.Gender, humanoid.Species, appearance); }