コード例 #1
0
 public static void WriteEmpty(PythonWriter pw)
 {
     pw.WriteTuple(4);
     pw.WriteNoneStruct();
     pw.WriteNoneStruct();
     pw.WriteNoneStruct();
     pw.WriteNoneStruct();
 }
コード例 #2
0
 public void Write(PythonWriter pw)
 {
     pw.WriteTuple(4);
     pw.WriteInt(Red);
     pw.WriteInt(Green);
     pw.WriteInt(Blue);
     pw.WriteInt(Alpha);
 }
コード例 #3
0
ファイル: AppearanceData.cs プロジェクト: zaklaus/Rasa.NET
        public void Write(PythonWriter pw)
        {
            pw.WriteInt(SlotId);

            pw.WriteTuple(2);
            pw.WriteInt(ClassId);
            pw.WriteStruct(Color);
        }
コード例 #4
0
 public override void Write(PythonWriter pw)
 {
     pw.WriteTuple(1);
     pw.WriteList(ContextIdList.Count);
     foreach (var contextId in ContextIdList)
     {
         pw.WriteUInt(contextId);
     }
 }
コード例 #5
0
ファイル: AppearanceData.cs プロジェクト: vitalyo7/Rasa.NET
        public void Write(PythonWriter pw)
        {
            pw.WriteInt((int)SlotId);

            pw.WriteTuple(3);
            pw.WriteUInt(Class);
            pw.WriteStruct(Color);

            Color.WriteEmpty(pw);
        }
コード例 #6
0
        private static string processNodes(PythonWriter parentWriter, IEnumerable <SyntaxNode> nodes)
        {
            PythonWriter pyWriter = new PythonWriter(parentWriter.IndentSize);

            foreach (var node in nodes)
            {
                pyWriter.Append(processNode(pyWriter, node));
            }

            return(pyWriter.ToString());
        }
コード例 #7
0
 public override void Write(PythonWriter pw)
 {
     pw.WriteTuple(5);
     pw.WriteUInt(ContextId);
     pw.WriteUInt(InstanceId);
     pw.WriteUInt(Version);
     pw.WriteTuple(3);
     pw.WriteDouble(Position.X);
     pw.WriteDouble(Position.Y);
     pw.WriteDouble(Position.Z);
     pw.WriteDouble(Rotation);
 }
コード例 #8
0
 public override void Write(PythonWriter pw)
 {
     pw.WriteTuple(2);
     pw.WriteTuple(3);
     pw.WriteDouble(Position.X);
     pw.WriteDouble(Position.Y);
     pw.WriteDouble(Position.Z);
     pw.WriteTuple(4);
     pw.WriteDouble(Rotation.X);
     pw.WriteDouble(Rotation.Y);
     pw.WriteDouble(Rotation.Z);
     pw.WriteDouble(Rotation.W);
 }
コード例 #9
0
        public override void Write(PythonWriter pw)
        {
            pw.WriteTuple(1);
            pw.WriteDictionary(9);

            pw.WriteString("SlotId");
            pw.WriteUInt(SlotId);

            pw.WriteString("IsSelected");
            pw.WriteInt(IsSelected ? 1 : 0);

            pw.WriteString("BodyData");
            pw.WriteStruct(BodyData);

            pw.WriteString("CharacterData");
            pw.WriteStruct(CharacterData);

            pw.WriteString("AppearanceData");
            pw.WriteDictionary(AppearanceData.Count);

            foreach (var appearance in AppearanceData)
            {
                appearance.Value.Write(pw);
            }

            pw.WriteString("UserName");
            if (FamilyName != null)
            {
                pw.WriteUnicodeString(FamilyName);
            }
            else
            {
                pw.WriteNoneStruct();
            }

            pw.WriteString("GameContextId");
            if (GameContextId == 0)
            {
                pw.WriteNoneStruct();
            }
            else
            {
                pw.WriteUInt(GameContextId);
            }

            pw.WriteString("LoginData");
            pw.WriteStruct(LoginData);

            pw.WriteString("ClanData");
            pw.WriteStruct(ClanData);
        }
コード例 #10
0
 public void Write(PythonWriter pw)
 {
     pw.WriteTuple(10);
     pw.WriteUnicodeString(Name);
     pw.WriteUInt(MapContextId);
     pw.WriteUInt(ExpPoints);
     pw.WriteInt(ExpLevel);
     pw.WriteUInt(Body);
     pw.WriteUInt(Mind);
     pw.WriteUInt(Spirit);
     pw.WriteUInt(Class);
     pw.WriteUInt(CloneCredits);
     pw.WriteInt((int)RaceId);
 }
コード例 #11
0
        /// <summary>
        /// Traverse C# tokens, convert C# syntax to (Iron)Python syntax
        /// </summary>
        /// <param name="token"></param>
        /// <returns></returns>
        private static string processRawToken(PythonWriter parentWriter, SyntaxToken token)
        {
            PythonWriter pyWriter = new PythonWriter(parentWriter.IndentSize);

            switch (token.Kind())
            {
            case SyntaxKind.ThisKeyword:
                // replace 'this' keyword to python self
                pyWriter.Append("self");
                break;

            case SyntaxKind.NewKeyword:
                // no 'new' keyword
                // skip
                break;

            case SyntaxKind.SemicolonToken:
                // semicolon -> end of expression
                pyWriter.NewLine();
                break;

            case SyntaxKind.NumericLiteralToken:
                // Float in C#, like '6F'
                pyWriter.Append(token.Text.Replace("F", ""));
                break;

            case SyntaxKind.OpenBraceToken:
                // Left Brace in C#
                // skip
                break;

            case SyntaxKind.CloseBraceToken:
                // Right Brace in C#
                // skip
                break;

            case SyntaxKind.TrueKeyword:
                pyWriter.Append("True");
                break;

            case SyntaxKind.FalseKeyword:
                pyWriter.Append("False");
                break;

            default:
                pyWriter.Append(token.Text);
                break;
            }
            return(pyWriter.ToString());
        }
コード例 #12
0
        public void Write(PythonWriter pw)
        {
            pw.WriteTuple(3);
            pw.WriteUInt(NumLogins);
            pw.WriteUInt(TotalTimePlayed);

            if (LastLogin.HasValue && LastLogin.Value < DateTime.UtcNow)
            {
                pw.WriteUInt((uint)Math.Floor((DateTime.UtcNow - LastLogin.Value).TotalMinutes));
            }
            else
            {
                pw.WriteUInt(0);
            }
        }
コード例 #13
0
        public override void Write(PythonWriter pw)
        {
            pw.WriteTuple(3);
            pw.WriteUInt(EntityId);
            pw.WriteInt(ClassId);

            if (EntityData != null)
            {
                // todo
            }
            else
            {
                pw.WriteNoneStruct();
            }
        }
コード例 #14
0
        public override void Write(PythonWriter pw)
        {
            pw.WriteTuple(5);
            pw.WriteUnicodeString(FamilyName);
            pw.WriteBool(HasCharacters);
            pw.WriteUInt(UserId);

            pw.WriteTuple(EnabledRaceList.Count);

            foreach (var race in EnabledRaceList)
            {
                pw.WriteInt((int)race);
            }

            pw.WriteBool(CanSkipBootcamp);
        }
コード例 #15
0
ファイル: ActorInfoPacket.cs プロジェクト: vitalyo7/Rasa.NET
        public override void Write(PythonWriter pw)
        {
            pw.WriteTuple(6);

            pw.WriteList(StateIds.Count);
            foreach (var stateId in StateIds)
            {
                pw.WriteUInt(stateId);
            }

            pw.WriteDouble(Rotation);
            pw.WriteULong(TrackingTargetEntityId);
            pw.WriteDouble(MovementModifier);
            pw.WriteUInt(DesiredPostureId);
            pw.WriteBool(IsHoldingCombatMode);
        }
コード例 #16
0
        public override void Write(PythonWriter pw)
        {
            pw.WriteTuple(3);
            pw.WriteUInt(EntityId);
            pw.WriteInt((int)ClassId);

            /*
             * These packets will be called on the newly created entity. It behaves the same as if we've sent them separately. Order matters!
             *
             * Possible packets that can be appended here: (Not all of them are reasonable to include...)
             *   + PhysicalEntity
             *     - BodyAttributes
             *     - WorldLocationDescriptor
             *     - WorldPlacementDescriptor
             *     - IsTargetable
             *     - ServerSkeleton
             *     - ExamineResults
             *     - GameEffectAttached
             *     - GameEffectAttachFailed
             *     - GameEffectTick
             *     - CallGameEffectMethod
             *     - GameEffectDetached
             *     - GameEffects
             *     - GameEffectUpdateTooltip
             *     - PerformObjectAbility
             *   + CharacterSelectionPod augmentation:
             *        - CharacterInfo
             *        - CloneCreditsChanged
             *   + Other augmentations: ...
             */
            if (EntityData.Count > 0)
            {
                pw.WriteList(EntityData.Count);

                foreach (var packet in EntityData)
                {
                    pw.WriteTuple(2);
                    pw.WriteInt((int)packet.Opcode);

                    packet.Write(pw);
                }
            }
            else
            {
                pw.WriteNoneStruct();
            }
        }
コード例 #17
0
 public override void Write(PythonWriter pw)
 {
     pw.WriteTuple(1);
     pw.WriteDictionary(AppearanceData.Count);
     foreach (var t in AppearanceData)
     {
         var appearance = t.Value;
         pw.WriteInt((int)appearance.SlotId);
         pw.WriteTuple(2);
         pw.WriteUInt((uint)appearance.Class);
         pw.WriteTuple(4);
         pw.WriteInt(appearance.Color.Red);
         pw.WriteInt(appearance.Color.Green);
         pw.WriteInt(appearance.Color.Blue);
         pw.WriteInt(appearance.Color.Alpha);
     }
 }
コード例 #18
0
ファイル: PythonInterpreter.cs プロジェクト: 424f/lebowski
        /// <summary>
        /// Executes the code and redirects the results into a writer object.
        /// </summary>
        /// <param name="code">Source code to be executed.</param>
        /// <param name="writer">The result is written here.</param>
        /// <returns>Object that encapsulates the compiles code.</returns>
        public object ExecuteCode(string code, PythonWriter writer)
        {
            ScriptSource source = engine.CreateScriptSourceFromString(code, SourceCodeKind.Statements);
            Object o = null;
            try
            {
                CompiledCode compiled = source.Compile();
                object sys = runtime.GetSysModule();
                engine.Operations.SetMember(sys, "stdout", writer);
                engine.Operations.SetMember(sys, "stderr", writer);

                o = compiled.Execute(scope);

                // TODO: allow canceling operation
            }
            catch (Exception e)
            {
                ExceptionOperations eo = engine.GetService<ExceptionOperations>();
                string error = eo.FormatException(e);
                writer.write(error);
            }
            return o;
        }
コード例 #19
0
 public override void Write(PythonWriter pw)
 {
     pw.WriteTuple(1);
     pw.WriteUInt(DesiredCrouchState);
 }
コード例 #20
0
 public override void Write(PythonWriter pw)
 {
     pw.WriteTuple(1);
     pw.WriteUnicodeString(Name);
 }
コード例 #21
0
ファイル: ClanData.cs プロジェクト: vitalyo7/Rasa.NET
 public void Write(PythonWriter pw)
 {
     pw.WriteTuple(2);
     pw.WriteUInt(Id);
     pw.WriteUnicodeString(Name);
 }
コード例 #22
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="parentWriter"></param>
        /// <param name="node"></param>
        /// <returns></returns>
        private static string processNode(PythonWriter parentWriter, SyntaxNode node)
        {
            PythonWriter pyWriter = new PythonWriter(parentWriter.IndentSize);

            switch (node.Kind())
            {
            case SyntaxKind.InvocationExpression:
                // Looking for interface cast invocation (e.g. the ISupportInitialize interface)
                var error = false;
                try
                {
                    var node_cast = node
                                    .ChildNodes().Where(n => n.IsKind(SyntaxKind.SimpleMemberAccessExpression)).Single()
                                    .ChildNodes().Where(n => n.IsKind(SyntaxKind.ParenthesizedExpression)).Single()
                                    .ChildNodes().Where(n => n.IsKind(SyntaxKind.CastExpression)).Single();
                    var node_qn = node_cast
                                  .ChildNodes().Where(n => n.IsKind(SyntaxKind.QualifiedName)).Single();
                    var node_pe = node_cast
                                  .ChildNodes().Where(n => n.IsKind(SyntaxKind.ParenthesizedExpression)).Single();
                    var node_in = node
                                  .ChildNodes().Where(n => n.IsKind(SyntaxKind.SimpleMemberAccessExpression)).Single()
                                  .ChildNodes().Where(n => n.IsKind(SyntaxKind.IdentifierName)).Single();

                    // TODO: make sure that there's nothing in the invocation has 0 argument

                    /**
                     *
                     *  C#:
                     *      ((node_qn)(node_pe)).node_in()
                     *
                     *  -> Python:
                     *      (node_qn).node_in(node_pe)
                     *
                     *  Reference:
                     *      https://mail.python.org/pipermail/ironpython-users/2006-February/001800.html
                     *
                     **/
                    pyWriter.Append(String.Format("{0}.{1}({2})",
                                                  processNode(pyWriter, node_qn),
                                                  processNode(pyWriter, node_in),
                                                  processNode(pyWriter, node_pe)
                                                  ));
                }
                catch (InvalidOperationException)
                {
                    error = true;
                }
                if (error)
                {
                    pyWriter.Append(processNodes(pyWriter, node.ChildNodes()));
                }
                break;

            case SyntaxKind.ArrayCreationExpression:

                var _nodeAT = from _n in node.ChildNodes().OfType <ArrayTypeSyntax>() select _n;
                var _nodeQN = from _n in _nodeAT.Single().ChildNodes().OfType <QualifiedNameSyntax>() select _n;
                var _nodeIE = from _n in node.DescendantNodes().OfType <InitializerExpressionSyntax>() select _n;

                pyWriter.Append(String.Format("System.Array[{0}]([{1}])",
                                              _nodeQN.Single().ToFullString(),        // e.g. "System.Windows.Forms.ToolStripItem"
                                              processNode(pyWriter, _nodeIE.Single()) // e.g. "self.a1, self.a2, self.a3"
                                              ));

                break;

            case SyntaxKind.AddAssignmentExpression:
            // TODO
            // break;
            default:
                foreach (var nodeOrToken in node.ChildNodesAndTokens())
                {
                    if (nodeOrToken.IsNode)
                    {
                        pyWriter.Append(processNode(pyWriter, nodeOrToken.AsNode()));
                    }
                    else
                    {
                        pyWriter.Append(processRawToken(pyWriter, nodeOrToken.AsToken()));
                    }
                }
                break;
            }
            return(pyWriter.ToString());
        }
コード例 #23
0
        public override void Write(PythonWriter pw)
        {
            pw.WriteTuple(1);
            pw.WriteDictionary(9);

            pw.WriteString("SlotId");
            pw.WriteUInt(SlotId);

            pw.WriteString("IsSelected");
            pw.WriteInt(SlotId == 0 ? 1 : 0);

            pw.WriteString("BodyData");
            if (BodyData != null && !_empty)
            {
                pw.WriteTuple(2);
                pw.WriteInt(BodyData.GenderClassId);
                pw.WriteDouble(BodyData.Scale);
            }
            else
            {
                pw.WriteNoneStruct();
            }

            pw.WriteString("CharacterData");
            if (CharacterData != null && !_empty)
            {
                pw.WriteTuple(10); // TODO
                pw.WriteUnicodeString("CharName");
                pw.WriteInt(1);    // pos
                pw.WriteInt(41);   // xpptrs
                pw.WriteInt(10);   // xplvl
                pw.WriteInt(111);  // body
                pw.WriteInt(12);   //mind
                pw.WriteInt(21);   // spirit
                pw.WriteInt(2);    // class id
                pw.WriteInt(3);    // clone credits
                pw.WriteInt(3);    // raceId
            }
            else
            {
                pw.WriteNoneStruct();
            }

            pw.WriteString("AppearanceData");
            if (AppearanceData != null && !_empty)
            {
                // TODO
                var count = 0;
                for (var i = 0; i < 21; ++i)
                {
                    if (true) // TODO:
                    {
                        ++count;
                    }
                }

                pw.WriteDictionary(count);

                for (var i = 0; i < 21; ++i)
                {
                    if (true)
                    {
                        pw.WriteInt(i + 1); // equipment slot id
                        pw.WriteTuple(2);
                        pw.WriteInt(0);     // classId

                        pw.WriteTuple(4);
                        pw.WriteInt(0); // hueR
                        pw.WriteInt(0); // hueG
                        pw.WriteInt(0); // hueB
                        pw.WriteInt(0); // hueA
                    }// TODO: else nonstruct?
                }
            }
            else
            {
                pw.WriteTuple(0);
            }

            pw.WriteString("UserName");
            if (UserName != null && !_empty)
            {
                pw.WriteUnicodeString(UserName);
            }
            else
            {
                pw.WriteNoneStruct();
            }

            pw.WriteString("GameContextId");
            if (!_empty)
            {
                pw.WriteInt(GameContextId);
            }
            else
            {
                pw.WriteNoneStruct();
            }

            pw.WriteString("LoginData");
            if (LoginData != null && !_empty)
            {
                pw.WriteTuple(3);
                pw.WriteInt(0); // num logins
                pw.WriteInt(0); // total time played
                pw.WriteInt(0); // time since last played
            }
            else
            {
                pw.WriteNoneStruct();
            }

            pw.WriteString("ClanData");
            if (ClanData != null && !_empty)
            {
                pw.WriteTuple(2);
                pw.WriteInt(0);                     // clan id
                pw.WriteUnicodeString("Clan name"); // clan name
            }
            else
            {
                pw.WriteNoneStruct();
            }
        }
コード例 #24
0
 public override void Write(PythonWriter pw)
 {
     pw.WriteTuple(1);
     pw.WriteInt((int)Result);
 }
コード例 #25
0
 public void NewLine(int indentation)
 {
     sb.AppendLine();
     sb.Append(PythonWriter.GetIndentationString(indentation));
 }
コード例 #26
0
 public void NewLine()
 {
     sb.AppendLine();
     sb.Append(PythonWriter.GetIndentationString(IndentSize));
 }
コード例 #27
0
        public static int Convert(string csFile, string outFile)
        {
            SyntaxTree tree = CSharpSyntaxTree.ParseText(File.ReadAllText(csFile));

            var root = (CompilationUnitSyntax)tree.GetRoot();

            var formClass = (from _n in root.DescendantNodes().OfType <ClassDeclarationSyntax>()
                             select _n).Single();

            var formName = formClass.Identifier.ValueText;

            // // Select the initial_components method
            //
            // var _nodeICMethod = (from methoddef in formClass.DescendantNodes().OfType<MethodDeclarationSyntax>()
            //                 where methoddef.Identifier.ValueText == "InitializeComponent"
            //                 select methoddef).Single();

            PythonWriter pyWriter = new PythonWriter();

            pyWriter.Append($@"
""""""
Auto generated by formdesingercs2ipy.
IronPython WinForm class from Visual Studio Form Designer. 
DO NOT MODIFY THIS FILE MANUALLY. 
""""""

import clr
clr.AddReference('System.Drawing')
clr.AddReference('System.Windows.Forms')

import System
from System.Drawing import *
from System.Windows.Forms import *

class {formName}(Form):
    def __init__(self):
        """"""
        Create child controls and initialize form
        """"""
        self.initialize_component()
    
    def initialize_component(self):
        """"""
        Windows Form Designer generated code, auto converted by formdesingercs2ipy
        """"""
        {generateFunctionBodyInitializeComponent(2, root)}
        
        
if __name__ == '__main__':
    Application.EnableVisualStyles()
    Application.SetCompatibleTextRenderingDefault(False)
        
    form = {formName}()
    Application.Run(form)
            ");

            // Write file
            Console.WriteLine(pyWriter.ToString());
            File.WriteAllText(outFile, pyWriter.ToString());

            return(0);
        }
コード例 #28
0
 public override void Write(PythonWriter pw)
 {
     pw.WriteTuple(1);
     pw.WriteUInt(ContextId);
 }
コード例 #29
0
 public override void Write(PythonWriter pw)
 {
     pw.WriteTuple(1);
     pw.WriteULong(EntityId);
 }
コード例 #30
0
 public override void Write(PythonWriter pw)
 {
     pw.WriteTuple(1);
     pw.WriteInt(LangId);
 }
コード例 #31
0
 public void Write(PythonWriter pw)
 {
     pw.WriteTuple(2);
     pw.WriteUInt((uint)GenderClassId);
     pw.WriteDouble(Scale);
 }