Skip to content

Problem with CommandLineParser #462

@ghost

Description

Hello everyone, nice idea!

I am trying to parse but my dll is external and it will pass method with CommandLine's reference from external dll and It doesn't see like GameWindow of OpenTK I will try width and height.

example:
myapp.exe is default size 1024 768.

myapp.exe -width 1200 -height 768

Example my code:

using CommandLine;
using OpenTK;

namespace Engine
{
    public class Client
    {
        private SDLWindow game;

        public void Host(string[] args)
        {
            game = new SDLWindow();
            var hlCommandOpts = new HLCommandOptions();
            if(Parser.Default.ParseArguments(args, hlCommandOpts))
            {
                // -width
                if (hlCommandOpts.Width != 0)
                    game.Width = hlCommandOpts.Width;

                // -height
                if (hlCommandOpts.Height != 0)
                    game.Height = hlCommandOpts.Height;

            }
            else
            {
                game.Width = 1024;
                game.Height = 768;
            }
            game.Run(60);
        }

        private sealed class SDLWindow : GameWindow
        {
            public SDLWindow()
            {
                WindowBorder = WindowBorder.Fixed;
                //Location = new Point((SystemInformation.PrimaryMonitorSize.Width / 2) - (Width / 2), (SystemInformation.PrimaryMonitorSize.Height / 2) - (Height / 2));
            }
        }

        private class HLCommandOptions
        {
            [Option("-width", Required = true)]
            public int Width
            {
                get; set;
            }

            [Option("-height", Required = true)]
            public int Height
            {
                get; set;
            }

            [Option("-game", Required = true)]
            public string GameDir
            {
                get; set;
            }
        }
    }
}

is Engine.dll and
my myapp

using System;
using System.Reflection;

namespace myapp
{
    class Program
    {
        static void Main(string[] args)
        {
            var DLL = Assembly.LoadFile(AppDomain.CurrentDomain.BaseDirectory + "Engine.dll");
            var class1Type = DLL.GetType("Engine.Client");
            var c = Activator.CreateInstance(class1Type);
            var method = class1Type.GetMethod("Host");
            method.Invoke(c, new object[] { args });
        }
    }
}

Run GameWindow normal with current width 1024 and current height 768.
It doesn't see for changing width and height? If I change width and height via powershell example
./myapp.exe -width 800 -height 640
than game window doesn't change - If I use this
game.width = options.width;
game.height = options.height;

Is it wrong or it doesn't support for external dll?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions