public static Color GetCurrentColor(Color colorOrig, int dashes, int index, PlayerHair self) { if (dashes >= MAX_DASH_COUNT) { return(colorOrig); } int speed = Instance.triggerManager.GetHairSpeed(dashes); int length = Instance.triggerManager.GetHairLength(dashes); float phaseShift = Math.Abs(((float)index / ((float)length)) - 0.01f); float phase = phaseShift + speed / 20.0f * Hyperline.Instance.time; phase -= (float)(Math.Floor(phase)); Color returnV = new Color(0, 0, 0); IHairType hair = Instance.triggerManager.GetHair(dashes); if (hair != null) { returnV = hair.GetColor(colorOrig, phase); if (returnV == null) { returnV = new Color(0, 0, 0); } } return(returnV); }
private void PlayerHair_AfterUpdate(On.Celeste.PlayerHair.orig_AfterUpdate orig, PlayerHair self) { if (!(self.Entity is Player) || !Settings.Enabled || (self.Entity as Player).Dashes > MAX_DASH_COUNT) { orig(self); return; } Player player = (Player)self.Entity; Instance.time += Engine.DeltaTime; maddyCrownSprite = null; Instance.UpdateHairLength(self); IHairType hair = Instance.triggerManager.GetHair(player.Dashes); if (hair != null) { hair.AfterUpdate(orig, self); } else { orig(self); //this really shouldn't happen, only happens when using the load command from the main menu, so we'll reload the trigger manager triggerManager.LoadFromSettings(); } }
public static void PlayerUpdate(On.Celeste.Player.orig_Update orig, Player player) { if (Settings.Enabled) { if (!(!Settings.DoFeatherColor && player.StateMachine.State == 19)) { Instance.maddyCrownSprite = null; IHairType currentHair = Instance.triggerManager.GetHair(player.Dashes); if (currentHair != null) { currentHair.PlayerUpdate(Instance.lastColor, player); } } else { player.OverrideHairColor = null; } } if (Instance.shouldClearOverride) { Instance.shouldClearOverride = false; player.OverrideHairColor = null; } orig(player); }
public static Color GetHairColor(On.Celeste.PlayerHair.orig_GetHairColor orig, PlayerHair self, int index) { Color colorOrig = orig(self, index); if (!(self.Entity is Player) || !Settings.Enabled) { return(colorOrig); } Player player = self.Entity as Player; if (player.Dashes >= MAX_DASH_COUNT || player.Dashes < 0 || (!Settings.DoFeatherColor && player.StateMachine.State == 19)) { return(colorOrig); } Color ReturnC = GetCurrentColor(colorOrig, ((Player)self.Entity).Dashes, index, self); if (index == 0) { Instance.UpdateMaddyCrown(self.Entity as Player); Instance.lastColor = ReturnC; Instance.lastHairLength = Instance.triggerManager.GetHairLength(((Player)self.Entity).Dashes); } if (IHairType.IsFlash() && Settings.DoDashFlash) { return(Player.FlashHairColor); } return(ReturnC); }
public void AddHairType(IHairType hair) { uint id = hair.GetHash(); if (!hairTypes.ContainsKey(id)) { hairTypes[id] = hair; } }
public void SetTrigger(IHairType hair, int dashCount, int length, int speed) { if (dashCount < Hyperline.MAX_DASH_COUNT) { hairChanges[dashCount] = hair; hairLengthChanges[dashCount] = length; hairSpeedChanges[dashCount] = speed; } UpdateFromChanges(); }
/* Here for backwards compatability */ public void ReadV1_15(BinaryReader reader) { const int DEFAULT_HAIR_TYPE_COUNT = 3; IHairType[] HairTypeDict = new IHairType[DEFAULT_HAIR_TYPE_COUNT]; HairTypeDict[0] = (new GradientHair()); HairTypeDict[1] = (new PatternHair()); HairTypeDict[2] = (new SolidHair()); IHairType[,] HairList = new IHairType[Hyperline.MAX_DASH_COUNT, DEFAULT_HAIR_TYPE_COUNT]; for (int i = 0; i < Hyperline.MAX_DASH_COUNT; i++) { for (int c = 0; c < (int)HairTypeDict.Length; c++) { HairList[i, c] = HairTypeDict[c].CreateNew(i); } } Enabled = reader.ReadBoolean(); AllowMapHairColors = reader.ReadBoolean(); for (int i = 0; i < Hyperline.MAX_DASH_COUNT; i++) { hairTypeList[i] = (uint)reader.ReadByte(); hairLengthList[i] = reader.ReadInt32(); hairLengthList[i] = (hairLengthList[i] >= MIN_HAIR_LENGTH && hairLengthList[i] <= MAX_HAIR_LENGTH) ? hairLengthList[i] : 4; hairSpeedList[i] = reader.ReadInt32(); for (int x = 0; x < HairTypeDict.Length; x++) { HairList[i, x] = HairTypeDict[x].CreateNew(); HairList[i, x].Read(reader, version); } } DoMaddyCrown = reader.ReadBoolean(); for (int i = 0; i < Hyperline.MAX_DASH_COUNT; i++) { hairTextureSource[i] = reader.ReadString(); } for (int i = 0; i < Hyperline.MAX_DASH_COUNT; i++) { hairBangsSource[i] = reader.ReadString(); } for (int i = 0; i < Hyperline.MAX_DASH_COUNT; i++) { for (int x = 0; x < HairTypeDict.Length; x++) { uint hash = HairList[i, x].GetHash(); hairList[i][hash] = HairList[i, x]; } hairTypeList[i] = HairTypeDict[hairTypeList[i]].GetHash(); } }
public IHairType[] GetHairTypes() { IHairType[] hairTypeList = new IHairType[hairTypes.Count]; uint index = 0; foreach (KeyValuePair <uint, IHairType> hair in hairTypes) { hairTypeList[index] = hair.Value; index++; } return(hairTypeList); }
private void UpdateHair(On.Celeste.Player.orig_UpdateHair orig, Player self, bool applyGravity) { if (!Settings.Enabled || self.Dashes > MAX_DASH_COUNT) { orig(self, applyGravity); return; } IHairType hair = Instance.triggerManager.GetHair(self.Dashes); if (hair != null) { hair.UpdateHair(orig, self, applyGravity); } else { orig(self, applyGravity); } }
public void RenderHair(On.Celeste.PlayerHair.orig_Render orig, PlayerHair self) { if (!(self.Entity is Player) || !Settings.Enabled || (self.Entity as Player).Dashes > MAX_DASH_COUNT) { orig(self); return; } Player player = self.Entity as Player; IHairType hair = Instance.triggerManager.GetHair(player.Dashes); if (hair != null) { hair.Render(orig, self); } else { orig(self); } }
public override void Read(BinaryReader reader) { try { byte[] header = reader.ReadBytes(4); reader.BaseStream.Seek(-4, SeekOrigin.Current); if (header.SequenceEqual(oldHeader) || header.SequenceEqual(newHeader)) { ReadV1_17(reader); } else { MemoryStream currentReader = new MemoryStream(reader.ReadBytes((int)reader.BaseStream.Length)); XDocument document = XDocument.Load(currentReader); XElement root = document.Element("root"); if (root != null) { XElement enabledElement = root.Element("enabled"); if (enabledElement != null) { Enabled = (bool)enabledElement; } XElement doDashFlashElement = root.Element("doDashFlash"); if (doDashFlashElement != null) { DoDashFlash = (bool)doDashFlashElement; } XElement allowMapColors = root.Element("allowMapHairColor"); if (allowMapColors != null) { AllowMapHairColors = (bool)allowMapColors; } XElement doMaddyCrown = root.Element("doMaddyCrown"); if (doMaddyCrown != null) { DoMaddyCrown = (bool)doMaddyCrown; } XElement hyperlineSoftCap = root.Element("hairLengthSoftCap"); if (hyperlineSoftCap != null) { HairLengthSoftCap = (int)hyperlineSoftCap; } if (HairLengthSoftCap > MAX_HAIR_LENGTH) { HairLengthSoftCap = MAX_HAIR_LENGTH; } XElement doFeatherColor = root.Element("doFeatherColor"); if (doFeatherColor != null) { DoFeatherColor = (bool)doFeatherColor; } XElement dashesElement = root.Element("dashes"); if (dashesElement != null) { foreach (XElement dashCountElement in dashesElement.Elements("dash")) { XAttribute dashAttr = dashCountElement.Attribute("count"); if (dashAttr != null) { int dash = (int)dashAttr; if (dash < Hyperline.MAX_DASH_COUNT) { XElement hairLengthElement = dashCountElement.Element("hairLength"); if (hairLengthElement != null) { hairLengthList[dash] = (int)hairLengthElement; if (hairLengthList[dash] > HairLengthSoftCap || hairLengthList[dash] < MIN_HAIR_LENGTH) { hairLengthList[dash] = 4; } } else { Logger.Log(LogLevel.Warn, "Hyperline", "Hyperline settings XML missing dash hair length element."); } XElement hairSpeedElement = dashCountElement.Element("hairSpeed"); if (hairSpeedElement != null) { hairSpeedList[dash] = (int)hairSpeedElement; if (hairSpeedList[dash] > MAX_HAIR_SPEED || hairSpeedList[dash] < MIN_HAIR_SPEED) { hairSpeedList[dash] = 0; } } else { Logger.Log(LogLevel.Warn, "Hyperline", "Hyperline settings XML missing dash hair speed element."); } XElement hairBangsElement = dashCountElement.Element("bangsTexture"); if (hairBangsElement != null) { hairBangsSource[dash] = (string)hairBangsElement; } XElement hairTextureElement = dashCountElement.Element("hairTexture"); if (hairTextureElement != null) { hairTextureSource[dash] = (string)hairTextureElement; } string chosenType = SolidHair.id; XElement hairTypeElement = dashCountElement.Element("type"); if (hairTypeElement != null) { chosenType = (string)hairTypeElement; } else { Logger.Log(LogLevel.Warn, "Hyperline", "Hyperline settings XML missing dash hair type element."); } if (Hyperline.Instance.hairTypes.Has(Hashing.FNV1Hash(chosenType))) { hairTypeList[dash] = Hashing.FNV1Hash(chosenType); } XElement tp = dashCountElement.Element("types"); if (tp != null) { foreach (XElement currentType in tp.Elements()) { uint type = Hashing.FNV1Hash(currentType.Name.LocalName); try { IHairType hair = Hyperline.Instance.hairTypes.CreateNewHairType(type); if (hair != null) { hair.Read(currentType); hairList[dash][type] = hair; } else { Logger.Log(LogLevel.Warn, "Hyperline", "Hyperline contained invalid hair type " + currentType.Name); } } catch (Exception exception) { Logger.Log(LogLevel.Warn, "Hyperline", "Exception occured while loading hair type " + currentType.Name.LocalName + " dash count " + dash + "\n" + exception); } } } else { Logger.Log(LogLevel.Warn, "Hyperline", "XML file missing types for dash count " + dash); } } } } } else { Logger.Log(LogLevel.Warn, "Hyperline", "Hyperline settings XML missing dashs element."); } } else { Logger.Log(LogLevel.Warn, "Hyperline", "Hyperline settings XML missing root element."); } } } catch (Exception exception) { Logger.Log(LogLevel.Error, "Hyperline", "Error while loading save file...\n" + exception.ToString()); } }
public void Read(BinaryReader reader) { MemoryStream currentReader = new MemoryStream(reader.ReadBytes((int)reader.BaseStream.Length)); XDocument document = XDocument.Load(currentReader); XElement root = document.Element("root"); if (root != null) { XElement hairChangesElement = root.Element("hairChanges"); if (hairChangesElement != null) { foreach (XElement dashCountElement in hairChangesElement.Elements("dash")) { XAttribute dashAttr = dashCountElement.Attribute("count"); if (dashAttr != null) { int dash = (int)dashAttr; if (dash < Hyperline.MAX_DASH_COUNT) { foreach (XElement hairElement in dashCountElement.Elements()) { uint type = Hashing.FNV1Hash(hairElement.Name.LocalName); IHairType currentHair = Hyperline.Instance.hairTypes.CreateNewHairType(type); if (currentHair != null) { currentHair.Read(hairElement); hairChanges[dash] = currentHair; } } } } } } XElement speedChangesElement = root.Element("speedChanges"); if (speedChangesElement != null) { foreach (XElement dashCountElement in speedChangesElement.Elements("dash")) { XAttribute dashAttr = dashCountElement.Attribute("count"); if (dashAttr != null) { int dash = (int)dashAttr; if (dash < Hyperline.MAX_DASH_COUNT) { XElement speedElement = dashCountElement.Element("speed"); if (speedElement != null) { hairSpeedChanges[dash] = (int)speedElement; } } } } } XElement lengthChangesElement = root.Element("speedChanges"); if (speedChangesElement != null) { foreach (XElement dashCountElement in lengthChangesElement.Elements("dash")) { XAttribute dashAttr = dashCountElement.Attribute("count"); if (dashAttr != null) { int dash = (int)dashAttr; if (dash < Hyperline.MAX_DASH_COUNT) { XElement lengthElement = dashCountElement.Element("length"); if (lengthElement != null) { hairLengthChanges[dash] = (int)lengthElement; } } } } } } }
public void AddHairType(IHairType type) { hairTypes.AddHairType(type); }
public void Read(BinaryReader reader) { try { MemoryStream currentReader = new MemoryStream(reader.ReadBytes((int)reader.BaseStream.Length)); XDocument document = XDocument.Load(currentReader); XElement root = document.Element("root"); if (root != null) { XElement dashesElement = root.Element("dashes"); if (dashesElement != null) { foreach (XElement dashCountElement in dashesElement.Elements("dash")) { XAttribute dashAttr = dashCountElement.Attribute("count"); if (dashAttr != null) { int dash = (int)dashAttr; if (dash < Hyperline.MAX_DASH_COUNT) { XElement hairLengthElement = dashCountElement.Element("hairLength"); if (hairLengthElement != null) { hairLengthList[dash] = (int)hairLengthElement; if (hairLengthList[dash] > HyperlineSettings.MAX_HAIR_LENGTH || hairLengthList[dash] < HyperlineSettings.MIN_HAIR_LENGTH) { hairLengthList[dash] = 4; } } else { Logger.Log(LogLevel.Warn, "Hyperline", "Hyperline settings XML missing dash hair length element."); } XElement hairSpeedElement = dashCountElement.Element("hairSpeed"); if (hairSpeedElement != null) { hairSpeedList[dash] = (int)hairSpeedElement; if (hairSpeedList[dash] > HyperlineSettings.MAX_HAIR_SPEED || hairSpeedList[dash] < HyperlineSettings.MIN_HAIR_SPEED) { hairSpeedList[dash] = 0; } } else { Logger.Log(LogLevel.Warn, "Hyperline", "Hyperline settings XML missing dash hair speed element."); } XElement hairBangsElement = dashCountElement.Element("bangsTexture"); if (hairBangsElement != null) { hairBangsSource[dash] = (string)hairBangsElement; } XElement hairTextureElement = dashCountElement.Element("hairTexture"); if (hairTextureElement != null) { hairTextureSource[dash] = (string)hairTextureElement; } string chosenType = SolidHair.id; XElement hairTypeElement = dashCountElement.Element("type"); if (hairTypeElement != null) { chosenType = (string)hairTypeElement; } else { Logger.Log(LogLevel.Warn, "Hyperline", "Hyperline settings XML missing dash hair type element."); } if (Hyperline.Instance.hairTypes.Has(Hashing.FNV1Hash(chosenType))) { hairTypeList[dash] = Hashing.FNV1Hash(chosenType); } XElement tp = dashCountElement.Element("types"); if (tp != null) { foreach (XElement currentType in tp.Elements()) { uint type = Hashing.FNV1Hash(currentType.Name.LocalName); try { IHairType hair = Hyperline.Instance.hairTypes.CreateNewHairType(type); if (hair != null) { hair.Read(currentType); hairList[dash][type] = hair; } else { Logger.Log(LogLevel.Warn, "Hyperline", "Hyperline contained invalid hair type " + currentType.Name); } } catch (Exception exception) { Logger.Log(LogLevel.Warn, "Hyperline", "Exception occured while loading hair type " + currentType.Name.LocalName + " dash count " + dash + "\n" + exception); } } } else { Logger.Log(LogLevel.Warn, "Hyperline", "XML file missing types for dash count " + dash); } } } } } else { Logger.Log(LogLevel.Warn, "Hyperline", "Hyperline settings XML missing dashs element."); } } else { Logger.Log(LogLevel.Warn, "Hyperline", "Hyperline settings XML missing root element."); } } catch (Exception exception) { Logger.Log(LogLevel.Error, "Hyperline", "Error while loading save file...\n" + exception.ToString()); } }