private ClothFile CreateClothFile() { string[] targets = { "UNIFORM", "SWIMSUIT", "SPORT", "CLUB" }; int suit = (int)ClothesViewModel.Kind; CharacterFile @char = ClothesViewModel.CharacterViewModel.Character; var attribs = @char.CharAttributes.Where(pair => pair.Key.StartsWith(targets[suit])) .Select(pair => pair.Value); ClothFile cf = new ClothFile { RawData = new byte[92], }; cf.Attributes["CLOTH_GENDER"].Value = ClothesViewModel.CharacterViewModel.Profile.Gender.Value; foreach (DataBlockWrapper wrapperChar in attribs) { string tgtKey = wrapperChar.Key.Replace(targets[suit], "CLOTH"); if (!cf.Attributes.ContainsKey(tgtKey)) { continue; } DataBlockWrapper wrapperCloth = cf.Attributes[tgtKey]; wrapperCloth.Value = wrapperChar.Value; } return(cf); }
public void SetAttribute(string attr, object value) { DataBlockWrapper attribute = ViewModel.GetAttribute(attr); if (attribute != null) { attribute.Value = value; } }
public SaveFileCharacterViewModelProvider(string savePath) { InstanceCache = new List <CharacterViewModel>(); SaveTimeouTimer = new Timer(FlushSave, null, Timeout.Infinite, Timeout.Infinite); SavePath = savePath; var fileBytes = File.ReadAllBytes(savePath); //Header XDocument scanDocument = Core.LoadHeaderDataXDocument(); Header = new DataBlockWrapperBuffer(fileBytes, scanDocument); HeaderBytes = new byte[Header.DataBytes.Length]; Buffer.BlockCopy(Header.DataBytes, 0, HeaderBytes, 0, HeaderBytes.Length); //Characters int lastChar; int numStudents = Header.GetAttribute <int>("HEADER_BOYS") + Header.GetAttribute <int>("HEADER_GIRLS"); Characters = ReadCharacters(fileBytes, numStudents, out lastChar); int footerSize = fileBytes.Length - lastChar; FooterBytes = new byte[footerSize]; Buffer.BlockCopy(fileBytes, lastChar, FooterBytes, 0, footerSize); //Player Seat Hax var pSeat = new byte[4]; Buffer.BlockCopy(FooterBytes, FooterBytes.Length - 4, pSeat, 0, 4); PlayerSeat = new DataBlockWrapper(pSeat, 0, new SeatDataBlock(), block => Header.HasChanges = true); Header.SaveChanges = () => { if (!Header.HasChanges) { return(false); } Buffer.BlockCopy(Header.DataBytes, 0, HeaderBytes, 0, HeaderBytes.Length); Buffer.BlockCopy(PlayerSeat.DataSource, 0, FooterBytes, FooterBytes.Length - 4, 4); StartSaveTimeout(); Header.HasChanges = false; return(true); }; Header.Reload = () => { Buffer.BlockCopy(HeaderBytes, 0, Header.DataBytes, 0, Header.DataBytes.Length); Buffer.BlockCopy(FooterBytes, FooterBytes.Length - 4, pSeat, 0, 4); foreach (DataBlockWrapper block in Header.Attributes.Values) { block.DataSource = Header.DataBytes; block.RaisePropertyChanged(String.Empty); } PlayerSeat.RaisePropertyChanged(String.Empty); Header.HasChanges = false; }; }
public object GetAttribute(string attr) { DataBlockWrapper attribute = ViewModel.GetAttribute(attr); if (attribute != null) { return(attribute.Value); } return(null); }
private void SideHairOnPropertyChanged(object sender, PropertyChangedEventArgs propertyChangedEventArgs) { DataBlockWrapper hair = CharacterViewModel.Body.HairPart.SideHair; DataBlockWrapper flip = CharacterViewModel.Body.HairPart.SideHairFlip; CharacterHairProvider.CharacterHair meta = CharacterHairProvider.SideHairs.FirstOrDefault (h => h.Id == (byte)hair.Value); if (meta == null) { return; } flip.Value = (bool)flip.Value & meta.Flippable; }
public void SetPlayData(string attr, object value) { if (!ViewModel.ExtraData.ContainsKey("PLAY_DATA")) { return; } DataBlockWrapperBuffer wb = ViewModel.ExtraData["PLAY_DATA"] as DataBlockWrapperBuffer; DataBlockWrapper playData = wb.GetAttribute(attr); if (playData != null) { playData.Value = value; } }
private void SuitOnPropertyChanged(object sender, PropertyChangedEventArgs args) { if (args.PropertyName != "Value") { return; } string[] data = { "IS_ONEPIECE", "IS_UNDERWEAR", "IS_SKIRT" }; bool[][] bData = { //Uniform new[] { false, true, true }, //Sport new[] { false, true, false }, //Swimsuit new[] { true, false, false }, //Formal new[] { false, true, true }, //Blazer new[] { false, true, true }, //Naked new[] { false, false, false }, //Undies new[] { false, true, false } }; DataBlockWrapper wrapper = (DataBlockWrapper)sender; string srcSuit = wrapper.Key.Remove(wrapper.Key.IndexOf('_')); int srcSuitValue = (int)wrapper.Value; CharacterFile @char = CharacterViewModel.Character; for (int prop = 0; prop < 3; prop++) { string targetKey = String.Format("{0}_{1}", srcSuit, data[prop]); bool targetValue; try { targetValue = bData[srcSuitValue][prop]; } catch { targetValue = false; } if (@char.CharAttributes.ContainsKey(targetKey)) { @char.CharAttributes[targetKey].Value = targetValue; } } }
private static void PropertyChangedCallback( DependencyObject dependencyObject, DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs) { ContentControl control = dependencyObject as ContentControl; if (control == null) { return; } DataTemplate overrideTemplate = GetDataTemplate(control); CharacterFile cf = GetCharacter(control); string at = GetAttribute(control); if (cf == null || string.IsNullOrEmpty(at) || !cf.CharAttributes.ContainsKey(at)) { return; } DataBlockWrapper attribute = cf.CharAttributes[at]; control.SetBinding(ContentControl.ContentProperty, new Binding { Source = attribute, }); BindingOperations.ClearBinding(control, ContentControl.ContentTemplateSelectorProperty); BindingOperations.ClearBinding(control, ContentControl.ContentTemplateProperty); if (overrideTemplate == null) { control.SetBinding(ContentControl.ContentTemplateSelectorProperty, new Binding { Source = TemplateSelector }); } else { control.SetBinding(ContentControl.ContentTemplateProperty, new Binding { Source = overrideTemplate }); } }
public IEnumerable <RenameInfo> GetNewNames(IEnumerable <CharacterViewModel> chars) { int counter = 1; string regexSearch = new string(Path.GetInvalidFileNameChars()); Regex r = new Regex(string.Format("[{0}]", Regex.Escape(regexSearch)), RegexOptions.Compiled); foreach (CharacterViewModel model in chars) { string oldPath = model.Metadata as string; string oldName = Path.GetFileNameWithoutExtension(oldPath); string dir = Path.GetDirectoryName(oldPath); string ext = Path.GetExtension(oldPath); var formatParameters = Properties.Select (s => { if (s.Equals("$")) { return(oldName); } if (s.Equals("#")) { return(counter); } DataBlockWrapper db = model.Character.CharAttributes[s]; return(db.IsEnum && ParseEnum ? db.EnumValue : db.Value); }) .ToArray(); counter++; string newName = string.Format(Format, formatParameters); newName = r.Replace(newName, ""); yield return(new RenameInfo { Path = dir, Extension = ext, OldName = oldName, NewName = newName }); } }
private string[] GetPropertyString(CharacterViewModel model) { string oldPath = model.Metadata as string; string oldName = Path.GetFileNameWithoutExtension(oldPath); return(Properties.Select (s => { if (s.Equals("$")) { return oldName; } DataBlockWrapper db = model.Character.CharAttributes[s]; return ParseEnum && db.IsEnum ? db.EnumValue : db.Value.ToString(); }) .ToArray()); }
public SaveHeaderViewModel(DataBlockWrapperBuffer header, DataBlockWrapper pSeat) { PlayerSeat = pSeat; SaveCommand = new RelayCommand(() => { if (SaveHeader.SaveChanges != null) { SaveHeader.SaveChanges(); } }, () => SaveHeader.HasChanges); ReloadCommand = new RelayCommand(() => { if (SaveHeader.Reload != null) { SaveHeader.Reload(); } }, () => SaveHeader.HasChanges); SaveHeader = header; }
private void ApplyClothFile(ClothFile cf) { string[] targets = { "UNIFORM", "SWIMSUIT", "SPORT", "CLUB" }; int suit = (int)ClothesViewModel.Kind; CharacterFile @char = ClothesViewModel.CharacterViewModel.Character; foreach (DataBlockWrapper wrapperCloth in cf.Attributes.Values) { string tgtKey = wrapperCloth.Key.Replace("CLOTH", targets[suit]); if ([email protected](tgtKey)) { continue; } DataBlockWrapper wrapperChar = @char.CharAttributes[tgtKey]; if (wrapperChar.ReadOnly) { continue; } wrapperChar.Value = wrapperCloth.Value; } }