Пример #1
0
        private Sound parseSound(LuaArgs args, int index)
        {
            LuaTable table            = args.GetTable(index);
            string   waveform         = table.IsNil("waveform") ? "square" : table.GetString("waveform");
            float    volume           = table.IsNil("volume") ? 1.0f : table.GetFloat("volume");
            float    duty             = table.IsNil("duty") ? 0.5f : table.GetFloat("duty");
            float    duration         = table.GetFloat("duration");
            float    attack           = table.IsNil("attack") ? 0.0f : table.GetFloat("attack");
            float    decay            = table.IsNil("decay") ? 0.0f : table.GetFloat("decay");
            float    frequency        = table.GetFloat("frequency");
            float    slide            = table.IsNil("slide") ? 0.0f : table.GetFloat("slide");
            float    vibratoDepth     = table.IsNil("vibrato_depth") ? 0.0f : table.GetFloat("vibrato_depth");
            float    vibratoFrequency = table.IsNil("vibrato_frequency") ? 0.0f : table.GetFloat("vibrato_frequency");
            bool     loop             = table.IsNil("loop") ? false : table.GetBool("loop");

            var sound = new Sound();

            sound.Waveform         = ParseWaveform(waveform);
            sound.Volume           = Clamp(volume, 0.0f, 1.0f);
            sound.Duty             = Clamp(duty, 0.0f, 1.0f);
            sound.Attack           = Math.Max(attack, 0.0f);
            sound.Duration         = Math.Max(duration, 0.0f);
            sound.Decay            = Math.Max(decay, 0.0f);
            sound.Frequency        = Math.Max(frequency, 0.0f);
            sound.Slide            = slide;
            sound.VibratoDepth     = Math.Max(vibratoDepth, 0.0f);
            sound.VibratoFrequency = Math.Max(vibratoFrequency, 0.0f);
            sound.Loop             = loop;

            return(sound);
        }
Пример #2
0
        private TileCoordinates GetCoordinates(LuaArgs args, int index)
        {
            var table = args.GetTable(index);

            return(new TileCoordinates(
                       table.GetInt("x"),
                       table.GetInt("y"),
                       table.GetInt("z")
                       ));
        }
Пример #3
0
        public LuaArgs isPlacementSelected(LuaArgs args)
        {
            var table    = args.GetTable(0);
            var location = new TileCoordinates(
                table.GetInt("x"),
                table.GetInt("y"),
                table.GetInt("z")
                );
            var marker = ((InGameState)m_state).SelectedSpawnMarker;

            if (marker != null && marker.Location == location)
            {
                return(new LuaArgs(true));
            }
            return(new LuaArgs(false));
        }
Пример #4
0
        public LuaArgs time(LuaArgs args)
        {
            DateTime dateTime;

            if (args.IsNil(0))
            {
                var clockDevice = FindClock();
                if (clockDevice != null)
                {
                    dateTime = clockDevice.Time;
                }
                else
                {
                    dateTime = DateFromTime(0.0);
                }
            }
            else
            {
                var table = args.GetTable(0);
                int year  = table.GetInt("year");
                int month = table.GetInt("month");
                int day   = table.GetInt("day");
                int hour  = table.IsNil("hour") ? 12 : table.GetInt("hour");
                int min   = table.IsNil("min") ? 0 : table.GetInt("min");
                int sec   = table.IsNil("sec") ? 0 : table.GetInt("sec");
                if (!table.IsNil("isdst"))
                {
                    table.GetBool("isdst");
                }
                bool isutc = table.IsNil("isutc") ? false : table.GetBool("isutc");
                try
                {
                    dateTime = new DateTime(year, month, day, hour, min, sec, isutc ? DateTimeKind.Utc : DateTimeKind.Local);
                }
                catch (ArgumentOutOfRangeException)
                {
                    throw new LuaError("Invalid date");
                }
            }
            var seconds = TimeFromDate(dateTime);

            return(new LuaArgs(seconds));
        }
Пример #5
0
        public LuaArgs getPlacementDelay(LuaArgs args)
        {
            var table    = args.GetTable(0);
            var location = new TileCoordinates(
                table.GetInt("x"),
                table.GetInt("y"),
                table.GetInt("z")
                );

            foreach (Entity e in m_state.Level.Entities)
            {
                if (!e.Dead && e is SpawnMarker)
                {
                    var marker = (SpawnMarker)e;
                    if (marker.Location == location)
                    {
                        return(new LuaArgs(marker.SpawnDelay));
                    }
                }
            }
            return(LuaArgs.Empty);
        }