示例#1
0
    public void ReadPokemonDataTest()
    {
        var mockPokemonService      = new Mock <IPokemonService>();
        var mockModServiceContainer = new Mock <IModServiceContainer>();

        mockModServiceContainer.SetupGet(i => i.Pokemon).Returns(mockPokemonService.Object);

        var input = new Pokemon()
        {
            Name        = "Pikachu",
            Type1       = TypeId.Electric,
            Hp          = 20,
            IsLegendary = false,
        };

        mockPokemonService.Setup(i => i.Retrieve(15)).Returns(input);

        // Create

        string readPokemonDataTestFile = Path.Combine(TestScriptFolder, "ReadPokemonDataTest.lua");

        File.Exists(readPokemonDataTestFile).Should().BeTrue();

        var luaService = new LuaService(mockModServiceContainer.Object);

        // assertions done within script
        luaService.RunScript(readPokemonDataTestFile);
    }
示例#2
0
        public override void ConfigureServices()
        {
            var luaService = new LuaService(this);

            // Register Lua Service
            tmpEngine.AddService(typeof(LuaService).FullName, luaService);
        }
示例#3
0
    public void EnumerateByIdTest()
    {
        // this test is important because it was necessary to use Enumerable.Range()
        // rather than a generator to provide the IEnumerable
        // else luanet.each doesn't work

        var itemService = new ItemService(Path.Combine(TestModFolder, Constants.ItemRomPath));

        var mockModServiceContainer = new Mock <IModServiceContainer>();

        mockModServiceContainer.SetupGet(i => i.Item).Returns(itemService);

        string enumerateByIdTestFile = Path.Combine(TestScriptFolder, "EnumerateByIdTest.lua");

        File.Exists(enumerateByIdTestFile).Should().BeTrue();

        var luaService = new LuaService(mockModServiceContainer.Object);

        luaService.RunScript(enumerateByIdTestFile);

        int id = 0;

        foreach (var item in itemService.Enumerate())
        {
            item.Name.Should().Be(id.ToString());
            item.ShopPriceMultiplier.Should().Be(id);
            id++;
        }
    }
 public void OnStateLeave()
 {
     JW.Common.Log.LogD("Leave LuaVM GameState");
     LuaService.DestroyInstance();
     //
     JW.Framework.Audio.AudioService.GetInstance().StopAll();
     JW.Framework.Asset.AssetService.GetInstance().UnloadAllUsingAssets();
 }
 private void OnMainLuaLoaded(int st)
 {
     if (st == LuaLoader.LoadStateSuccess)
     {
         LuaService.GetInstance().InitFramework();
         LuaService.GetInstance().InitLogic();
         LuaService.GetInstance().StartGame();
     }
 }
示例#6
0
 public LuaTestLogic(
     IScriptEventRuntime eventRuntime,
     LuaService luaService,
     CommandService commandService,
     ILogger logger
     )
 {
     this.eventRuntime = eventRuntime;
     this.luaService   = luaService;
     this.logger       = logger;
     commandService.AddCommand("lua").Triggered += (source, args) => Init();
 }
示例#7
0
        public override void ConfigureEngine(Dictionary <string, string> metaData = null)
        {
            base.ConfigureEngine(metaData);

            luaService = new LuaService();

        #if !UNITY_WEBGL
            luaService.script.Options.DebugPrint = s => Debug.Log(s);
        #endif

            // Register Lua Service
            tmpEngine.chipManager.AddService(typeof(LuaService).FullName, luaService);
        }
示例#8
0
    /// 程序切前后台切换
    public static void OnApplicationPause(bool pause)
    {
        if (pause)
        {
            JW.Common.Log.LogD("OnApplicationPause - Application is sent to background.");

            if (LuaService.IsValidate())
            {
                if (LuaService.GetInstance().LuaFramework != null)
                {
                    LuaService.GetInstance().LuaFramework.DealAppEnterBackground();
                }
            }

            if (AudioService.IsValidate())
            {
                AudioService.GetInstance().CloseAll();
            }
            if (EventService.IsValidate())
            {
                EventService.GetInstance().SendEvent((uint)(EventId.ApplicationPause), new EventDeclare.ApplicationPauseArg()
                {
                    IsPause = true
                });
            }
        }
        else
        {
            JW.Common.Log.LogD("OnApplicationPause - Application is brought to foreground.");

            if (LuaService.IsValidate())
            {
                if (LuaService.GetInstance().LuaFramework != null)
                {
                    LuaService.GetInstance().LuaFramework.DealAppEnterForeground();
                }
            }

            if (AudioService.IsValidate())
            {
                AudioService.GetInstance().OpenAll();
            }
            if (EventService.IsValidate())
            {
                EventService.GetInstance().SendEvent((uint)(EventId.ApplicationPause), new EventDeclare.ApplicationPauseArg()
                {
                    IsPause = false
                });
            }
        }
    }
示例#9
0
 /// <summary>
 /// 统一驱动
 /// </summary>
 public static void Update()
 {
     //驱动输入
     ArcadeInputService.GetInstance().LogicUpdate();
     //驱动网络
     NetworkService.GetInstance().LogicUpdate();
     //Lua
     if (LuaService.IsValidate())
     {
         LuaService.GetInstance().LogicUpdate();
     }
     //UI
     UGUIRoot.GetInstance().CustomUpdate();
 }
示例#10
0
 /// <summary>
 /// 初始化Logic层
 /// </summary>
 /// <param name="initialize">初始化/反初始化</param>
 public static void InitLogic(bool initialize)
 {
     if (initialize)
     {
         //街机输入初始化
         ArcadeInputService.GetInstance();
         //模块初始化
         ModuleService.GetInstance();
         //注册C# 游戏模块
         ModuleService.GetInstance().Create <LaunchModule, UILaunchMediator>();
         ModuleService.GetInstance().Create <RegisterModule, UIRegisterMediator>();
         ModuleService.GetInstance().Create <UpdateModule, UIUpdateMediator>();
     }
     else
     {
         UGUIRoot.DestroyInstance();
         ModuleService.DestroyInstance();
         LuaService.DestroyInstance();
     }
 }
示例#11
0
    public LuaTestLogic(IScriptEventRuntime eventRuntime, LuaService luaService)
    {
        eventRuntime.LoadDefaultEvents();

        luaService.LoadDefaultDefinitions();

        luaService.LoadDefinitions <CustomMathDefinition>();
        luaService.LoadDefinitions <TestDefinition>();

        using FileStream testLua  = File.OpenRead("test.lua");
        using StreamReader reader = new StreamReader(testLua);
        try
        {
            luaService.LoadScript("test.lua", reader.ReadToEnd());
        }
        catch (InterpreterException ex)
        {
            System.Console.WriteLine("Failed to load script\n\t{0}", ex.DecoratedMessage);
        }
    }
示例#12
0
    public void EnumerateWarriorsTest()
    {
        var warriorService = new BaseWarriorService(Path.Combine(TestModFolder, Constants.BaseBushouRomPath));

        var mockModServiceContainer = new Mock <IModServiceContainer>();

        mockModServiceContainer.SetupGet(i => i.BaseWarrior).Returns(warriorService);

        string enumerateWarriorsTestFile = Path.Combine(TestScriptFolder, "EnumerateWarriorsTest.lua");

        File.Exists(enumerateWarriorsTestFile).Should().BeTrue();

        var luaService = new LuaService(mockModServiceContainer.Object);

        luaService.RunScript(enumerateWarriorsTestFile);

        foreach (var warrior in warriorService.Enumerate())
        {
            warrior.Wisdom.Should().Be(45);
            warrior.Speciality1.Should().Be(TypeId.Fire);
        }
    }
示例#13
0
        public object StartFile(string path)
        {
            if (path == null)
            {
                return(null);
            }

            object ret = LuaService.start(path);

            if (ret == null)
            {
                return(null);
            }

            LuaTable resultTable  = (LuaTable)ret;
            LuaTable luaTable     = (LuaTable)resultTable[1];
            string   luaTableName = (string)resultTable[2];

            RegisterLuaTable(luaTableName, luaTable);

            return(ret);
        }
示例#14
0
    public void ScriptInteractWithPokemonService()
    {
        var mockPokemonService      = new Mock <IPokemonService>();
        var mockModServiceContainer = new Mock <IModServiceContainer>();

        mockModServiceContainer.SetupGet(i => i.Pokemon).Returns(mockPokemonService.Object);

        var input = new Pokemon()
        {
            Type1       = TypeId.Grass,
            Hp          = 20,
            IsLegendary = false,
        };

        mockPokemonService.Setup(i => i.Retrieve(15)).Returns(input);

        // Create

        string setPropertySaveTestFile = Path.Combine(TestScriptFolder, "SetPropertyAndSaveTest.lua");

        File.Exists(setPropertySaveTestFile).Should().BeTrue();

        var luaService = new LuaService(mockModServiceContainer.Object);

        luaService.RunScript(setPropertySaveTestFile);

        // Test Changes Occurred

        mockPokemonService.Verify(i => i.Retrieve(15), Times.Once());
        mockPokemonService.Verify(i => i.Save(), Times.Once());

        input.Type1.Should().Be(TypeId.Electric);
        input.Hp.Should().Be(34);
        input.IsLegendary.Should().BeTrue();
        input.Evolutions.Should().ContainSingle().Which.Should().Be(PokemonId.Glaceon);
    }
 public void OnStateEnter(object usrData = null)
 {
     JW.Common.Log.LogD("Enter Login GameState");
     LuaService.GetInstance();
     LuaService.GetInstance().LoadMainLua(OnMainLuaLoaded);
 }
示例#16
0
 /// <summary>
 /// Initializes a new instance of the <see cref="LuaScriptToken"/> class.
 /// </summary>
 /// <param name="luaService">The lua execution service.</param>
 /// <param name="content">The application's content service.</param>
 public LuaScriptToken(LuaService luaService, ContentService content)
 {
     this.Lua     = luaService;
     this.Content = content;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="LuaScriptToken"/> class.
 /// </summary>
 /// <param name="luaService">The lua execution service.</param>
 public LuaScriptToken([NotNull] LuaService luaService)
 {
     _lua = luaService;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="LuaSnippetToken"/> class.
 /// </summary>
 /// <param name="luaService">The lua execution service.</param>
 public LuaSnippetToken(LuaService luaService)
 {
     this.Lua = luaService;
 }
示例#19
0
 private void Awake()
 {
     Instance = this;
 }
示例#20
0
 /// <summary>
 /// Initializes a new instance of the <see cref="LuaSnippetToken"/> class.
 /// </summary>
 /// <param name="luaService">The lua execution service.</param>
 public LuaSnippetToken(LuaService luaService)
 {
     _lua = luaService;
 }
示例#21
0
 /// <summary>
 /// Initializes a new instance of the <see cref="LuaScriptToken"/> class.
 /// </summary>
 /// <param name="luaService">The lua execution service.</param>
 public LuaScriptToken(LuaService luaService)
 {
     _lua = luaService;
 }
示例#22
0
 public LuaServiceTests()
 {
     this.Lua = new LuaService(new Mock <ContentService>().Object);
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="LuaSnippetToken"/> class.
 /// </summary>
 /// <param name="luaService">The lua execution service.</param>
 public LuaSnippetToken([NotNull] LuaService luaService)
 {
     _lua = luaService;
 }
 public ExecuteSnippetAsync()
 {
     _lua = new LuaService(new ContentService(FileSystemFactory.CreateContentFileSystem()));
 }
示例#25
0
        // ReSharper restore PrivateFieldCanBeConvertedToLocalVariable

        /// <summary>
        /// Initializes a new instance of the <see cref="AmbassadorClient"/> class.
        /// </summary>
        /// <param name="content">The content service.</param>
        public AmbassadorClient([NotNull] ContentService content)
        {
            this.Client = Type.GetType("Mono.Runtime") is null
                                ? new DiscordSocketClient()
                                : new DiscordSocketClient(new DiscordSocketConfig {
                WebSocketProvider = () => new WebSocketSharpProvider()
            });

            this.Client.Log += OnDiscordLogEvent;

            this.Commands      = new CommandService();
            this.Commands.Log += OnDiscordLogEvent;

            this.DiscordIntegration = new DiscordService();
            this.Content            = content;
            this.Commands           = new CommandService();
            this.OwnedEntities      = new OwnedEntityService();
            this.Roleplays          = new RoleplayService(this.Commands, this.OwnedEntities);
            this.Transformation     = new TransformationService(this.Content);

            this.Characters = new CharacterService(this.Commands, this.OwnedEntities, this.Content, this.Transformation);
            this.Characters.DiscoverPronounProviders();

            this.Feedback    = new UserFeedbackService();
            this.Dossiers    = new DossierService(this.Content);
            this.Interactive = new InteractiveService(this.Client);

            this.Lua   = new LuaService(this.Content);
            this.Kinks = new KinkService(this.Feedback);

            this.Permissions = new PermissionService();

            this.Privacy = new PrivacyService();

            this.Services = new ServiceCollection()
                            .AddSingleton(this.Client)
                            .AddSingleton(this.DiscordIntegration)
                            .AddSingleton(this.Content)
                            .AddSingleton(this.Commands)
                            .AddSingleton(this.Roleplays)
                            .AddSingleton(this.Characters)
                            .AddSingleton(this.Feedback)
                            .AddSingleton(this.Dossiers)
                            .AddSingleton(this.Interactive)
                            .AddSingleton(this.Transformation)
                            .AddSingleton(this.Lua)
                            .AddSingleton(this.Kinks)
                            .AddSingleton(this.Permissions)
                            .AddSingleton(this.Privacy)
                            .AddDbContextPool <GlobalInfoContext>(builder => GlobalInfoContext.ConfigureOptions(builder))
                            .BuildServiceProvider();

            this.Transformation = this.Transformation
                                  .WithDescriptionBuilder
                                  (
                ActivatorUtilities.CreateInstance <TransformationDescriptionBuilder>(this.Services)
                                  );

            this.Client.MessageReceived += OnMessageReceived;
            this.Client.MessageUpdated  += OnMessageUpdated;
        }