private void Start() { // Database loading Debug.Log("Loading the game database...", gameObject); database = new Database.Database(); const string filesPrefix = "Assets/Resources/Core"; database = database.AddDataFile($"{filesPrefix}/events.json", DataFileType.Event) .AddDataFolder("Assets/Resources/Core/news", DataFileType.News) .AddDataFile($"{filesPrefix}/genres.json", DataFileType.GameGenre) .AddDataFile($"{filesPrefix}/themes.json", DataFileType.GameTheme) .AddDataFolder("Assets/Resources/Core/platforms", DataFileType.GamingPlatform) .AddDataFolder("Assets/Resources/Core/games", DataFileType.GameSeries) .AddDataFile($"{filesPrefix}/engine_features.json", DataFileType.EngineFeature) .AddDataFile($"{filesPrefix}/rooms.json", DataFileType.Room) .AddDataFile($"{filesPrefix}/objects.json", DataFileType.RoomObject) .AddDataFile($"{filesPrefix}/skills.json", DataFileType.Skill) .AddDataFile($"{filesPrefix}/hiring.json", DataFileType.HiringMethod) .AddDataFolder("Assets/Resources/Core/names", DataFileType.CommonNames) .Load(); if (database == null) { Debug.LogError($"World.Start() : Database loading error."); #if UNITY_EDITOR UnityEditor.EditorApplication.isPlaying = false; #endif Application.Quit(); return; } database.PrintDatabaseInfo(); Debug.Log("Instanciating the game world...", gameObject); dayPercentage = 0f; gameDateTime = new DateTime(gameStartYear, gameStartMonth, gameStartDay); globalMarket.Init(gameDateTime, database.GameSeries.Collection); worldController.OnGameStarted(database, gameDateTime, playerCompany); worldController.OnDateModified(gameDateTime); worldController.OnPlayerCompanyModified(); var employeesParentObject = transform.Find("Employees"); for (int i = 0; i < employeesParentObject.childCount; i++) { playerCompany.AddEmployee(employeesParentObject.GetChild(i).GetComponent <Employee>()); } gameMenu.ShowMenu(); }
public void OnGameStarted(Database.Database db, DateTime date, GameDevCompany playedCompany) { database = db; playerCompany = playedCompany; gameDateTime = date; // load script functions scriptFunctions = Function <bool> .DefaultFunctions(); scriptGlobalVariables = GameVariables(); // additional local variables Assert.IsTrue(ScriptContext.AddLocalVariable(this, "Employee_HiringCost", new FloatSymbol(0), true)); Assert.IsTrue(ScriptContext.AddLocalVariable(this, "Employee_Salary", new FloatSymbol(0), true)); // parser context ParserContext parserContext = new ParserContext { Grammar = Grammar.DefaultGrammar(), LocalVariables = scriptVariables, GlobalVariables = scriptGlobalVariables, Functions = scriptFunctions, }; // test const string script = @" //{ let b: int = b; //} b "; Executable executable = Executable.FromScript(script, parserContext); if (executable != null) { int result; executable.ExecuteExpecting(this, out result); Debug.LogWarning($"===> executable result = {result}"); } // scripts parsing eventsController.CreateEvents(db.Events.Collection, parserContext); playerCompany.Init(database.Skills, parserContext); engineFeaturesController.CreateFeatures(db.EngineFeatures.Collection, parserContext); engineFeaturesController.CheckFeatures(this); newsController.CreateNews(db.News.Collection, date); // events OnInit calls Assert.IsTrue(eventsController.InitEvents(this)); float hiringCost; Employee employee = playedCompany.EmployeesManager.GenerateRandomEmployee( this, db.HiringMethod.FindById("CompSciGraduates"), db.Names.FindById("CommonNamesUSA"), db.Skills, out hiringCost); playedCompany.AddEmployee(employee); Debug.Log($"Generated Random Employee : hiring cost = {hiringCost}."); }