private void SetAnimation(Entity.State state, Entity.Cardinal direction) { switch (state) { case Entity.State.Walking: case Entity.State.Idle: { switch (direction) { case Entity.Cardinal.North: { animationPlayer.CurrentAnimation = "Idle_Up"; break; } case Entity.Cardinal.South: { animationPlayer.CurrentAnimation = "Idle_Down"; break; } case Entity.Cardinal.East: { animationPlayer.CurrentAnimation = "Idle_Right"; break; } case Entity.Cardinal.West: { animationPlayer.CurrentAnimation = "Idle_Left"; break; } } break; } } }
public void onCharacterAnimationChange(Entity.State state, Entity.Cardinal direction) { SetAnimation(state, direction); }
/// <summary> /// Updates user personal information. /// </summary> /// <param name="userId">The user ID to be updated.</param> /// <param name="newData">The new data to input.</param> /// <returns>Whether the operation was successful.</returns> public async Task <bool> UpdateUserPersonalInfo(Guid userId, IUserData newData) { // TODO: make this function less terrible var cityString = newData.GetCity(); Entity.City cityEntity = null; if (cityString != null) { cityEntity = await _context.Addresses .Where(a => a.City.Name.ToLower() == cityString.ToLower().Trim()) .Select(a => a.City) .FirstOrDefaultAsync(); if (cityEntity == null) { cityEntity = new Entity.City(); cityEntity.Name = cityString.Trim(); } } // TODO: validate states var stateString = newData.GetState(); Entity.State stateEntity = null; if (stateString != null) { stateEntity = await _context.Addresses .Where(a => a.State.Name.ToLower() == stateString.ToLower().Trim()) .Select(a => a.State) .FirstOrDefaultAsync(); if (stateEntity == null) { stateEntity = new Entity.State(); stateEntity.Name = stateString.Trim(); } } var zipString = newData.GetZip(); if (zipString != null) { // Match any amount of numbers, optionally followed by a dash and any amount of numbers. var zipValidator = new Regex(@"^[0-9]{5}(-?[0-9]{4})?$"); if (!zipValidator.IsMatch(newData.GetZip().Trim())) { return(false); } } Entity.ZipCode zipEntity = null; if (zipString != null) { zipEntity = await _context.Addresses .Where(a => a.Zip.Zip == zipString.Trim()) .Select(a => a.Zip) .FirstOrDefaultAsync(); if (zipEntity == null) { zipEntity = new Entity.ZipCode(); zipEntity.Zip = zipString.Trim(); } } var addressLine1String = newData.GetAddressLine1(); Entity.AddressLine1 addressLine1Entity = null; if (addressLine1String != null) { addressLine1Entity = await _context.AddressLine1s .Where(l => l.Data.ToLower() == addressLine1String.ToLower().Trim()) .Select(l => l) .FirstOrDefaultAsync(); if (addressLine1Entity == null) { addressLine1Entity = new Entity.AddressLine1(); addressLine1Entity.Data = addressLine1String.Trim(); } } var addressLine2String = newData.GetAddressLine2(); Entity.AddressLine2 addressLine2Entity = null; if (addressLine2String != null) { addressLine2Entity = await _context.AddressLine2s .Where(l => l.Data.ToLower() == addressLine2String.ToLower().Trim()) .Select(l => l) .FirstOrDefaultAsync(); if (addressLine2Entity == null) { addressLine2Entity = new Entity.AddressLine2(); addressLine2Entity.Data = addressLine2String.Trim(); } } var user = await _context.Users .Include(c => c.Address) .ThenInclude(a => a.City) .Include(c => c.Address) .ThenInclude(a => a.State) .Include(c => c.Address) .ThenInclude(a => a.Zip) .Include(c => c.Address) .ThenInclude(a => a.Line1) .Include(c => c.Address) .ThenInclude(a => a.Line2) .Where(c => c.UserId == userId) .Select(c => c) .FirstOrDefaultAsync(); Entity.Address address = null; if (user.Address == null) { address = new Entity.Address(); _context.Add(address); user.Address = address; } else { address = await _context.Addresses .Where(a => a.AddressId == user.Address.AddressId) .Select(a => a) .FirstOrDefaultAsync(); } if (newData.GetFirstName() != null) { user.FirstName = newData.GetFirstName().Trim(); } else { user.FirstName = null; } if (newData.GetLastName() != null) { user.LastName = newData.GetLastName().Trim(); } else { user.LastName = null; } address.City = cityEntity; address.State = stateEntity; address.Zip = zipEntity; address.Line1 = addressLine1Entity; address.Line2 = addressLine2Entity; await _context.SaveChangesAsync(); return(true); }