using System; using System.Collections.Generic; using System.Text; using System.Windows.Forms; using Rmake.API.Interfaces; using Rmake.API.Interfaces.UI; using Rmake.API.Realizations.UI; using Rmake.Model; using Rmake.Model.Engine; using IronPython.Hosting; using Rmake.API.Interfaces.Enums; using Rmake.Framework.Logging; using Rmake.API.Interfaces.Extensions; using Rmake.API.Interfaces.Model; using Rmake.Model.Maps; using System.Drawing; namespace Rmake.API.Realizations { public class EngineAPIImpl : IEngineAPI { private EngineWindowImpl engineWindow = null; private PlayingGame game = null; private PythonEngine engine = null; private GameController controller = null; private Control renderTarget = null; public EngineAPIImpl(PlayingGame game, Control renderTarget, GameController controller) { this.game = game; this.controller = controller; this.renderTarget = renderTarget; this.engineWindow = new EngineWindowImpl(this, game, renderTarget); this.engine = new PythonEngine(); this.engine.Globals.Add("common_api", this); this.engine.Globals.Add("result", "true"); this.engine.Globals.Add("message", MessageTypes.Nothing); } #region IEngineAPI メンバ public IEngineWindow EngineWindow { get { return engineWindow; } } public Rmake.API.Interfaces.Model.IGame Game { get { return game; } } public void CloseGame() { try { controller.IsExit = true; } catch (Exception ex) { Logger.Fatal(ex); } } public IProcessor DoScript(string script) { try { // 変数の設定 engine.Globals["common_api"] = this; engine.Globals["script_processor"] = null; // Script の実行 engine.Execute(script); IProcessor result = engine.Globals["script_processor"] as IProcessor; return result; } catch (Exception ex) { MessageBox.Show(ex.ToString(), "Rmake", MessageBoxButtons.OK, MessageBoxIcon.Information); Logger.Fatal(ex); } return null; } public IProcessor DoScriptFile(String filename) { try { // 変数の設定 engine.Globals["common_api"] = this; engine.Globals["script_processor"] = null; // Script の実行 engine.ExecuteFile(filename); IProcessor result = engine.Globals["script_processor"] as IProcessor; return result; } catch (Exception ex) { MessageBox.Show(ex.ToString(), "Rmake", MessageBoxButtons.OK, MessageBoxIcon.Information); Logger.Fatal(ex); } return null; } public void SetCurrentMap(IMap map) { try { Map model = map as Map; if (model != null) { this.engineWindow.Renderer.InitializeMapOnEngine(model); this.engineWindow.Renderer.Render(); } } catch (Exception ex) { Logger.Fatal(ex); } } public void SetCurrentLocation(IMap map, int layerIndex, int x, int y) { try { this.SetCurrentMap(map); this.game.CurrentParty.CurrentLocation.Position = new Point((x - 9) * 32 - 16, (y - 7) * 32);//336, 240 this.game.CurrentParty.CurrentLocation.LayerIndex = layerIndex; } catch (Exception ex) { Logger.Fatal(ex); } } #endregion } }