Пример #1
0
        public override void setSingleValue(string value)
        {
            this.type = this.__determineSoType(value);

            if (this.type != SOType.Null)
            {
                this.singleValue = value;
            }
        }
        //*************************************************************************
        public SpaceObject(SOType myType)
        {
            type          = myType;
            velocity      = new Vector2(0, 0); // no moving
            angle         = 0;                 // facing = 0
            angleVelocity = 0;                 // no turning
            isDead        = false;
            isHit         = false;
            isNewHit      = false;
            lifeCounter   = 20;
            asteroidSize  = 1;

            position = new Vector2(100, 100); // start near the upper-left corner
        }
Пример #3
0
        void CreateNewPrimitive()
        {
            SOType activePrimType = scene.DefaultPrimitiveType;

            if (activePrimType == SOTypes.Sphere)
            {
                eActiveType = SupportedTypes.Sphere;
            }
            else if (activePrimType == SOTypes.Box)
            {
                eActiveType = SupportedTypes.Box;
            }
            else
            {
                eActiveType = SupportedTypes.Cylinder;
            }


            float fScale = scene.GetSceneScale();

            if (eActiveType == SupportedTypes.Cylinder)
            {
                primitive        = new MeshPrimitivePreview();
                primitive.Type   = MeshPrimitivePreview.PrimType.Cylinder;
                primitive.Center = CenterModes.Base;
                primitive.Create(scene.NewSOMaterial, scene.RootGameObject, MinDimension * fScale);
            }
            else if (eActiveType == SupportedTypes.Sphere)
            {
                primitive        = new MeshPrimitivePreview();
                primitive.Type   = MeshPrimitivePreview.PrimType.Sphere;
                primitive.Center = CenterModes.Origin;
                primitive.Create(scene.NewSOMaterial, scene.RootGameObject, MinDimension * fScale);
            }
            else if (eActiveType == SupportedTypes.Box)
            {
                primitive        = new MeshPrimitivePreview();
                primitive.Type   = MeshPrimitivePreview.PrimType.Box;
                primitive.Center = CenterModes.Corner;
                primitive.Create(scene.NewSOMaterial, scene.RootGameObject, MinDimension * fScale);
            }
            else
            {
                throw new NotImplementedException("SnapDrawPrimitivesTool.Create: unsupported type");
            }
        }
Пример #4
0
        /// <summary>
        /// Set or creates an property with an json string
        /// </summary>
        /// <param name="objectName">The json object name</param>
        /// <param name="value">The json string </param>
        public void set(string objectName, string value, SOType forceType = SOType.Undefined)
        {
            interfaceSemaphore.WaitOne();

            if (objectName != "")
            {
                if (!objectName.StartsWith("\""))
                {
                    objectName = '"' + objectName + '"';
                }
                objectName = "{" + objectName + ":" + value + "}";
                this.parseJson(objectName, "", false, forceType);
            }
            else
            {
                this.parseJson(value, "", false, forceType);
            }
            interfaceSemaphore.Release();
        }
Пример #5
0
    public void setSingleValue(string value)
    {
        int    sucess  = 0;
        double sucess2 = 0;

        //trye as null
        if ((value == null) || (value == "null") || (value == ""))
        {
            this.type = SOType.Null;
        }
        else
        {
            //try as boolean
            this.singleValue = value;

            if ((value == "true") || (value == "false"))
            {
                this.type = SOType.Boolean;
            }
            else
            {
                //try as int
                if (int.TryParse(value, out sucess))
                {
                    type = SOType.Int;
                }
                else
                {
                    //try as double
                    if (double.TryParse(value, out sucess2))
                    {
                        type = SOType.Double;
                    }
                    else
                    {
                        //is a string
                        type = SOType.String;
                    }
                }
            }
        }
    }
    DropPrimitiveButton add_primitive_button(Cockpit cockpit, string sName, float fHUDRadius, float dx, float dy,
                                             PrimitiveType primType, SOType soType, float fPrimRadiusScale,
                                             Material bgMaterial, Material primMaterial,
                                             Func <SceneObject> CreatePrimitiveF,
                                             IGameObjectGenerator customGenerator = null
                                             )
    {
        float fButtonRadius = 0.08f;

        DropPrimitiveButton button = new DropPrimitiveButton()
        {
            TargetScene     = cockpit.Scene,
            CreatePrimitive = CreatePrimitiveF
        };

        button.Create(fButtonRadius, bgMaterial);
        var gen = (customGenerator != null) ? customGenerator :
                  new primitiveIconGenerator()
        {
            PrimType = primType, PrimMaterial = primMaterial, PrimSize = fButtonRadius * fPrimRadiusScale
        };

        button.AddVisualElements(gen.Generate(), true);
        HUDUtil.PlaceInSphere(button, fHUDRadius, dx, dy);
        button.Name       = sName;
        button.OnClicked += (s, e) => {
            cockpit.Scene.DefaultPrimitiveType = soType;
        };
        button.OnDoubleClicked += (s, e) => {
            // [TODO] could have a lighter record here because we can easily recreate primitive...
            cockpit.Scene.History.PushChange(
                new AddSOChange()
            {
                scene = cockpit.Scene, so = CreatePrimitiveF()
            });
            cockpit.Scene.History.PushInteractionCheckpoint();
        };
        return(button);
    }
Пример #7
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="soInfo"></param>
        /// <param name="soType"></param>
        /// <param name="command"></param>
        /// <returns></returns>
        public static SOAction Create(SOAction.SOCommandInfo command)
        {
            //订单出库目前只处理SellerPortal发来请求
            if (command == null || command.SOInfo == null || !command.SOInfo.BaseInfo.SOType.HasValue)
            {
                BizExceptionHelper.Throw("SO_SOIsNotExist");
            }

            SOType soType = SOType.General;

            soType = command.SOInfo.BaseInfo.SOType.Value;
            //默认都使用 普通订单 的行为方法,如果某些订单类型有特定的行为方法,请在下 switch 代码中设置。

            string filterSOType = SOType.General.ToString();

            switch (command.Command)
            {
            case SOAction.SOCommand.Create:
                switch (soType)
                {
                case SOType.PhysicalCard:
                case SOType.ElectronicCard:
                case SOType.Gift:
                    filterSOType = soType.ToString();
                    break;
                }
                break;

            case SOAction.SOCommand.Update:
                switch (soType)
                {
                case SOType.PhysicalCard:
                case SOType.ElectronicCard:
                case SOType.Gift:
                case SOType.GroupBuy:
                    filterSOType = soType.ToString();
                    break;
                }
                break;

            case SOAction.SOCommand.Audit:
                switch (soType)
                {
                case SOType.PhysicalCard:
                case SOType.ElectronicCard:
                case SOType.Gift:
                case SOType.GroupBuy:
                    filterSOType = command.SOInfo.BaseInfo.SOType.Value.ToString();
                    break;
                }
                break;

            case SOAction.SOCommand.Abandon:
                switch (soType)
                {
                case SOType.ElectronicCard:
                case SOType.PhysicalCard:
                    filterSOType = command.SOInfo.BaseInfo.SOType.Value.ToString();
                    break;

                case SOType.General:
                    if (command.SOInfo.BaseInfo.SpecialSOType != SpecialSOType.Normal)
                    {
                        filterSOType = ThirdPartSOFilter;
                    }
                    break;
                }
                break;

            case SOAction.SOCommand.Job:
                switch (soType)
                {
                case SOType.GroupBuy:
                    filterSOType = soType.ToString();
                    break;
                }
                break;
            }

            SOAction action = ObjectFactory <SOAction> .NewInstance(new string[] { filterSOType, command.Command.ToString() });

            action.CurrentSO = command.SOInfo;
            action.Parameter = command.Parameter;
            return(action);
        }
 public virtual void forceType(SOType forcedType)
 {
     this.forcedType = forcedType;
 }
Пример #9
0
        private IJSONObject find(string objectName, bool autoCreateTree, IJSONObject currentParent, SOType forceType = SOType.Undefined)
        {
            //quebra o nome em um array
            objectName = objectName.Replace("]", "").Replace("[", ".");
            string      currentName = objectName;
            string      childsNames = "";
            IJSONObject childOnParent;

            if (objectName.IndexOf('.') > -1)
            {
                currentName = objectName.Substring(0, objectName.IndexOf('.'));
                childsNames = objectName.Substring(objectName.IndexOf('.') + 1);
            }

            if (!(currentParent.__containsChild(currentName)))
            {
                if (autoCreateTree)
                {
                    IJSONObject tempObj;
                    string      currentParentRelativeName = currentParent.getRelativeName();
                    if (currentParent is InMemoryJsonObject)
                    {
                        tempObj = new InMemoryJsonObject((InMemoryJsonObject)currentParent, currentParent.getRelativeName() + (currentParentRelativeName.Contains('.') ? "." : "") + currentName);
                    }
                    else
                    {
                        tempObj = new FileSystemJsonObject((FileSystemJsonObject)currentParent, currentParent.getRelativeName() + (currentParentRelativeName.Contains('.') ? "." : "") + currentName, (string)JsonObjectArguments);
                    }

                    if (forceType != SOType.Undefined)
                    {
                        tempObj.forceType(forceType);
                    }

                    currentParent.setChild(currentName, tempObj);
                }
                else
                {
                    return(null);
                }
            }


            childOnParent = currentParent.__getChild(currentName);


            if (childsNames == "")
            {
                return(childOnParent);
            }
            else
            {
                return(this.find(childsNames, autoCreateTree, childOnParent));
            }
        }
Пример #10
0
        public void parseJson(string json, string parentName = "", bool tryParseInvalidJson = false, SOType forceType = SOType.Undefined)
        {
            var currentObject = this.root;

            if (parentName != "")
            {
                currentObject = this.find(parentName, true, root);
            }
            currentObject.name = parentName;

            ParseStates state = ParseStates.findValueStart;

            bool          ignoreNextChar            = false;
            StringBuilder currentStringContent      = new StringBuilder();
            StringBuilder currentNumberContent      = new StringBuilder();
            StringBuilder currentSpecialWordContent = new StringBuilder();
            StringBuilder currentChildName          = new StringBuilder();

            int currLine = 1;
            int currCol  = 1;

            int  max  = json.Length;
            char curr = ' ';

            for (int cont = 0; cont < max; cont++)
            {
                curr = json[cont];

                currCol++;
                if (curr == '\n')
                {
                    currCol = 1;
                    currLine++;
                }

                switch (state)
                {
                case ParseStates.findingStart:
                    if (curr == '"')
                    {
                        if (currentObject.isArray())
                        {
                            state = ParseStates.prepareArray;
                        }
                        else
                        {
                            state = ParseStates.readingName;
                        }
                        currentChildName.Clear();
                    }
                    else if ((curr == ',') /* || (curr == '[') || (curr == '{')*/)
                    {
                        if (currentObject.isArray())
                        {
                            state = ParseStates.prepareArray;
                        }
                    }

                    else if ((curr == '}') || (curr == ']'))
                    {
                        if (parentName.Contains('.'))
                        {
                            parentName    = parentName.Substring(0, parentName.LastIndexOf('.'));
                            currentObject = currentObject.parent;
                        }
                        else
                        {
                            parentName    = "";
                            currentObject = root;
                        }
                    }
                    break;

                case ParseStates.readingName:
                    if (curr == '"')
                    {
                        state              = ParseStates.waitingKeyValueSep;
                        currentObject      = this.find(currentChildName.ToString(), true, currentObject, forceType);
                        currentObject.name = currentChildName.ToString();
                        parentName         = parentName + (parentName != "" ? "." : "") + currentChildName;
                    }
                    else
                    {
                        currentChildName.Append(curr);
                    }
                    break;

                case ParseStates.waitingKeyValueSep:
                    if (curr == ':')
                    {
                        state = ParseStates.findValueStart;
                    }
                    break;

                case ParseStates.findValueStart:
                    if (curr == '"')
                    {
                        state = ParseStates.readingContentString;
                        currentStringContent.Clear();
                    }
                    else if (curr == '{')
                    {
                        state = ParseStates.findingStart;
                    }
                    else if (curr == '[')
                    {
                        state = ParseStates.prepareArray;
                    }
                    else if ("0123456789-+.".Contains(curr))
                    {
                        state = ParseStates.readingContentNumber;
                        currentNumberContent.Clear();
                        cont--;
                        currCol--;
                    }
                    else if ("untf".Contains(curr))
                    {
                        state = ParseStates.readingContentSpecialWord;
                        currentSpecialWordContent.Clear();
                        cont--;
                        currCol--;
                    }
                    else if (curr == ']')
                    {
                        //delete currenObject
                        var temp = currentObject;

                        if (parentName.Contains('.'))
                        {
                            parentName    = parentName.Substring(0, parentName.LastIndexOf('.'));
                            currentObject = currentObject.parent;
                        }
                        else
                        {
                            parentName    = "";
                            currentObject = root;
                        }

                        currentObject.delete(temp.name);

                        cont--;
                        currCol--;
                        state = ParseStates.findingStart;
                    }
                    else if (!" \t\r\n".Contains(curr))
                    {
                        if (!tryParseInvalidJson)
                        {
                            throw new Exception("SintaxError at line " + currLine + " and column " + currCol + ". Expected ' '(space), \t, \r or \n, but found " + curr + ".");
                        }
                    }
                    break;

                case ParseStates.prepareArray:
                    //state = "findingStart";
                    currentChildName.Clear();
                    currentChildName.Append(currentObject.__getChildsNames().Count.ToString());
                    currentObject      = this.find(currentChildName.ToString(), true, currentObject, forceType);
                    currentObject.name = currentChildName.ToString();
                    parentName         = parentName + (parentName != "" ? "." : "") + currentChildName;
                    state = ParseStates.findValueStart;
                    cont--;
                    currCol--;
                    break;

                case ParseStates.readingContentString:
                    if (ignoreNextChar)
                    {
                        currentStringContent.Append(curr);
                        ignoreNextChar = false;
                    }
                    else if (curr == '\\')
                    {
                        ignoreNextChar = true;
                        currentStringContent.Append(curr);
                    }
                    else if (curr == '"')
                    {
                        currentObject.setSingleValue(currentStringContent.ToString());

                        //return to parent Object
                        if (parentName.Contains('.'))
                        {
                            parentName    = parentName.Substring(0, parentName.LastIndexOf('.'));
                            currentObject = currentObject.parent;
                        }
                        else
                        {
                            parentName    = "";
                            currentObject = root;
                        }

                        state = ParseStates.findingStart;
                    }
                    else
                    {
                        currentStringContent.Append(curr);
                    }
                    break;

                case ParseStates.readingContentNumber:
                    if ("0123456789.-+".Contains(curr))
                    {
                        currentNumberContent.Append(curr);
                    }
                    else
                    {
                        currentObject.setSingleValue(currentNumberContent.ToString());

                        //return to parent Object
                        if (parentName.Contains('.'))
                        {
                            parentName    = parentName.Substring(0, parentName.LastIndexOf('.'));
                            currentObject = currentObject.parent;
                        }
                        else
                        {
                            parentName    = "";
                            currentObject = root;
                        }

                        cont--;
                        state = ParseStates.findingStart;
                    }

                    break;

                case ParseStates.readingContentSpecialWord:
                    if ("truefalseundefindednul".Contains(curr))
                    {
                        currentSpecialWordContent.Append(curr);
                    }
                    else
                    {
                        string strTemp = currentSpecialWordContent.ToString();
                        if ((strTemp == "true") ||
                            (strTemp == "false") ||
                            (strTemp == "null") ||
                            (strTemp == "undefined"))
                        {
                            currentObject.setSingleValue(strTemp);

                            //return to parent Object
                            if (parentName.Contains('.'))
                            {
                                parentName    = parentName.Substring(0, parentName.LastIndexOf('.'));
                                currentObject = currentObject.parent;
                            }
                            else
                            {
                                parentName    = "";
                                currentObject = root;
                            }

                            cont--;
                            state = ParseStates.findingStart;
                        }
                        else
                        {
                            if (!tryParseInvalidJson)
                            {
                                throw new Exception("Invalid simbol at line " + currLine + " and column " + currCol + ": " + currentSpecialWordContent);
                            }
                        }
                    }

                    break;
                }
            }
        }
Пример #11
0
            internal Ruling ruling;    //protected

            public SortObject(SOType type, double position, Ruling ruling)
            {
                this.type     = type;
                this.position = position;
                this.ruling   = ruling;
            }