12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- import Tool from './Tool';
- import {Tools} from '../Tools/index'
- import React from 'react';
- import {StyleSheet,View , Text} from 'react-native';
- import Mouse from './mouse';
- function log(args){
- console.log(args)
- }
- export default class ToolBox {
- constructor(CoreSystem, defaultTool = 'Select'){
- this.CoreSystem = CoreSystem;
- this.tools = {};
- this.activeTool = null;
- this.loadTools(defaultTool);
- this.__onUpdate = null;
- //this.selectTool('Select')
-
- }
- on(e) { return this.activeTool.on(e) }
- editNode(View){
- console.log("@@@@@@@ wHTTTATATATA")
- console.log(View)
- return this.activeTool.editViewNode(this.CoreSystem,View);
- }
- onUpdate(fn){
- this.__onUpdate = fn;
- }
- update(){
- this.__onUpdate && this.__onUpdate();
- }
- selectTool(key){
- let tool = this.tools[key];
- this.activeTool = tool;
- this.update()
- }
- loadTools(defaultTool){
- log("Loading Tools")
- Object.keys(Tools).map((key) => {
- if( Tools[key].prototype instanceof Tool === false ){
- throw new Error("This is not a Tool")
- }
- if(this.tools[key]){
- log("Tool already Exists: ",key);
- }
- this.tools[key] = new Tools[key]();
- })
- if(defaultTool && this.tools[defaultTool]) {
- this.activeTool = this.tools[defaultTool];
- }
- }
- render(){
- let tools = Object.keys(this.tools).map((key) => {
- let toolStyle = styles.tool;
- if(this.activeTool !== null){
-
- if(this.activeTool.constructor.name === key){
- toolStyle = styles.activeTool;
- }
- }
- return(
- <View onClick={() => this.selectTool(key) } style={ toolStyle}>{this.tools[key].render()}</View>)});
- return tools;
- }
- }
- /** Must be remove from here**/
- const styles = StyleSheet.create({
- tool:{
- padding: 5
- },
- activeTool:{
- backgroundColor:'green',
- padding: 5
- }
- })
|