private void RunActions(List <Element> elements) { elements.ForEach(e => { _element = e; if (_element is MusicBlock) { MusicBlock block = (MusicBlock)_element; HandleClef(block.Clef); } if (!ElementActionDictionary.TryGetValue(e.GetType(), out var action)) { return; } if (action != HandleAlternatives) { CheckEndingRepeat(); } action(); }); }
private void CreateNormalMusicBlock(MusicBlock musicBlock) { // Music block HandleMarker(Marker.MusicBlockStart); RunActions(musicBlock.Elements); HandleMarker(Marker.MusicBlockEnd); }
private void UpdateSources(MusicBlock block) { switch (engineStatus) { case Source.JustZero: sources[1].clip = block.clip; clip = block.clip; clipWaiting = true; sourceWaiting = Source.JustZero; break; case Source.JustOne: sources[0].clip = block.clip; clip = block.clip; clipWaiting = true; sourceWaiting = Source.JustOne; break; case Source.Both: clipWaiting = true; sourceWaiting = Source.Both; break; case Source.Neither: clip = block.clip; for (int i = 0; i < 2; i++) { sources[i].clip = clip; } clipWaiting = false; sourceWaiting = Source.Neither; break; } }
/// <summary> /// Plays the given music block. /// </summary> /// <param name='musicName'> /// Music block name. /// </param> public void PlayMusic(string musicName) { MusicBlock musicBlock = GetBlock(musicName) as MusicBlock; if (musicBlock) { musicBlock.Play(); RegisterFinishedEvent(musicBlock); } }
/// <summary> /// Tests if a music block is equal to a block /// </summary> /// <param name="b">The block</param> /// <returns>True if equal in value</returns> public bool EqualsBlock(Block b) { if (b is MusicBlock) { MusicBlock mB = (MusicBlock)b; return(mB.X == X && mB.Y == Y && mB.Layer == Layer && mB.ID == ID && mB.MusicID == MusicID); } return(false); }
public void NextBlock(MusicBlock block) { if (block == currentBlock) { return; } currentBlock = block; UpdateSources(block); }
private void CreateAlternativesMusicBlock(MusicBlock musicBlock) { HandleMarker(Marker.AlternativeStart); int differenceOctaves = 0; musicBlock.Elements.ForEach(e => { //if (e is MusicElement && musicBlock.Elements.ElementAt(0) != e) if (e is MusicElement) { MusicElement musicElement = (MusicElement)e; differenceOctaves += musicElement.Octaves; } }); if (_isCreatingMidiFile) { // Repeat already in sequence, add alternative _isHandlingAlternativeOption = true; RunActions(musicBlock.Elements); _isHandlingAlternativeOption = false; } else { // Midi player int runs = 1; if (_currentAlternative == 1) { runs = 1 + _repeats - _alternatives; } for (int i = 1; i <= runs; i++) { // Add repeat and alternative to sequence AddRepeatForMidiPlayer(); _isHandlingAlternativeOption = true; RunActions(musicBlock.Elements); _isHandlingAlternativeOption = false; if (runs > 1 && i < runs) { _startHeight += 12 * (differenceOctaves * -1); } } _currentAlternative++; } }
private void HandleMusicBlock() { MusicBlock musicBlock = (MusicBlock)_element; HandleTime(musicBlock.TimeSignature); if (!_isHandlingAlternatives || _isHandlingAlternativeOption) { this.CreateNormalMusicBlock(musicBlock); } else { this.CreateAlternativesMusicBlock(musicBlock); } HandleMarker(Marker.MusicBlockEnd); }
/// <summary> /// Processes the message /// </summary> /// <param name="connectionBase">The connection base</param> /// <param name="message">The playerio message</param> /// <param name="handled">Whether the message was already handled</param> public void Process(ConnectionBase connectionBase, Message message, bool handled) { WorldConnection worldCon = (WorldConnection)connectionBase; World world = worldCon.World; int x = message.GetInt(0); int y = message.GetInt(1); BlockID blockId = (BlockID)message.GetInt(2); uint musicId = message.GetUInt(3); MusicBlock musicBlock = null; if (message.Count > 4) { int userId = message.GetInt(4); WorldPlayer player = worldCon.Players.GetPlayer(userId); musicBlock = new MusicBlock(worldCon, blockId, x, y, musicId) { Placer = player }; } else { musicBlock = new MusicBlock(worldCon, blockId, x, y, musicId); } if (!handled) { world.SetBlock(musicBlock); } worldCon.CheckBlock(musicBlock); MusicBlockEvent musicBlockEvent = new MusicBlockEvent() { Raw = message, MusicBlock = musicBlock }; connectionBase.RaiseServerEvent <MusicBlockEvent>(musicBlockEvent); }
/// <summary> /// Deserializes the world blocks from an Everybody Edits world based on a <see cref="Message"/> object. /// </summary> /// <param name="m">The Message object that contains the data about the Everybody Edits world.</param> /// <param name="worldWidth">The width of the Everybody Edits world.</param> /// <param name="worldHeight">The height of the Everybody Edits world.</param> /// <returns> /// A 3-dimensional array of type <see cref="Block"/>. The first dimension represents layer, the second represents horizontal coordinate, and the third represents /// vertical coordinate. /// </returns> public static Block[,,] DeserializeBlocks(Message m, int worldWidth, int worldHeight) { if (!CanDeserializeBlocks(m)) { throw new Exception($"Can not deserialize world blocks from \"{m.Type}\" message."); } Block[,,] worldBlocks = InitalizeWorldBlocksArray(2, worldWidth, worldHeight); uint currentBlockChunk = GetWorldStart(m) + 1; while (m[currentBlockChunk] as string != EverybodyEditsMessage.WorldEnd) { int blockId = m.GetInt(currentBlockChunk); int layer = m.GetInt(currentBlockChunk + 1); byte[] xPositions = m.GetByteArray(currentBlockChunk + 2); byte[] yPositions = m.GetByteArray(currentBlockChunk + 3); uint chunkArgsRead = 4; for (int i = 0; i < xPositions.Length; i += 2) { int x = (xPositions[i] << 8) | (xPositions[i + 1]); int y = (yPositions[i] << 8) | (yPositions[i + 1]); switch (blockId) { case 77: case 83: case 1520: { int soundId = m.GetInt(currentBlockChunk + 4); worldBlocks[layer, x, y] = new MusicBlock(blockId, soundId); chunkArgsRead = 5; } break; case 113: case 184: case 185: case 467: case 1619: case 1620: case 1079: case 1080: { uint switchId = m.GetUInt(currentBlockChunk + 4); worldBlocks[layer, x, y] = new SwitchBlock(blockId, switchId); chunkArgsRead = 5; } break; case 242: case 381: { int portalId = m.GetInt(currentBlockChunk + 4); int targetId = m.GetInt(currentBlockChunk + 5); int rotationId = m.GetInt(currentBlockChunk + 6); worldBlocks[layer, x, y] = new PortalBlock(blockId, portalId, targetId, rotationId); chunkArgsRead = 7; } break; case 1582: { int spawnId = m.GetInt(currentBlockChunk + 4); worldBlocks[layer, x, y] = new WorldPortalSpawnBlock(blockId, spawnId); chunkArgsRead = 5; } break; case 374: { string targetWorldId = m.GetString(currentBlockChunk + 4); int targetSpawn = m.GetInt(currentBlockChunk + 5); worldBlocks[layer, x, y] = new WorldPortalBlock(blockId, targetWorldId, targetSpawn); chunkArgsRead = 6; } break; case 385: { string text = m.GetString(currentBlockChunk + 4); int rotationId = m.GetInt(currentBlockChunk + 5); worldBlocks[layer, x, y] = new SignBlock(blockId, text, rotationId); chunkArgsRead = 6; } break; case 417: case 418: case 419: case 420: case 423: case 453: case 461: case 1517: case 1584: { int effectId = m.GetInt(currentBlockChunk + 4); worldBlocks[layer, x, y] = new EffectBlock(blockId, effectId); chunkArgsRead = 5; } break; case 421: case 422: { int duration = m.GetInt(currentBlockChunk + 4); worldBlocks[layer, x, y] = new TimedEffectBlock(blockId, duration); chunkArgsRead = 5; } break; case 1550: case 1551: case 1552: case 1553: case 1554: case 1556: case 1557: case 1558: case 1571: case 1572: case 1573: case 1576: case 1579: { string name = m.GetString(currentBlockChunk + 4); string[] messages = { m.GetString(currentBlockChunk + 5), m.GetString(currentBlockChunk + 6), m.GetString(currentBlockChunk + 7) }; worldBlocks[layer, x, y] = new NonPlayableCharacterBlock(blockId, name, messages); chunkArgsRead = 8; } break; case 273: case 275: case 276: case 277: case 279: case 280: case 327: case 328: case 329: case 338: case 339: case 340: case 361: case 376: case 377: case 378: case 379: case 380: case 438: case 439: case 440: case 447: case 448: case 449: case 451: case 452: case 456: case 457: case 458: case 464: case 465: case 471: case 499: case 1001: case 1002: case 1003: case 1004: case 1116: case 1117: case 1118: case 1119: case 1120: case 1121: case 1122: case 1123: case 1124: case 1125: case 1041: case 1042: case 1043: case 1052: case 1053: case 1054: case 1055: case 1056: case 1092: case 1134: case 1135: case 1140: case 1141: case 1500: case 1502: case 1506: case 1507: case 1535: case 1536: case 1537: case 1538: case 1155: case 1160: case 1581: case 1587: case 1588: case 1592: case 1593: case 1594: case 1595: case 1596: case 1597: case 1605: case 1606: case 1607: case 1608: case 1609: case 1610: case 1611: case 1612: case 1613: case 1614: case 1615: case 1616: case 1617: case 1633: { int morphId = m.GetInt(currentBlockChunk + 4); worldBlocks[layer, x, y] = new MorphableBlock(blockId, morphId); chunkArgsRead = 5; } break; default: { worldBlocks[layer, x, y] = new Block(blockId); chunkArgsRead = 4; } break; } } currentBlockChunk += chunkArgsRead; } return(worldBlocks); }
private void HandleMusicBlockStart() { MusicBlock musicBlock = new MusicBlock(); AddElement(musicBlock); }
/// <summary> /// Deserialize's the world data /// </summary> /// <param name="message">The message</param> internal void Deserialize(Message message) { // Find the start of the init message's world data uint start = 0; for (uint i = 0; i < message.Count; i++) { if (message[i] is string) { if (string.Compare(message.GetString(i), "ws", false) == 0) { start = i + 1; break; } } } uint index = start; try { while (index < message.Count) { if (message[index] is string) { if (string.Compare(message.GetString(index), "we", false) == 0) { break; } } int blockInt = message.GetInt(index++); int layerInt = message.GetInt(index++); byte[] bytesX = message.GetByteArray(index++); byte[] bytesY = message.GetByteArray(index++); List <FluidPoint> locations = GetLocations(bytesX, bytesY); BlockID blockId = (BlockID)blockInt; Layer layer = (Layer)layerInt; switch (blockId) { case BlockID.HazardSpike: case BlockID.DecorSciFi2013BlueSlope: case BlockID.DecorSciFi2013BlueStraight: case BlockID.DecorSciFi2013YellowSlope: case BlockID.DecorSciFi2013YellowStraight: case BlockID.DecorSciFi2013GreenSlope: case BlockID.DecorSciFi2013GreenStraight: case BlockID.OneWayCyan: case BlockID.OneWayPink: case BlockID.OneWayRed: case BlockID.OneWayYellow: { Rotation rotation = (Rotation)message.GetUInt(index++); foreach (FluidPoint p in locations) { RotatableBlock rotatableBlock = new RotatableBlock(blockId, p.X, p.Y, rotation); SetBlock(rotatableBlock); } } break; case BlockID.CoinDoor: case BlockID.BlueCoinDoor: case BlockID.CoinGate: case BlockID.BlueCoinGate: { uint goal = message.GetUInt(index++); foreach (FluidPoint p in locations) { CoinBlock door = new CoinBlock(blockId, p.X, p.Y, goal); SetBlock(door); } } break; case BlockID.MusicDrum: case BlockID.MusicPiano: { uint musicId = message.GetUInt(index++); foreach (FluidPoint p in locations) { MusicBlock musicBlock = new MusicBlock(blockId, p.X, p.Y, musicId); SetBlock(musicBlock); } } break; case BlockID.Portal: case BlockID.InvisiblePortal: { Rotation rotation = (Rotation)message.GetUInt(index++); uint portalid = message.GetUInt(index++); uint portaltarget = message.GetUInt(index++); foreach (FluidPoint p in locations) { Portal portal = new Portal(blockId, p.X, p.Y, rotation, portalid, portaltarget); SetBlock(portal); } } break; case BlockID.SwitchPurple: case BlockID.PurpleSwitchDoor: case BlockID.PurpleSwitchGate: { uint goal = message.GetUInt(index++); foreach (FluidPoint p in locations) { PurpleBlock purpleBlock = new PurpleBlock(blockId, p.X, p.Y, goal); SetBlock(purpleBlock); } } break; case BlockID.DeathDoor: case BlockID.DeathGate: { uint goal = message.GetUInt(index++); foreach (FluidPoint p in locations) { DeathBlock deathBlock = new DeathBlock(blockId, p.X, p.Y, goal); SetBlock(deathBlock); } } break; case BlockID.WorldPortal: { string targetId = message.GetString(index++); foreach (FluidPoint p in locations) { WorldPortal worldPortal = new WorldPortal(blockId, p.X, p.Y, targetId); SetBlock(worldPortal); } } break; case BlockID.DecorSign: { string text = message.GetString(index++); foreach (FluidPoint p in locations) { TextBlock textBlock = new TextBlock(blockId, p.X, p.Y, text); SetBlock(textBlock); } } break; case BlockID.DecorLabel: { string text = message.GetString(index++); string hexColor = message.GetString(index++); foreach (FluidPoint p in locations) { LabelBlock labelBlock = new LabelBlock(blockId, p.X, p.Y, text, hexColor); SetBlock(labelBlock); } } break; default: foreach (FluidPoint p in locations) { Block block = new Block(blockId, layer, p.X, p.Y); SetBlock(block); } break; } } } catch { m_Client.Log.Add(FluidLogCategory.Message, "World init deserializer is out of date. Check for an update."); } }
/// <summary> /// Deserialize's the world data /// </summary> /// <param name="worldObject">The world data as a database array</param> private void Deserialize(DatabaseObject worldObject) { Owner = GetValue <string>(worldObject, "owner"); Width = GetValue <int>(worldObject, "width", 200); Height = GetValue <int>(worldObject, "height", 200); Title = GetValue <string>(worldObject, "name"); Plays = GetValue <int>(worldObject, "plays"); WorldType = (WorldType)GetValue <int>(worldObject, "type", 3); AllowPotions = GetValue <bool>(worldObject, "allowpotions", true); Woots = GetValue <int>(worldObject, "woots", 0); TotalWoots = GetValue <int>(worldObject, "totalwoots", 0); Visible = GetValue <bool>(worldObject, "visible", true); BackgroundColor = new FluidColor(GetValue <uint>(worldObject, "backgroundColor", 0)); //Check is worlddata is present if (!worldObject.Contains("worlddata")) { return; } CreateEmptyWorld(); DatabaseArray databaseArray = (DatabaseArray)worldObject["worlddata"]; IEnumerable <object> databaseEnum = (IEnumerable <object>)databaseArray; using (IEnumerator <object> enumerator = databaseEnum.GetEnumerator()) { while (enumerator.MoveNext()) { DatabaseObject blockData = (DatabaseObject)enumerator.Current; byte[] xBytes = blockData.GetBytes("x"); byte[] yBytes = blockData.GetBytes("y"); BlockID blockId = (BlockID)blockData.GetUInt("type"); for (int i = 0; i < xBytes.Length; i += 2) { int x = xBytes[i] << 8 | xBytes[i + 1]; int y = yBytes[i] << 8 | yBytes[i + 1]; if (blockData.Contains("layer")) { Layer layer = (Layer)blockData.GetInt("layer"); switch (blockId) { case BlockID.HazardSpike: case BlockID.DecorSciFi2013BlueSlope: case BlockID.DecorSciFi2013BlueStraight: case BlockID.DecorSciFi2013YellowSlope: case BlockID.DecorSciFi2013YellowStraight: case BlockID.DecorSciFi2013GreenSlope: case BlockID.DecorSciFi2013GreenStraight: case BlockID.OneWayCyan: case BlockID.OneWayPink: case BlockID.OneWayRed: case BlockID.OneWayYellow: { Rotation rotation = (Rotation)blockData.GetUInt("rotation"); RotatableBlock rotatableBlock = new RotatableBlock(blockId, x, y, rotation); SetBlock(rotatableBlock); } break; case BlockID.CoinDoor: case BlockID.BlueCoinDoor: case BlockID.CoinGate: case BlockID.BlueCoinGate: { uint goal = blockData.GetUInt("goal"); CoinBlock door = new CoinBlock(blockId, x, y, goal); SetBlock(door); } break; case BlockID.MusicDrum: case BlockID.MusicPiano: { uint musicId = blockData.GetUInt("id"); MusicBlock musicBlock = new MusicBlock(blockId, x, y, musicId); SetBlock(musicBlock); } break; case BlockID.Portal: case BlockID.InvisiblePortal: { Rotation rotation = (Rotation)blockData.GetUInt("rotation"); uint portalid = blockData.GetUInt("id"); uint portaltarget = blockData.GetUInt("target"); Portal portal = new Portal(blockId, x, y, rotation, portalid, portaltarget); SetBlock(portal); } break; case BlockID.SwitchPurple: case BlockID.PurpleSwitchDoor: case BlockID.PurpleSwitchGate: { uint goal = 0; if (blockData.Contains("goal")) { goal = blockData.GetUInt("goal"); } PurpleBlock purpleBlock = new PurpleBlock(blockId, x, y, goal); SetBlock(purpleBlock); } break; case BlockID.DeathDoor: case BlockID.DeathGate: { uint goal = blockData.GetUInt("goal"); DeathBlock deathBlock = new DeathBlock(blockId, x, y, goal); SetBlock(deathBlock); } break; case BlockID.WorldPortal: { string targetId = blockData.GetString("target"); WorldPortal worldPortal = new WorldPortal(blockId, x, y, targetId); SetBlock(worldPortal); } break; case BlockID.DecorSign: { string text = blockData.GetString("text"); TextBlock textBlock = new TextBlock(blockId, x, y, text); SetBlock(textBlock); } break; case BlockID.DecorLabel: { string text = blockData.GetString("text"); if (blockData.Contains("text_color")) { string hexColor = blockData.GetString("text_color"); LabelBlock labelBlock = new LabelBlock(blockId, x, y, text, hexColor); SetBlock(labelBlock); } else { LabelBlock labelBlock = new LabelBlock(blockId, x, y, text); SetBlock(labelBlock); } } break; default: Block block = new Block(blockId, layer, x, y); SetBlock(block); break; } } } } } IsLoaded = true; }