Example #1
0
 public static ConstString New(BlockBase parent, string value)
 {
     var ret = new ConstString();
     ret.Parent = parent;
     ret.Value = value;
     return ret;
 }
Example #2
0
File: TypeOf.cs Project: 7shi/LLPML
        public static void AddCodes(NodeBase caller, BlockBase parent, NodeBase target, OpModule codes, string op, Addr32 dest)
        {
            if (target is TypeOf) target = (target as TypeOf).Target;

            var v = target as Variant;
            if (v != null && parent.GetFunction(v.Name) == null)
            {
                var fpname = (target as Variant).Name;
                var fpt = Types.GetType(parent, fpname);
                if (fpt == null || !fpt.Check())
                    throw caller.Abort("undefined type: {0}", fpname);
                codes.AddCodesV(op, dest, codes.GetTypeObject(fpt));
                return;
            }

            var tt = target.Type;
            var tr = tt as TypeReference;
            var tts = tt.Type as TypeStruct;
            if (tr != null && (tr.IsArray || (tts != null && tts.IsClass)))
            {
                target.AddCodesV(codes, "mov", null);
                var label = new OpCode();
                codes.Add(I386.Test(Reg32.EAX, Reg32.EAX));
                codes.Add(I386.Jcc(Cc.Z, label.Address));
                codes.Add(I386.MovRA(Reg32.EAX, Addr32.NewRO(Reg32.EAX, -16)));
                codes.Add(label);
                codes.AddCodes(op, dest);
            }
            else
                codes.AddCodesV(op, dest, codes.GetTypeObject(tt));
        }
Example #3
0
 public static VarDeclare Array(BlockBase parent, string name, TypeBase type, NodeBase count)
 {
     var ret = New(parent, name, null);
     ret.doneInferType = true;
     ret.type = TypeArray.New(type, count);
     return ret;
 }
Example #4
0
File: Block.cs Project: 7shi/LLPML
 public static NodeBase[] Parse(BlockBase parent, Tokenizer token)
 {
     var parser = Parser.Create(token, parent);
     var ret = parser.Parse();
     if (token.CanRead) ret = null;
     return ret;
 }
Example #5
0
File: Types.cs Project: 7shi/LLPML
 public static TypeBase GetType(BlockBase parent, string type)
 {
     if (type == null)
         return null;
     else if (type == "delegate")
         return DelgFunc.GetDefaultType(parent);
     else if (type.StartsWith("var:"))
         return ToVarType(GetType(parent, type.Substring(4)));
     else if (type.EndsWith("*"))
     {
         var t = type.Substring(0, type.Length - 1).TrimEnd();
         return TypePointer.New(GetType(parent, t));
     }
     else if (type.EndsWith("[]"))
     {
         var t = type.Substring(0, type.Length - 2).TrimEnd();
         return TypeReference.New(GetType(parent, t), true);
     }
     else if (type.EndsWith("]"))
     {
         var p = type.IndexOf('[');
         var t = GetType(parent, type.Substring(0, p));
         var n = type.Substring(p + 1, type.Length - p - 2);
         return TypeArray.NewInt(t, int.Parse(n));
     }
     var ret = Types.GetValueType(type);
     if (ret != null) return ret;
     return TypeStruct.New(parent, type);
 }
Example #6
0
 protected static VarOperator Init1(VarOperator op, BlockBase parent, NodeBase dest, NodeBase arg)
 {
     op.Parent = parent;
     op.dest = dest;
     op.values.Add(arg);
     return op;
 }
Example #7
0
File: TypeOf.cs Project: 7shi/LLPML
 public static TypeOf New(BlockBase parent, NodeBase target)
 {
     var ret = new TypeOf();
     ret.Parent = parent;
     ret.Target = target;
     return ret;
 }
Example #8
0
 public static Variant NewName(BlockBase parent, string name)
 {
     var ret = new Variant();
     ret.Parent = parent;
     ret.name = name;
     return ret;
 }
Example #9
0
 protected static Operator Init2(Operator op, BlockBase parent, NodeBase arg1, NodeBase arg2)
 {
     op.Parent = parent;
     if (arg1 != null) op.values.Add(arg1);
     if (arg2 != null) op.values.Add(arg2);
     return op;
 }
Example #10
0
File: Null.cs Project: 7shi/LLPML
 public static Null New(BlockBase parent)
 {
     var ret = new Null();
     ret.Parent = parent;
     ret.name = "null";
     return ret;
 }
Example #11
0
File: Return.cs Project: 7shi/LLPML
 public static Return New(BlockBase parent, NodeBase value)
 {
     var ret = new Return();
     ret.init(parent);
     if (value != null) ret.Value = value;
     return ret;
 }
Example #12
0
File: Arg.cs Project: 7shi/LLPML
 public static Arg NewVar(BlockBase parent, VarDeclare target)
 {
     var ret = new Arg();
     ret.init1(parent, target.Name, null);
     ret.target = target;
     return ret;
 }
Example #13
0
	void Update ()
	{
		if(!MapEditor.Instance)
		{
			if(m_cells == null) return;

			if(m_selectedBlock == null)
			{
				for (int y = 0; y < m_cells.Count; ++y) 
				{
					for (int x = 0; x < m_cells[y].Count; ++x) 
					{
						m_selectedBlock = m_cells[y][x].UpdateInput();
						if(m_selectedBlock)
							return;
					}
				}
			}
			else
			{
				m_selectedBlock.UpdateMovement();
				if(!Input.GetMouseButton(0))
					m_selectedBlock = null;
			}
		}
	}
Example #14
0
File: New.cs Project: 7shi/LLPML
 public static New New2(BlockBase parent, string type, NodeBase length)
 {
     var ret = new New();
     ret.Parent = parent;
     ret.type = TypeReference.New(Types.GetType(parent, type), true);
     ret.Length = length;
     return ret;
 }
Example #15
0
File: New.cs Project: 7shi/LLPML
 public static New New1(BlockBase parent, string type)
 {
     var ret = new New();
     ret.Parent = parent;
     ret.type = Types.GetVarType(parent, type);
     ret.Length = IntValue.New(-1);
     return ret;
 }
Example #16
0
File: Base.cs Project: 7shi/LLPML
 public static Base New(BlockBase parent)
 {
     var ret = new Base();
     ret.Parent = parent;
     ret.name = "base";
     ret.Reference = parent.GetVar("this");
     return ret;
 }
Example #17
0
 public static Declare New(BlockBase parent, string name, string type)
 {
     var ret = new Declare();
     ret.init1(parent, name, null);
     ret.type = Types.GetType(parent, type) as TypeStruct;
     if (ret.type == null) throw ret.Abort("type required");
     return ret;
 }
Example #18
0
 public static TypeDelegate New(
     BlockBase parent, CallType callType, TypeBase retType, VarDeclare[] args)
 {
     var ret = new TypeDelegate();
     ret.init(callType, retType, args);
     ret.Parent = parent;
     return ret;
 }
Example #19
0
File: Parser.cs Project: 7shi/LLPML
 public static Parser Create(Tokenizer tokenizer, BlockBase parent)
 {
     var ret = new Parser();
     ret.tokenizer = tokenizer;
     ret.parent = parent;
     ret.InitOperator();
     return ret;
 }
Example #20
0
File: Extern.cs Project: 7shi/LLPML
 public static Extern New(BlockBase parent, string name, string module, string alias)
 {
     var ret = new Extern();
     ret.init2(parent, name, false);
     ret.module = module;
     ret.alias = alias;
     return ret;
 }
Example #21
0
File: Var.cs Project: 7shi/LLPML
 public static Var New(BlockBase parent, VarDeclare var)
 {
     var ret = new Var();
     ret.Parent = parent;
     ret.name = var.Name;
     ret.Reference = var;
     return ret;
 }
Example #22
0
File: This.cs Project: 7shi/LLPML
 public static This New(BlockBase parent)
 {
     var ret = new This();
     ret.Parent = parent;
     ret.name = "this";
     ret.Reference = parent.GetVar(ret.name);
     return ret;
 }
Example #23
0
File: Cast.cs Project: 7shi/LLPML
 public static Cast New(BlockBase parent, string type, NodeBase source)
 {
     var ret = new Cast();
     ret.Parent = parent;
     ret.name = "__cast";
     ret.type = type;
     ret.Source = source;
     return ret;
 }
Example #24
0
 public static TypeStruct New(BlockBase parent, string name)
 {
     if (name.EndsWith("]"))
         throw new Exception("TypeStruct: invalid type: " + name);
     var ret = new TypeStruct();
     ret.Parent = parent;
     ret.name = name;
     return ret;
 }
Example #25
0
File: Var.cs Project: 7shi/LLPML
 public static Var NewName(BlockBase parent, string name)
 {
     var ret = new Var();
     ret.Parent = parent;
     ret.name = name;
     ret.Reference = parent.GetVar(name);
     if (ret.Reference == null)
         throw ret.Abort("undefined pointer: " + name);
     return ret;
 }
Example #26
0
	public void SetBlock(BlockBase block) 
	{ 
		if(m_currentBlock)
		{
			m_currentBlock.SetParentCell(null);
		}

		m_currentBlock = block;
		if(m_currentBlock)
			m_currentBlock.SetParentCell(this);
	}
Example #27
0
File: TypeOf.cs Project: 7shi/LLPML
 public static TypeBase GetType(BlockBase parent, NodeBase target)
 {
     var v = target as Variant;
     if (v != null)
     {
         var vt = v.GetVariantType();
         if (vt != null) return vt;
         return Types.GetType(parent, v.Name);
     }
     return target.Type;
 }
Example #28
0
 /// <summary>
 /// Parses a literal value from a line.
 /// </summary>
 /// <param name="input">The reference to the line of code</param>
 /// <param name="label">Debug information about the expected literal</param>
 /// <param name="replace">Whether to perform variable replacement in the literal</param>
 /// <param name="data">The BotData needed for variable replacement</param>
 /// <returns>The literal without the leading and trailing double quotes</returns>
 public static string ParseLiteral(ref string input, string label, bool replace = false, BotData data = null)
 {
     try {
         if (replace)
         {
             return(BlockBase.ReplaceValues(ParseToken(ref input, TokenType.Literal, true), data));
         }
         else
         {
             return(ParseToken(ref input, TokenType.Literal, true));
         }
     }
     catch { throw new ArgumentException($"Expected Literal value for '{label}'"); }
 }
Example #29
0
        public BlockBase CreateAndInitialiseBlock(View hostView, Node parentNode, BlockBase parentBlock, FieldList definitionData, FieldList contentData, bool isRoot)
        {
            if (definitionData != null)
            {
                BlockDefinition bd = Core.Definitions.UnpackDefinition(definitionData) as BlockDefinition;

                if (bd != null)
                {
                    return(CreateAndInitialiseBlock(hostView, parentNode, parentBlock, bd, contentData, isRoot));
                }
            }

            return(null);
        }
Example #30
0
        public virtual BlockBase Parse(Memory <byte> source)
        {
            //Memory<byte> sourceMemory = new Memory<byte>(source);

            Memory <byte> spanBody = SliceInitialBytes(source, out Memory <byte> spanHeader);

            BlockBase blockBase = ParseBody(spanBody, out Memory <byte> nonHeaderBytes);

            blockBase.RawData = source.Slice(0, spanHeader.Length + nonHeaderBytes.Length);

            FillBlockBaseHeader(blockBase, spanHeader);

            return(blockBase);
        }
        private void CreateOrUpdateEpoch(BlockBase block, List <Transaction> allMessagedTransactions)
        {
            var epochNumber = block.Depth / (EpochSize + 1) + 1;

            if (_stakingStorage.Epochs.TryGetValue(epochNumber - 1, out var previousEpoch))
            {
                var currentEpoch = _stakingStorage.Epochs.GetOrAdd(epochNumber, new Epoch(previousEpoch, epochNumber));
                allMessagedTransactions.ForEach(mt => currentEpoch.Transactions.TryAdd(mt.Id, mt));
            }
            else
            {
                Console.WriteLine($"Could not find epoch parent {epochNumber - 1}\nDepth: {block.Depth}");
            }
        }
Example #32
0
 private bool Header_GetVersion(ExecutionEngine engine)
 {
     if (engine.CurrentContext.EvaluationStack.Pop() is InteropInterface _interface)
     {
         BlockBase header = _interface.GetInterface <BlockBase>();
         if (header == null)
         {
             return(false);
         }
         engine.CurrentContext.EvaluationStack.Push(header.Version);
         return(true);
     }
     return(false);
 }
Example #33
0
 internal void Clear()
 {
     for (int y = 0; y < GridObject.GetLength(1); y++)
     {
         for (int x = 0; x < GridObject.GetLength(0); x++)
         {
             BlockBase blockToErase = GridObject[x, y];
             if (blockToErase != null)
             {
                 blockToErase.DestroyTiles(x, y);
             }
         }
     }
 }
Example #34
0
 protected bool Header_GetTimestamp(ExecutionEngine engine)
 {
     if (engine.CurrentContext.EvaluationStack.Pop() is InteropInterface _interface)
     {
         BlockBase header = _interface.GetInterface <BlockBase>();
         if (header == null)
         {
             return(false);
         }
         engine.CurrentContext.EvaluationStack.Push(header.Timestamp);
         return(true);
     }
     return(false);
 }
Example #35
0
        public static DiagramBlock CreateDiagramBlock(BlockBase block, bool useNextPosition)
        {
            var   className = (block.ID == null) ?  block.GetAssemblyClassName() : block.ID;
            Image image     = Envision.Properties.Resources.unknownicon;

            if (block.Picture != null)
            {
                image = block.Picture;
            }
            var label     = className;
            var shortname = typeof(BlockOutputNode).GetProperty("ShortName");

            return(new DiagramBlock(image, label, block, block.InputNodes.ToArray <object>(), block.OutputNodes.ToArray <object>(), shortname, true, useNextPosition));
        }
Example #36
0
 protected bool Header_GetPrevHash(ExecutionEngine engine)
 {
     if (engine.CurrentContext.EvaluationStack.Pop() is InteropContract _interface)
     {
         BlockBase header = _interface.GetInterface <BlockBase>();
         if (header == null)
         {
             return(false);
         }
         engine.CurrentContext.EvaluationStack.Push(header.PrevHash.ToArray());
         return(true);
     }
     return(false);
 }
Example #37
0
        private void Process()
        {
            try {
                vm.LS.TakeStep(vm.BotData);
                OB.Logger.LogInfo(Components.Stacker, $"Processed {BlockBase.TruncatePretty(vm.LS.CurrentLine, 20)}");
            }
            catch (Exception ex) {
                OB.Logger.LogError(Components.Stacker, $"Processing of line {BlockBase.TruncatePretty(vm.LS.CurrentLine, 20)} failed, exception: {ex.Message}");
            }

            PrintBotData();
            PrintLogBuffer();
            DisplayHTML();
        }
Example #38
0
 private bool Header_GetNextConsensus(ExecutionEngine engine)
 {
     if (engine.CurrentContext.EvaluationStack.Pop() is InteropContract _interface)
     {
         BlockBase header = _interface.GetInterface <BlockBase>();
         if (header == null)
         {
             return(false);
         }
         engine.CurrentContext.EvaluationStack.Push(header.NextConsensus.ToArray());
         return(true);
     }
     return(false);
 }
 public override void OnInputDisconnected(BlockBase src, string srcSlotName, string targetSlotName)
 {
     base.OnInputDisconnected(src, srcSlotName, targetSlotName);
     if (targetSlotName == "set_Grabber" && _streamer != null)
     {
         _streamer.Stop();
         _streamer.Close();
         if (_grabber != null)
         {
             _grabber.Destroy();
         }
         _grabber = null;
     }
 }
Example #40
0
 private static bool Header_GetPrevHash(ApplicationEngine engine)
 {
     if (engine.CurrentContext.EvaluationStack.Pop() is InteropInterface _interface)
     {
         BlockBase header = _interface.GetInterface <BlockBase>();
         if (header == null)
         {
             return(false);
         }
         engine.CurrentContext.EvaluationStack.Push(header.PrevHash.ToArray());
         return(true);
     }
     return(false);
 }
Example #41
0
 protected virtual bool Header_GetNextConsensus(ExecutionEngine engine)
 {
     if (engine.EvaluationStack.Pop() is InteropInterface _interface)
     {
         BlockBase header = _interface.GetInterface <BlockBase>();
         if (header == null)
         {
             return(false);
         }
         engine.EvaluationStack.Push(header.NextConsensus.ToArray());
         return(true);
     }
     return(false);
 }
Example #42
0
        /// <summary>
        /// Replaces the values and verifies if a condition is true or false.
        /// </summary>
        /// <param name="kcCond">The keycheck condition struct</param>
        /// <param name="data">The BotData used for variable replacement</param>
        /// <returns>Whether the comparison is verified or not.</returns>
        public static bool ReplaceAndVerify(KeycheckCondition kcCond, BotData data)
        {
            var style    = NumberStyles.Number | NumberStyles.AllowCurrencySymbol; // Needed when comparing values with a currency symbol
            var provider = new CultureInfo("en-US");
            var L        = BlockBase.ReplaceValuesRecursive(kcCond.Left, data);    // The left-hand term can accept recursive values like <LIST[*]>
            var r        = BlockBase.ReplaceValues(kcCond.Right, data);            // The right-hand term cannot

            switch (kcCond.Comparer)
            {
            case Comparer.EqualTo:
                return(L.Any(l => l == r));

            case Comparer.NotEqualTo:
                return(L.Any(l => l != r));

            case Comparer.GreaterThan:
                return(L.Any(l => decimal.Parse(l.Replace(',', '.'), style, provider) > decimal.Parse(r.Replace(',', '.'), style, provider)));

            case Comparer.GreaterOrEqual:
                return(L.Any(l => decimal.Parse(l.Replace(',', '.'), style, provider) >= decimal.Parse(r.Replace(',', '.'), style, provider)));

            case Comparer.LessThan:
                return(L.Any(l => decimal.Parse(l.Replace(',', '.'), style, provider) < decimal.Parse(r.Replace(',', '.'), style, provider)));

            case Comparer.LessThanOrEqual:
                return(L.Any(l => decimal.Parse(l.Replace(',', '.'), style, provider) <= decimal.Parse(r.Replace(',', '.'), style, provider)));

            case Comparer.Contains:
                return(L.Any(l => l.Contains(r)));

            case Comparer.DoesNotContain:
                return(L.Any(l => !l.Contains(r)));

            case Comparer.Exists:
                return(L.Any(l => l != kcCond.Left));    // Returns true if any replacement took place

            case Comparer.DoesNotExist:
                return(L.All(l => l == kcCond.Left));    // Returns true if no replacement took place

            case Comparer.MatchesRegex:
                return(L.Any(l => Regex.Match(l, r).Success));

            case Comparer.DoesNotMatchRegex:
                return(L.Any(l => !Regex.Match(l, r).Success));

            default:
                return(false);
            }
        }
Example #43
0
        void CompileApply(AstApply ast, BlockBase parent)
        {
            var e   = ast.Block;
            var src = e.Source;
            var fc  = new FunctionCompiler(_compiler, parent);
            var p   = fc.ResolveExpression(e, null);

            if (p.IsInvalid)
            {
                return;
            }

            if (p is PartialType)
            {
                var dt = (p as PartialType).Type;

                if (dt.Block != null)
                {
                    dt.PopulateMembers();
                    dt.Block.Populate();
                    parent.Members.Add(new Apply(src, ast.Modifier, dt.Block, null));
                    return;
                }
            }
            else if (p is PartialBlock)
            {
                var b = (p as PartialBlock).Block;
                b.Populate();
                parent.Members.Add(new Apply(src, ast.Modifier, b, null));
                return;
            }

            var sym = fc.CompilePartial(p);

            if (sym.IsInvalid)
            {
                return;
            }

            if (sym.ReturnType.Block != null)
            {
                sym.ReturnType.PopulateMembers();
                sym.ReturnType.Block.Populate();
                parent.Members.Add(new Apply(src, ast.Modifier, sym.ReturnType.Block, sym));
                return;
            }

            Log.Error(src, ErrorCode.E3213, "Only 'block', 'class', 'struct' or 'interface' types can be applied");
        }
Example #44
0
        public static List <ODCoverage> GetRecords(BlockBase block, string layer, CoverageType type)
        {
            List <ODCoverage> recs = new List <ODCoverage>();
            var btr         = block.IdBtr.GetObject(OpenMode.ForRead) as BlockTableRecord;
            var plsCoverage = btr.GetObjects <Polyline>().
                              Where(p => p.Visible && p.Layer.Equals(layer, StringComparison.OrdinalIgnoreCase));

            foreach (var item in plsCoverage)
            {
                var        idPlCoverage = block.CopyEntToModel(btr.Database.CurrentSpaceId, item.Id);
                ODCoverage odCoverage   = new ODCoverage(idPlCoverage, type);
                recs.Add(odCoverage);
            }
            return(recs);
        }
Example #45
0
        public override bool Begin(BlockBase b)
        {
            var bp = b.ParentBlock;

            if (bp != null && bp.BlockType == BlockType.MetaBlock)
            {
                if (b.BlockType != BlockType.MetaBlock ||
                    ((MetaBlock)bp).MetaBlockType != MetaBlockType.Scope)
                {
                    Log.Error(b.Source, ErrorCode.E0000, "Block " + b.Quote() + " is not allowed in meta block");
                }
            }

            return(!Environment.IsGeneratingCode);
        }
Example #46
0
        public bool VerifyBlock(BlockBase blockBase)
        {
            SyncedBlockBase syncedBlockBase = (SyncedBlockBase)blockBase;

            ulong syncBlockHeight = syncedBlockBase.SyncBlockHeight;

            if (!((_synchronizationContext.LastBlockDescriptor?.BlockHeight.Equals(syncBlockHeight) ?? true) ||
                  (_synchronizationContext.PrevBlockDescriptor?.BlockHeight.Equals(syncBlockHeight) ?? true)))
            {
                _log.Error($"Synchronization block height is outdated: {blockBase.RawData.ToArray().ToHexString()}");
                return(false);
            }

            return(CheckSyncPOW(syncedBlockBase));
        }
Example #47
0
        public bool ExecuteApplicationEvent(Anchor anchor, BlockBase sourceBlock, Node sourceNode, long sourceViewID)
        {
            if (ApplicationEvents != null)
            {
                ActionSet actions = ApplicationEvents[anchor];

                if (actions != null)
                {
                    ExecuteAction(actions, sourceBlock, sourceNode, sourceViewID);
                    return(true);
                }
            }

            return(false);
        }
        public void AddBlock(BlockBase block)
        {
            int position;

            if (vm.CurrentBlockIndex == -1)
            {
                position = vm.Stack.Count;
            }
            else
            {
                position = vm.Stack.Count > 0 ? vm.CurrentBlockIndex + 1 : 0;
            }
            OB.Logger.LogInfo(Components.Stacker, $"Added a block of type {block.GetType()} in position {position}");
            vm.AddBlock(block, position);
        }
 public override void OnOutputConnected(string srcSlotName, BlockBase target, string targetSlotName)
 {
     base.OnOutputConnected(srcSlotName, target, targetSlotName);
     if (srcSlotName == "Grabber" && _grabber != null)
     {
         _grabber.Restart();
         _grabber.Start();
         _grabber.SetVolume(_volume);
     }
     else if (srcSlotName == "Samples" && _grabber != null)
     {
         _grabber.Start();
         _grabber.StartThreadedGrabber();
     }
 }
Example #50
0
        public BlockBase GetLastBlock(IKey key)
        {
            TransactionalBlock transactionalBlock = DataAccessService.Instance.GetLastTransactionalBlock(key);

            if (transactionalBlock != null)
            {
                ITranslator <TransactionalBlock, BlockBase> mapper = _mapperFactory.GetInstance <TransactionalBlock, BlockBase>();

                BlockBase block = mapper?.Translate(transactionalBlock);

                return(block);
            }

            return(null);
        }
Example #51
0
        public void TestGetName()
        {
            var block = new ConvolutionBlock();

            Assert.AreEqual(block.Name, BlockBase.GetName(block.GetType()));
            Assert.AreEqual("ConvolutionBlock", block.GetAssemblyClassName());

            Assert.AreEqual("", BlockBase.GetName(typeof(Object)));
            Assert.AreEqual("", BlockBase.GetName(typeof(BlockBase)));
            Assert.AreEqual(true, block.HasParameters());

            var block2 = new InvertBlock();

            Assert.AreEqual(false, block2.HasParameters());
        }
    // Get a variable.
    public Variable GetVariable(string name)
    {
        BlockBase block = this;

        do
        {
            Variable variable = block.Variables.Where(x => x.Name == name).FirstOrDefault();
            if (variable != null)
            {
                return(variable);
            }
            block = block.Parent;
        } while (block != null);
        return(null);
    }
Example #53
0
    public static List <BlockBase> LoadJsonByName(string fileName)
    {
        currentJsonFileName = fileName;
        TextAsset jsonfile = Resources.Load("stage") as TextAsset;
        string    _data    = jsonfile.text;

        currentJsonString = _data;
        JsonData jdata = JsonMapper.ToObject(_data);

        if (jdata.IsArray)
        {
            List <BlockBase> ret = new List <BlockBase>();
            var list             = jdata;
            for (int i = 0; i < list.Count; ++i)
            {
                //Debug.Log (DataManager._currentStage.ToString () + " " + list [i] ["stage"]);
                if (DataManager._currentStage == toInt(list [i] ["stage"].ToString()))
                {
                    //Debug.Log ("add");
                    BlockBase bb = new BlockBase();
                    bb._id     = toInt(list [i] ["id"].ToString());
                    bb._type   = (BlockType)toInt(list [i] ["style"].ToString());
                    bb._startX = toFloat(list [i] ["xHead"].ToString());
                    bb._endX   = toFloat(list [i] ["xEnd"].ToString());
                    bb._Y      = toFloat(list [i] ["yHead"].ToString());
                    if (bb._type == BlockType.BT_LRSTAIR)
                    {
                        bb._stairXStart   = toFloat(list [i] ["xMin"].ToString());
                        bb._stairXEnd     = toFloat(list [i] ["xMax"].ToString());
                        bb._stairMoveTime = toFloat(list [i] ["time"].ToString());
                    }
                    if (bb._type == BlockType.BT_UDSTAIR)
                    {
                        bb._stairYStart   = toFloat(list [i] ["yMin"].ToString());
                        bb._stairYEnd     = toFloat(list [i] ["yMax"].ToString());
                        bb._stairMoveTime = toFloat(list [i] ["time"].ToString());
                    }
                    if (bb._type == BlockType.BT_FALLSTAIR)
                    {
                        bb._stairDelay = toFloat(list [i] ["fallTime"].ToString());
                    }
                    ret.Add(bb);
                }
            }
            return(ret);
        }
        return(null);
    }
Example #54
0
 public override void OnInputDisconnected(BlockBase src, string srcSlotName, string targetSlotName)
 {
     base.OnInputDisconnected(src, srcSlotName, targetSlotName);
     if (targetSlotName == "set_Eyes")
     {
         Eyes = null;
     }
     if (targetSlotName == "set_Ears")
     {
         Ears = null;
     }
     if (targetSlotName == "set_Body")
     {
         Body = null;
     }
 }
Example #55
0
 public override void OnInputDisconnected(BlockBase src, string srcSlotName, string targetSlotName)
 {
     base.OnInputDisconnected(src, srcSlotName, targetSlotName);
     if (targetSlotName == "set_Source1")
     {
         _sources[0] = null;
     }
     else if (targetSlotName == "set_Source2")
     {
         _sources[1] = null;
     }
     else if (targetSlotName == "set_Source3")
     {
         _sources[2] = null;
     }
 }
Example #56
0
        public BlockItem(BlockBase block)
        {
            Block = block;

            foreach (var e in block.Members)
            {
                if (e is MetaProperty)
                {
                    AddChild(new MetaPropertyItem(e as MetaProperty));
                }
                else if (e is Node)
                {
                    AddChild(new BlockItem((e as Node).Block));
                }
            }
        }
Example #57
0
 public override void OnInputDisconnected(BlockBase src, string srcSlotName, string targetSlotName)
 {
     base.OnInputDisconnected(src, srcSlotName, targetSlotName);
     if (targetSlotName == "set_LeftEye")
     {
         LeftEye = null;
     }
     if (targetSlotName == "set_RightEye")
     {
         RightEye = null;
     }
     if (targetSlotName == "set_Config")
     {
         Config = _tmpConfig;
     }
 }
Example #58
0
        public static NodeBase GetTarget(BlockBase parent, string name)
        {
            if (parent == null || name == null)
                return null;

            var i = parent.GetInt(name);
            if (i != null && i.Parent.Parent == null) return i;

            var s = parent.GetString(name);
            if (s != null && s.Parent.Parent == null) return s;

            if (parent.Parent == null) return null;

            var v = parent.GetVar(name);
            if (v != null && (v.Parent is Define || v.Parent.Parent == null))
                return Var.New(parent, v);

            return null;
        }
Example #59
0
	public BlockBase CreateBlock(BlockBase.BlockProperty type)
	{
		string prefabName = null;

		switch(type)
		{
		case BlockBase.BlockProperty.Empty:
			break;
		case BlockBase.BlockProperty.Movable:
			prefabName = "Movable";
			break;
		case BlockBase.BlockProperty.NonMovable:
			prefabName = "NonMovable";
			break;
		case BlockBase.BlockProperty.SlowPowerUp:
			prefabName = "SlowPowerUp";
			break;
		case BlockBase.BlockProperty.LaneChangerLeft:
			prefabName = "LaneChangerLeft";
			break;
		case BlockBase.BlockProperty.LaneChangerRight:
			prefabName = "LaneChangerRight";
			break;
		default:
			break;
		}

		if(prefabName != null)
		{
			GameObject block = Game.Instance.ObjectPool.GetFromPool(prefabName, true);
			if(block == null)
				return null;
			return block.GetComponent<BlockBase>();
		}
		return null;
	}
Example #60
0
	public static bool SetBlock(RaycastHit hit, BlockBase block) {
		if (hit.collider == null)
			return false;
		
		Chunk chunk = hit.collider.GetComponent<Chunk>();
		if (chunk == null)
			return false;
		
		WorldPos Pos = GetBlockPos(hit);
		chunk.world.SetBlock(Pos.x, Pos.y, Pos.z, block);
		
		// now save whenever i update blocks
		//Serialization.SaveChunk(chunk);
		return true;
	}