Toggle navigation
Toggle navigation
This project
Loading...
Sign in
arcs
/
arcs.js
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
3
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
Jean-Yves Didier
2022-04-02 11:18:34 +0200
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
f8e4dbf8a65f747f2e1afa2a6396e18a0d757265
f8e4dbf8
1 parent
a1e13ada
changes to shorten arcsapp description and remove useless fields in JSON
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
111 additions
and
99 deletions
build/arcs.js
example/arcsapp.json
example/loop.html
package.json
src/invocation.js
src/sheet.js
build/arcs.js
View file @
f8e4dbf
...
...
@@ -360,9 +360,14 @@ __webpack_require__.r(__webpack_exports__);
/**
* Describes a statemachine
* @param obj {object} an object describing a state machine. If obj is empty then the statemachine is empty
* @param obj.initial {String} name of the initial state of the statemachine
* @param obj.final {String} name of the final state of the statemachine
* @param obj.transitions {Object} transition object. Each key of the object is named after
* the name of a state and its associated value is an object whose keys are tokens
* and values the name of the state the transition should reach once activated
* by the token
* @class
*/
let
StateMachine
=
_component_js__WEBPACK_IMPORTED_MODULE_0__
.
default
.
create
(
function
(
obj
)
{
// dynamic construction: properties are initial state that have properties
// that are tokens and value that are the final state
...
...
@@ -399,18 +404,6 @@ let StateMachine = _component_js__WEBPACK_IMPORTED_MODULE_0__.default.create(fun
for
(
t
in
transitions
[
s
])
{
if
(
transitions
[
s
].
hasOwnProperty
(
t
))
{
network
[
t
]
=
_transitionnetwork_js__WEBPACK_IMPORTED_MODULE_1__
.
default
.
build
(
astTokens
[
s
][
t
],
tokenEvents
);
/*network = TransitionNetwork.build(astTokens[s][t],tokenEvents).promise;
network.then(
function() {
var token;
// clean up remaining promises
for (token in tokenEvents) {
if (tokenEvents.hasOwnProperty(token)) tokenEvents[token].abort();
}
// then activate next sheet
setSheet(transitions[s][t]);
}
);*/
}
}
}
...
...
@@ -502,20 +495,8 @@ let StateMachine = _component_js__WEBPACK_IMPORTED_MODULE_0__.default.create(fun
}
}
}
// we will temporay dump properties in order to understand how the statemachine is built
/*
for (p in transitions) {
if (transitions.hasOwnProperty(p)) {
for (t in transitions[p]) {
if (transitions[p].hasOwnProperty(t)) {
console.log("\t" + p + "\t----\t" + t + "\t--->\t" + transitions[p][t]);
}
}
}
}*/
};
/**
* Initialize and starts the statemachine, setting its current state to
* the initial state (by default, it is the departure of the first transition
...
...
@@ -1418,10 +1399,10 @@ __webpack_require__.r(__webpack_exports__);
/**
* @class Context
* @classdesc Class representing a context containing libraries and components
* used by different parts of the framework.
* @param ctx {object} an object representing data for the context.
* @class Context
*/
let
Context
=
function
(
ctx
)
{
let
components
=
{};
...
...
@@ -1540,6 +1521,7 @@ let Context = function( ctx ) {
* when the library is loaded.
* @param libName {string} name of the library to load
* @param cbFunction {function} callback function to call when library is loaded
* @function Context#loadLibrary
*/
this
.
loadLibrary
=
function
(
libName
,
cbFunction
)
{
var
libUrl
=
libName
,
libActualName
=
libName
;
...
...
@@ -1571,6 +1553,7 @@ let Context = function( ctx ) {
/**
* @return the component list stored inside context
* @function Context#getComponentList
*/
this
.
getComponentList
=
function
()
{
var
list
=
Object
.
keys
(
components
);
...
...
@@ -1584,34 +1567,30 @@ let Context = function( ctx ) {
return
list
;
};
/**
* @return a constant value stored by the engine given its name
* @param cName {String} name of the constant
* @function Context#getConstant
*/
this
.
getConstant
=
function
(
cName
)
{
/*if (!constants.hasOwnProperty(cName)) {
return undefined;
}*/
return
constants
[
cName
];
};
// to determine if really needed
this
.
getComponentType
=
function
(
cName
)
{
/*if (!components.hasOwnProperty(cName))
return undefined;*/
if
(
components
[
cName
]
===
undefined
)
return
undefined
;
return
components
[
cName
].
type
;
};
// to determine if really needed
this
.
getComponentValue
=
function
(
cName
)
{
/*if (!components.hasOwnProperty(cName))
return undefined;*/
if
(
components
[
cName
]
===
undefined
)
return
undefined
;
return
components
[
cName
].
value
;
};
// to determine if really needed
this
.
getComponent
=
function
(
cName
)
{
/*if (!components.hasOwnProperty(cName))
return undefined;*/
if
(
components
[
cName
]
===
undefined
)
return
undefined
;
return
components
[
cName
].
instance
;
};
...
...
@@ -1765,22 +1744,36 @@ __webpack_require__.r(__webpack_exports__);
* @param value {mixed} value passed to the invoked slot
* @constructor
*/
let
Invocation
=
function
(
destination
,
slot
,
value
)
{
/**
* Returns the destination component of this invocation
* @returns {object} destination component of this invocation
*/
this
.
getDestination
=
function
()
{
return
destination
;
};
/**
* Returns the slot name of this invocation
* @returns {String} slot name of this invocation
*/
this
.
getSlot
=
function
()
{
return
slot
;
};
/**
* Returns the value used for this invocation
* @returns {mixed} value used for this invocation
*/
this
.
getValue
=
function
()
{
return
value
;
};
/**
* Performs the invocation
*/
this
.
invoke
=
function
()
{
var
func
=
destination
[
slot
];
let
func
=
destination
[
slot
];
if
(
func
===
undefined
)
{
console
.
error
(
"Undefined slot %s of component %s"
,
slot
,
destination
);
return
;
...
...
@@ -1823,6 +1816,9 @@ Invocation.cast = function (obj, context) {
return
new
Invocation
(
component
,
obj
.
slot
,
data
);
}
// default invocation without any value
return
new
Invocation
(
component
,
obj
.
slot
);
};
/*ARCS.Invocation.revert = function(obj, context) {
...
...
@@ -2049,8 +2045,8 @@ let Sheet = function (ctx /*context*/) {
};
var
removeItem
=
function
(
id
,
tab
)
{
var
i
=
tab
.
length
;
let
removeItem
=
function
(
id
,
tab
)
{
let
i
=
tab
.
length
;
while
(
i
--
&&
tab
[
i
].
id
!==
id
);
...
...
@@ -2098,10 +2094,10 @@ let Sheet = function (ctx /*context*/) {
};
var
swapItems
=
function
(
id1
,
id2
,
tab
)
{
var
item
;
let
swapItems
=
function
(
id1
,
id2
,
tab
)
{
let
item
;
var
i
=
tab
.
length
,
j
=
tab
.
length
;
let
i
=
tab
.
length
,
j
=
tab
.
length
;
while
(
i
--
&&
tab
[
i
].
id
!==
id1
)
;
while
(
j
--
&&
tab
[
j
].
id
!==
id2
)
;
...
...
@@ -2132,20 +2128,28 @@ let Sheet = function (ctx /*context*/) {
};
var
cacheConnectionsInvocations
=
function
(
object
)
{
var
i
=
0
,
castInvocation
=
_invocation_js__WEBPACK_IMPORTED_MODULE_1__
.
default
.
cast
,
castConnection
=
_connection_js__WEBPACK_IMPORTED_MODULE_2__
.
default
.
cast
;
for
(
i
=
0
;
i
<
object
.
preconnections
.
length
;
i
++
)
{
preconnections
.
push
(
castInvocation
(
object
.
preconnections
[
i
],
context
));
let
cacheConnectionsInvocations
=
function
(
object
)
{
let
i
=
0
,
castInvocation
=
_invocation_js__WEBPACK_IMPORTED_MODULE_1__
.
default
.
cast
,
castConnection
=
_connection_js__WEBPACK_IMPORTED_MODULE_2__
.
default
.
cast
;
if
(
object
.
preconnections
!==
undefined
)
{
for
(
i
=
0
;
i
<
object
.
preconnections
.
length
;
i
++
)
{
preconnections
.
push
(
castInvocation
(
object
.
preconnections
[
i
],
context
));
}
}
if
(
object
.
postconnections
!==
undefined
)
{
for
(
i
=
0
;
i
<
object
.
postconnections
.
length
;
i
++
)
{
postconnections
.
push
(
castInvocation
(
object
.
postconnections
[
i
],
context
));
}
}
for
(
i
=
0
;
i
<
object
.
postconnections
.
length
;
i
++
)
{
postconnections
.
push
(
castInvocation
(
object
.
postconnections
[
i
],
context
));
if
(
object
.
cleanups
!==
undefined
)
{
for
(
i
=
0
;
i
<
object
.
cleanups
.
length
;
i
++
)
{
cleanups
.
push
(
castInvocation
(
object
.
cleanups
[
i
],
context
));
}
}
for
(
i
=
0
;
i
<
object
.
cleanups
.
length
;
i
++
)
{
cleanups
.
push
(
castInvocation
(
object
.
cleanups
[
i
],
context
));
if
(
object
.
connections
!==
undefined
)
{
for
(
i
=
0
;
i
<
object
.
connections
.
length
;
i
++
)
{
connections
.
push
(
castConnection
(
object
.
connections
[
i
],
context
));
}
}
for
(
i
=
0
;
i
<
object
.
connections
.
length
;
i
++
)
{
connections
.
push
(
castConnection
(
object
.
connections
[
i
],
context
));
}
};
/**
...
...
@@ -2165,7 +2169,7 @@ let Sheet = function (ctx /*context*/) {
});
};
var
revertInvocation
=
function
(
obj
)
{
let
revertInvocation
=
function
(
obj
)
{
return
{
destination
:
context
.
getComponentName
(
obj
.
getDestination
()),
slot
:
obj
.
getSlot
(),
...
...
@@ -2173,7 +2177,7 @@ let Sheet = function (ctx /*context*/) {
};
};
var
revertConnection
=
function
(
obj
)
{
let
revertConnection
=
function
(
obj
)
{
return
{
source
:
context
.
getComponentName
(
obj
.
getSource
()),
signal
:
obj
.
getSignal
(),
...
...
@@ -2183,12 +2187,12 @@ let Sheet = function (ctx /*context*/) {
};
this
.
toJSON
=
function
()
{
var
preconns
=
[];
var
postconns
=
[];
var
conns
=
[];
var
cleans
=
[];
let
preconns
=
[];
let
postconns
=
[];
let
conns
=
[];
let
cleans
=
[];
var
i
;
let
i
;
for
(
i
=
0
;
i
<
connections
.
length
;
i
++
)
{
conns
.
push
(
revertConnection
(
connections
[
i
]))
}
...
...
example/arcsapp.json
View file @
f8e4dbf
...
...
@@ -19,26 +19,22 @@
"controller"
:
"statemachine"
,
"sheets"
:
{
"start"
:
{
"preconnections"
:
[],
"postconnections"
:
[
{
"destination"
:
"loop"
,
"slot"
:
"setIterations"
,
"value"
:[
4
]
}
],
"connections"
:
[
{
"source"
:
"loop"
,
"signal"
:
"newIteration"
,
"destination"
:
"dint"
,
"slot"
:
"display"
},
{
"source"
:
"loop"
,
"signal"
:
"endLoop"
,
"destination"
:
"statemachine"
,
"slot"
:
"end"
}
],
"cleanups"
:
[]
]
},
"start2"
:
{
"preconnections"
:
[],
"postconnections"
:
[
{
"destination"
:
"loop"
,
"slot"
:
"setIterations"
,
"value"
:[
8
]
}
],
"connections"
:
[
{
"source"
:
"loop"
,
"signal"
:
"newIteration"
,
"destination"
:
"dint"
,
"slot"
:
"display"
},
{
"source"
:
"loop"
,
"signal"
:
"endLoop"
,
"destination"
:
"statemachine"
,
"slot"
:
"end"
}
],
"cleanups"
:
[]
]
}
}
}
...
...
example/loop.html
View file @
f8e4dbf
<html>
<head>
<title>
ARCS engine
</title>
<script
data-base-url=
".."
<head>
<title>
ARCS engine
</title>
<meta
charset=
"utf-8"
/>
<script
data-base-url=
".."
data-arcsapp=
"arcsapp.json"
type=
"module"
src=
"../build/arcs_browser.js"
>
...
...
@@ -11,11 +12,11 @@
font-family
:
sans-serif
;
}
</style>
</head>
<body>
<h1>
ARCS in Web Browser
</h1>
</head>
<body>
<h1>
ARCS in Web Browser
</h1>
<div
style=
"height:80vh; overflow: auto; border: solid 1px navy;"
>
<p
id=
"output"
style=
"margin: 5px; padding: 5px; font-family: monospace;"
></p>
<div>
</body>
</body>
</html>
...
...
package.json
View file @
f8e4dbf
{
"name"
:
"arcsjs"
,
"version"
:
"0.9.
3
"
,
"version"
:
"0.9.
4
"
,
"description"
:
"Augmented Reality Component System in web browser and node environment"
,
"homepage"
:
"http://arcs.ibisc.fr"
,
"repository"
:
{
...
...
src/invocation.js
View file @
f8e4dbf
...
...
@@ -37,7 +37,7 @@ let Invocation = function (destination, slot, value) {
* Performs the invocation
*/
this
.
invoke
=
function
()
{
var
func
=
destination
[
slot
];
let
func
=
destination
[
slot
];
if
(
func
===
undefined
)
{
console
.
error
(
"Undefined slot %s of component %s"
,
slot
,
destination
);
return
;
...
...
@@ -80,6 +80,9 @@ Invocation.cast = function (obj, context) {
return
new
Invocation
(
component
,
obj
.
slot
,
data
);
}
// default invocation without any value
return
new
Invocation
(
component
,
obj
.
slot
);
};
/*ARCS.Invocation.revert = function(obj, context) {
...
...
src/sheet.js
View file @
f8e4dbf
...
...
@@ -107,8 +107,8 @@ let Sheet = function (ctx /*context*/) {
};
var
removeItem
=
function
(
id
,
tab
)
{
var
i
=
tab
.
length
;
let
removeItem
=
function
(
id
,
tab
)
{
let
i
=
tab
.
length
;
while
(
i
--
&&
tab
[
i
].
id
!==
id
);
...
...
@@ -156,10 +156,10 @@ let Sheet = function (ctx /*context*/) {
};
var
swapItems
=
function
(
id1
,
id2
,
tab
)
{
var
item
;
let
swapItems
=
function
(
id1
,
id2
,
tab
)
{
let
item
;
var
i
=
tab
.
length
,
j
=
tab
.
length
;
let
i
=
tab
.
length
,
j
=
tab
.
length
;
while
(
i
--
&&
tab
[
i
].
id
!==
id1
)
;
while
(
j
--
&&
tab
[
j
].
id
!==
id2
)
;
...
...
@@ -190,20 +190,28 @@ let Sheet = function (ctx /*context*/) {
};
var
cacheConnectionsInvocations
=
function
(
object
)
{
var
i
=
0
,
castInvocation
=
Invocation
.
cast
,
castConnection
=
Connection
.
cast
;
for
(
i
=
0
;
i
<
object
.
preconnections
.
length
;
i
++
)
{
preconnections
.
push
(
castInvocation
(
object
.
preconnections
[
i
],
context
));
let
cacheConnectionsInvocations
=
function
(
object
)
{
let
i
=
0
,
castInvocation
=
Invocation
.
cast
,
castConnection
=
Connection
.
cast
;
if
(
object
.
preconnections
!==
undefined
)
{
for
(
i
=
0
;
i
<
object
.
preconnections
.
length
;
i
++
)
{
preconnections
.
push
(
castInvocation
(
object
.
preconnections
[
i
],
context
));
}
}
for
(
i
=
0
;
i
<
object
.
postconnections
.
length
;
i
++
)
{
postconnections
.
push
(
castInvocation
(
object
.
postconnections
[
i
],
context
));
if
(
object
.
postconnections
!==
undefined
)
{
for
(
i
=
0
;
i
<
object
.
postconnections
.
length
;
i
++
)
{
postconnections
.
push
(
castInvocation
(
object
.
postconnections
[
i
],
context
));
}
}
for
(
i
=
0
;
i
<
object
.
cleanups
.
length
;
i
++
)
{
cleanups
.
push
(
castInvocation
(
object
.
cleanups
[
i
],
context
));
if
(
object
.
cleanups
!==
undefined
)
{
for
(
i
=
0
;
i
<
object
.
cleanups
.
length
;
i
++
)
{
cleanups
.
push
(
castInvocation
(
object
.
cleanups
[
i
],
context
));
}
}
if
(
object
.
connections
!==
undefined
)
{
for
(
i
=
0
;
i
<
object
.
connections
.
length
;
i
++
)
{
connections
.
push
(
castConnection
(
object
.
connections
[
i
],
context
));
}
}
for
(
i
=
0
;
i
<
object
.
connections
.
length
;
i
++
)
{
connections
.
push
(
castConnection
(
object
.
connections
[
i
],
context
));
}
};
/**
...
...
@@ -223,7 +231,7 @@ let Sheet = function (ctx /*context*/) {
});
};
var
revertInvocation
=
function
(
obj
)
{
let
revertInvocation
=
function
(
obj
)
{
return
{
destination
:
context
.
getComponentName
(
obj
.
getDestination
()),
slot
:
obj
.
getSlot
(),
...
...
@@ -231,7 +239,7 @@ let Sheet = function (ctx /*context*/) {
};
};
var
revertConnection
=
function
(
obj
)
{
let
revertConnection
=
function
(
obj
)
{
return
{
source
:
context
.
getComponentName
(
obj
.
getSource
()),
signal
:
obj
.
getSignal
(),
...
...
@@ -241,12 +249,12 @@ let Sheet = function (ctx /*context*/) {
};
this
.
toJSON
=
function
()
{
var
preconns
=
[];
var
postconns
=
[];
var
conns
=
[];
var
cleans
=
[];
let
preconns
=
[];
let
postconns
=
[];
let
conns
=
[];
let
cleans
=
[];
var
i
;
let
i
;
for
(
i
=
0
;
i
<
connections
.
length
;
i
++
)
{
conns
.
push
(
revertConnection
(
connections
[
i
]))
}
...
...
Please
register
or
login
to post a comment