|
@@ -10,11 +10,11 @@
|
|
|
<meta property="og:url" content="https://minigrid.farama.org/_modules/gymnasium/core.html" /><meta property="og:image" content="https://minigrid.farama.org//_static/img/minigrid-github.png" /><meta name="twitter:card" content="summary_large_image"><link rel="index" title="Index" href="../../../genindex/" /><link rel="search" title="Search" href="../../../search/" />
|
|
|
<link rel="canonical" href="https://minigrid.farama.org/_modules/gymnasium/core.html" />
|
|
|
|
|
|
- <link rel="shortcut icon" href="../../../_static/minigrid-favicon.png"/><!-- Generated with Sphinx 5.2.3 and Furo 2022.12.07.dev1 -->
|
|
|
+ <link rel="shortcut icon" href="../../../_static/minigrid-favicon.png"/><!-- Generated with Sphinx 7.0.1 and Furo 2023.05.20.dev1 -->
|
|
|
<title>gymnasium.core - MiniGrid Documentation</title>
|
|
|
<link rel="stylesheet" type="text/css" href="../../../_static/pygments.css" />
|
|
|
- <link rel="stylesheet" type="text/css" href="../../../_static/styles/furo.css?digest=cfd2cc3354364f303ef4a892d279bfffada5835d" />
|
|
|
- <link rel="stylesheet" type="text/css" href="../../../_static/styles/furo-extensions.css?digest=6342a809aabeb35cfac296000cfa245808bc1d78" />
|
|
|
+ <link rel="stylesheet" type="text/css" href="../../../_static/styles/furo.css?digest=2b6f8eb5452c44539a42dd9ada0a48f56e5f404d" />
|
|
|
+ <link rel="stylesheet" type="text/css" href="../../../_static/styles/furo-extensions.css?digest=d98e5db1aa483f10fd0a50bf79700ebb0c5bab79" />
|
|
|
|
|
|
|
|
|
|
|
@@ -52,18 +52,6 @@
|
|
|
<line x1="0.232" y1="12" x2="23.5" y2="12"></line>
|
|
|
<line x1="0.232" y1="20" x2="23.5" y2="20"></line>
|
|
|
</svg>
|
|
|
- <!-- <svg viewBox="0 0 24 24" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
|
|
|
- <line x1="0.5" y1="4.5" x2="23.5" y2="4.5" style="fill: none; "></line>
|
|
|
- <line x1="0.5" y1="12" x2="14" y2="12" ></line>
|
|
|
- <line x1="0.5" y1="19.5" x2="23.5" y2="19.5"></line>
|
|
|
- <polyline style="stroke-width: 0px;" points="17 7 22 12 17 17"></polyline>
|
|
|
- </svg> -->
|
|
|
- <!-- <svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" style="width:20px">
|
|
|
- <defs></defs>
|
|
|
- <rect y="1" width="22" height="22" rx="2" ry="2" style="fill: none;" x="1"></rect>
|
|
|
- <line x1="8" y1="1" x2="8" y2="23"></line>
|
|
|
- <polyline style="stroke-linecap: round; fill: none; stroke-linejoin: round;" points="13 7 17 12 13 17"></polyline>
|
|
|
- </svg> -->
|
|
|
</label>
|
|
|
</div>
|
|
|
<div class="farama-header__left farama-header__center--mobile">
|
|
@@ -227,15 +215,20 @@
|
|
|
<li class="toctree-l1"><a class="reference internal" href="../../../content/basic_usage/#training-an-agent">Training an Agent</a></li>
|
|
|
<li class="toctree-l1"><a class="reference internal" href="../../../content/publications/">List of Publications</a></li>
|
|
|
<li class="toctree-l1"><a class="reference internal" href="../../../content/create_env_tutorial/">Tutorial on Creating Environments</a></li>
|
|
|
+<li class="toctree-l1"><a class="reference internal" href="../../../content/training/">Training Minigrid Environments</a></li>
|
|
|
+<li class="toctree-l1"><a class="reference internal" href="../../../content/training/#create-custom-feature-extractor">Create Custom Feature Extractor</a></li>
|
|
|
+<li class="toctree-l1"><a class="reference internal" href="../../../content/training/#train-a-ppo-agent">Train a PPO Agent</a></li>
|
|
|
+<li class="toctree-l1"><a class="reference internal" href="../../../content/training/#further-reading">Further Reading</a></li>
|
|
|
</ul>
|
|
|
<p class="caption" role="heading"><span class="caption-text">Wrappers</span></p>
|
|
|
<ul>
|
|
|
-<li class="toctree-l1 has-children"><a class="reference internal" href="../../../api/wrapper/">Wrapper</a><input class="toctree-checkbox" id="toctree-checkbox-1" name="toctree-checkbox-1" role="switch" type="checkbox"/><label for="toctree-checkbox-1"><div class="visually-hidden">Toggle child pages in navigation</div><i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i></label><ul>
|
|
|
+<li class="toctree-l1 has-children"><a class="reference internal" href="../../../api/wrapper/">Wrapper</a><input class="toctree-checkbox" id="toctree-checkbox-1" name="toctree-checkbox-1" role="switch" type="checkbox"/><label for="toctree-checkbox-1"><div class="visually-hidden">Toggle navigation of Wrapper</div><i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i></label><ul>
|
|
|
<li class="toctree-l2"><a class="reference internal" href="../../../api/wrappers/">Action Bonus</a></li>
|
|
|
<li class="toctree-l2"><a class="reference internal" href="../../../api/wrappers/#dict-observation-space">Dict Observation Space</a></li>
|
|
|
<li class="toctree-l2"><a class="reference internal" href="../../../api/wrappers/#direction-obs">Direction Obs</a></li>
|
|
|
<li class="toctree-l2"><a class="reference internal" href="../../../api/wrappers/#flatobs">FlatObs</a></li>
|
|
|
<li class="toctree-l2"><a class="reference internal" href="../../../api/wrappers/#fully-obs">Fully Obs</a></li>
|
|
|
+<li class="toctree-l2"><a class="reference internal" href="../../../api/wrappers/#no-death">No Death</a></li>
|
|
|
<li class="toctree-l2"><a class="reference internal" href="../../../api/wrappers/#observation">Observation</a></li>
|
|
|
<li class="toctree-l2"><a class="reference internal" href="../../../api/wrappers/#one-hot-partial-obs">One Hot Partial Obs</a></li>
|
|
|
<li class="toctree-l2"><a class="reference internal" href="../../../api/wrappers/#reseed">Reseed</a></li>
|
|
@@ -248,7 +241,7 @@
|
|
|
</ul>
|
|
|
<p class="caption" role="heading"><span class="caption-text">Environments</span></p>
|
|
|
<ul>
|
|
|
-<li class="toctree-l1 has-children"><a class="reference internal" href="../../../environments/minigrid/">Minigrid Environments</a><input class="toctree-checkbox" id="toctree-checkbox-2" name="toctree-checkbox-2" role="switch" type="checkbox"/><label for="toctree-checkbox-2"><div class="visually-hidden">Toggle child pages in navigation</div><i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i></label><ul>
|
|
|
+<li class="toctree-l1 has-children"><a class="reference internal" href="../../../environments/minigrid/">Minigrid Environments</a><input class="toctree-checkbox" id="toctree-checkbox-2" name="toctree-checkbox-2" role="switch" type="checkbox"/><label for="toctree-checkbox-2"><div class="visually-hidden">Toggle navigation of Minigrid Environments</div><i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i></label><ul>
|
|
|
<li class="toctree-l2"><a class="reference internal" href="../../../environments/minigrid/BlockedUnlockPickupEnv/">Blocked Unlock Pickup</a></li>
|
|
|
<li class="toctree-l2"><a class="reference internal" href="../../../environments/minigrid/CrossingEnv/">Crossing</a></li>
|
|
|
<li class="toctree-l2"><a class="reference internal" href="../../../environments/minigrid/DistShiftEnv/">Dist Shift</a></li>
|
|
@@ -273,7 +266,7 @@
|
|
|
<li class="toctree-l2"><a class="reference internal" href="../../../environments/minigrid/UnlockPickupEnv/">Unlock Pickup</a></li>
|
|
|
</ul>
|
|
|
</li>
|
|
|
-<li class="toctree-l1 has-children"><a class="reference internal" href="../../../environments/babyai/">BabyAI Environments</a><input class="toctree-checkbox" id="toctree-checkbox-3" name="toctree-checkbox-3" role="switch" type="checkbox"/><label for="toctree-checkbox-3"><div class="visually-hidden">Toggle child pages in navigation</div><i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i></label><ul>
|
|
|
+<li class="toctree-l1 has-children"><a class="reference internal" href="../../../environments/babyai/">BabyAI Environments</a><input class="toctree-checkbox" id="toctree-checkbox-3" name="toctree-checkbox-3" role="switch" type="checkbox"/><label for="toctree-checkbox-3"><div class="visually-hidden">Toggle navigation of BabyAI Environments</div><i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i></label><ul>
|
|
|
<li class="toctree-l2"><a class="reference internal" href="../../../environments/babyai/GoToRedBallGrey/">Go To Red Ball Grey</a></li>
|
|
|
<li class="toctree-l2"><a class="reference internal" href="../../../environments/babyai/GoToRedBall/">Go To Red Ball</a></li>
|
|
|
<li class="toctree-l2"><a class="reference internal" href="../../../environments/babyai/GoToRedBallNoDists/">Go To Red Ball No Dists</a></li>
|
|
@@ -377,7 +370,7 @@
|
|
|
|
|
|
<span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
|
|
|
|
|
|
-<span class="kn">from</span> <span class="nn">gymnasium</span> <span class="kn">import</span> <span class="n">spaces</span>
|
|
|
+<span class="kn">from</span> <span class="nn">gymnasium</span> <span class="kn">import</span> <span class="n">logger</span><span class="p">,</span> <span class="n">spaces</span>
|
|
|
<span class="kn">from</span> <span class="nn">gymnasium.utils</span> <span class="kn">import</span> <span class="n">RecordConstructorArgs</span><span class="p">,</span> <span class="n">seeding</span>
|
|
|
|
|
|
|
|
@@ -556,6 +549,7 @@
|
|
|
<span class="w"> </span><span class="sd">"""After the user has finished using the environment, close contains the code necessary to "clean up" the environment.</span>
|
|
|
|
|
|
<span class="sd"> This is critical for closing rendering windows, database or HTTP connections.</span>
|
|
|
+<span class="sd"> Calling ``close`` on an already closed environment has no effect and won't raise an error.</span>
|
|
|
<span class="sd"> """</span>
|
|
|
<span class="k">pass</span>
|
|
|
|
|
@@ -604,6 +598,10 @@
|
|
|
<span class="c1"># propagate exception</span>
|
|
|
<span class="k">return</span> <span class="kc">False</span>
|
|
|
|
|
|
+ <span class="k">def</span> <span class="nf">get_wrapper_attr</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">name</span><span class="p">:</span> <span class="nb">str</span><span class="p">)</span> <span class="o">-></span> <span class="n">Any</span><span class="p">:</span>
|
|
|
+<span class="w"> </span><span class="sd">"""Gets the attribute `name` from the environment."""</span>
|
|
|
+ <span class="k">return</span> <span class="nb">getattr</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">name</span><span class="p">)</span>
|
|
|
+
|
|
|
|
|
|
<span class="n">WrapperObsType</span> <span class="o">=</span> <span class="n">TypeVar</span><span class="p">(</span><span class="s2">"WrapperObsType"</span><span class="p">)</span>
|
|
|
<span class="n">WrapperActType</span> <span class="o">=</span> <span class="n">TypeVar</span><span class="p">(</span><span class="s2">"WrapperActType"</span><span class="p">)</span>
|
|
@@ -643,15 +641,48 @@
|
|
|
<span class="bp">self</span><span class="o">.</span><span class="n">_cached_spec</span><span class="p">:</span> <span class="n">EnvSpec</span> <span class="o">|</span> <span class="kc">None</span> <span class="o">=</span> <span class="kc">None</span>
|
|
|
|
|
|
<span class="k">def</span> <span class="fm">__getattr__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">name</span><span class="p">:</span> <span class="nb">str</span><span class="p">)</span> <span class="o">-></span> <span class="n">Any</span><span class="p">:</span>
|
|
|
-<span class="w"> </span><span class="sd">"""Returns an attribute with ``name``, unless ``name`` starts with an underscore."""</span>
|
|
|
+<span class="w"> </span><span class="sd">"""Returns an attribute with ``name``, unless ``name`` starts with an underscore.</span>
|
|
|
+
|
|
|
+<span class="sd"> Args:</span>
|
|
|
+<span class="sd"> name: The variable name</span>
|
|
|
+
|
|
|
+<span class="sd"> Returns:</span>
|
|
|
+<span class="sd"> The value of the variable in the wrapper stack</span>
|
|
|
+
|
|
|
+<span class="sd"> Warnings:</span>
|
|
|
+<span class="sd"> This feature is deprecated and removed in v1.0 and replaced with `env.get_attr(name})`</span>
|
|
|
+<span class="sd"> """</span>
|
|
|
<span class="k">if</span> <span class="n">name</span> <span class="o">==</span> <span class="s2">"_np_random"</span><span class="p">:</span>
|
|
|
<span class="k">raise</span> <span class="ne">AttributeError</span><span class="p">(</span>
|
|
|
<span class="s2">"Can't access `_np_random` of a wrapper, use `self.unwrapped._np_random` or `self.np_random`."</span>
|
|
|
<span class="p">)</span>
|
|
|
<span class="k">elif</span> <span class="n">name</span><span class="o">.</span><span class="n">startswith</span><span class="p">(</span><span class="s2">"_"</span><span class="p">):</span>
|
|
|
<span class="k">raise</span> <span class="ne">AttributeError</span><span class="p">(</span><span class="sa">f</span><span class="s2">"accessing private attribute '</span><span class="si">{</span><span class="n">name</span><span class="si">}</span><span class="s2">' is prohibited"</span><span class="p">)</span>
|
|
|
+ <span class="n">logger</span><span class="o">.</span><span class="n">warn</span><span class="p">(</span>
|
|
|
+ <span class="sa">f</span><span class="s2">"env.</span><span class="si">{</span><span class="n">name</span><span class="si">}</span><span class="s2"> to get variables from other wrappers is deprecated and will be removed in v1.0, "</span>
|
|
|
+ <span class="sa">f</span><span class="s2">"to get this variable you can do `env.unwrapped.</span><span class="si">{</span><span class="n">name</span><span class="si">}</span><span class="s2">` for environment variables or `env.get_attr('</span><span class="si">{</span><span class="n">name</span><span class="si">}</span><span class="s2">')` that will search the reminding wrappers."</span>
|
|
|
+ <span class="p">)</span>
|
|
|
<span class="k">return</span> <span class="nb">getattr</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">env</span><span class="p">,</span> <span class="n">name</span><span class="p">)</span>
|
|
|
|
|
|
+ <span class="k">def</span> <span class="nf">get_wrapper_attr</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">name</span><span class="p">:</span> <span class="nb">str</span><span class="p">)</span> <span class="o">-></span> <span class="n">Any</span><span class="p">:</span>
|
|
|
+<span class="w"> </span><span class="sd">"""Gets an attribute from the wrapper and lower environments if `name` doesn't exist in this object.</span>
|
|
|
+
|
|
|
+<span class="sd"> Args:</span>
|
|
|
+<span class="sd"> name: The variable name to get</span>
|
|
|
+
|
|
|
+<span class="sd"> Returns:</span>
|
|
|
+<span class="sd"> The variable with name in wrapper or lower environments</span>
|
|
|
+<span class="sd"> """</span>
|
|
|
+ <span class="k">if</span> <span class="nb">hasattr</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">name</span><span class="p">):</span>
|
|
|
+ <span class="k">return</span> <span class="nb">getattr</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">name</span><span class="p">)</span>
|
|
|
+ <span class="k">else</span><span class="p">:</span>
|
|
|
+ <span class="k">try</span><span class="p">:</span>
|
|
|
+ <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">env</span><span class="o">.</span><span class="n">get_wrapper_attr</span><span class="p">(</span><span class="n">name</span><span class="p">)</span>
|
|
|
+ <span class="k">except</span> <span class="ne">AttributeError</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
|
|
|
+ <span class="k">raise</span> <span class="ne">AttributeError</span><span class="p">(</span>
|
|
|
+ <span class="sa">f</span><span class="s2">"wrapper </span><span class="si">{</span><span class="bp">self</span><span class="o">.</span><span class="n">class_name</span><span class="p">()</span><span class="si">}</span><span class="s2"> has no attribute </span><span class="si">{</span><span class="n">name</span><span class="si">!r}</span><span class="s2">"</span>
|
|
|
+ <span class="p">)</span> <span class="kn">from</span> <span class="nn">e</span>
|
|
|
+
|
|
|
<span class="nd">@property</span>
|
|
|
<span class="k">def</span> <span class="nf">spec</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-></span> <span class="n">EnvSpec</span> <span class="o">|</span> <span class="kc">None</span><span class="p">:</span>
|
|
|
<span class="w"> </span><span class="sd">"""Returns the :attr:`Env` :attr:`spec` attribute with the `WrapperSpec` if the wrapper inherits from `EzPickle`."""</span>
|
|
@@ -731,6 +762,7 @@
|
|
|
<span class="w"> </span><span class="sd">"""Return the :attr:`Env` :attr:`reward_range` unless overwritten then the wrapper :attr:`reward_range` is used."""</span>
|
|
|
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">_reward_range</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
|
|
|
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">env</span><span class="o">.</span><span class="n">reward_range</span>
|
|
|
+ <span class="n">logger</span><span class="o">.</span><span class="n">warn</span><span class="p">(</span><span class="s2">"The `reward_range` is deprecated and will be removed in v1.0"</span><span class="p">)</span>
|
|
|
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_reward_range</span>
|
|
|
|
|
|
<span class="nd">@reward_range</span><span class="o">.</span><span class="n">setter</span>
|
|
@@ -981,49 +1013,97 @@
|
|
|
</script>
|
|
|
|
|
|
|
|
|
- <script>
|
|
|
- (() => {
|
|
|
- if (!localStorage.getItem("shownCookieAlert")) {
|
|
|
- const boxElem = document.createElement("div");
|
|
|
- boxElem.classList.add("cookie-alert");
|
|
|
- const containerElem = document.createElement("div");
|
|
|
- containerElem.classList.add("cookie-alert__container");
|
|
|
- const textElem = document.createElement("p");
|
|
|
- textElem.innerHTML = `This page uses <a href="https://analytics.google.com/">
|
|
|
- Google Analytics</a> to collect statistics. You can disable it by blocking
|
|
|
- the JavaScript coming from www.google-analytics.com.`;
|
|
|
- containerElem.appendChild(textElem);
|
|
|
- const closeBtn = document.createElement("button");
|
|
|
- closeBtn.innerHTML = `<?xml version="1.0" ?><svg viewBox="0 0 32 32" xmlns="http://www.w3.org/2000/svg"><defs><style>.cls-1{fill:none;stroke:#000;stroke-linecap:round;stroke-linejoin:round;stroke-width:2px;}</style></defs><title/><g id="cross"><line class="cls-1" x1="7" x2="25" y1="7" y2="25"/><line class="cls-1" x1="7" x2="25" y1="25" y2="7"/></g></svg>`
|
|
|
- closeBtn.onclick = () => {
|
|
|
- localStorage.setItem("shownCookieAlert", "true");
|
|
|
- boxElem.style.display = "none";
|
|
|
+ <script async src="https://www.googletagmanager.com/gtag/js?id=G-FBXJQQLXKD"></script>
|
|
|
+ <script>
|
|
|
+ const enableGtag = () => {
|
|
|
+ window.dataLayer = window.dataLayer || [];
|
|
|
+ function gtag(){dataLayer.push(arguments);}
|
|
|
+ gtag('js', new Date());
|
|
|
+ gtag('config', 'G-FBXJQQLXKD');
|
|
|
+ }
|
|
|
+ (() => {
|
|
|
+ if (!localStorage.getItem("acceptedCookieAlert")) {
|
|
|
+ const boxElem = document.createElement("div");
|
|
|
+ boxElem.classList.add("cookie-alert");
|
|
|
+ const containerElem = document.createElement("div");
|
|
|
+ containerElem.classList.add("cookie-alert__container");
|
|
|
+ const textElem = document.createElement("p");
|
|
|
+ textElem.innerHTML = `This page uses <a href="https://analytics.google.com/">
|
|
|
+ Google Analytics</a> to collect statistics.`;
|
|
|
+ containerElem.appendChild(textElem);
|
|
|
+
|
|
|
+ const declineBtn = Object.assign(document.createElement("button"),
|
|
|
+ {
|
|
|
+ innerText: "Deny",
|
|
|
+ className: "farama-btn cookie-alert__button",
|
|
|
+ id: "cookie-alert__decline",
|
|
|
}
|
|
|
- containerElem.appendChild(closeBtn);
|
|
|
- boxElem.appendChild(containerElem);
|
|
|
- document.body.appendChild(boxElem);
|
|
|
- }
|
|
|
- })()
|
|
|
- </script>
|
|
|
+ );
|
|
|
+ declineBtn.addEventListener("click", () => {
|
|
|
+ localStorage.setItem("acceptedCookieAlert", false);
|
|
|
+ boxElem.remove();
|
|
|
+ });
|
|
|
|
|
|
- <script async src="https://www.googletagmanager.com/gtag/js?id=G-FBXJQQLXKD"></script>
|
|
|
- <script>
|
|
|
- window.dataLayer = window.dataLayer || [];
|
|
|
- function gtag(){dataLayer.push(arguments);}
|
|
|
- gtag('js', new Date());
|
|
|
+ const acceptBtn = Object.assign(document.createElement("button"),
|
|
|
+ {
|
|
|
+ innerText: "Allow",
|
|
|
+ className: "farama-btn cookie-alert__button",
|
|
|
+ id: "cookie-alert__accept",
|
|
|
+ }
|
|
|
+ );
|
|
|
+ acceptBtn.addEventListener("click", () => {
|
|
|
+ localStorage.setItem("acceptedCookieAlert", true);
|
|
|
+ boxElem.remove();
|
|
|
+ enableGtag();
|
|
|
+ });
|
|
|
|
|
|
- gtag('config', 'G-FBXJQQLXKD');
|
|
|
+ containerElem.appendChild(declineBtn);
|
|
|
+ containerElem.appendChild(acceptBtn);
|
|
|
+ boxElem.appendChild(containerElem);
|
|
|
+ document.body.appendChild(boxElem);
|
|
|
+ } else if (localStorage.getItem("acceptedCookieAlert") === "true") {
|
|
|
+ enableGtag();
|
|
|
+ }
|
|
|
+ })()
|
|
|
</script>
|
|
|
|
|
|
<script data-url_root="../../../" id="documentation_options" src="../../../_static/documentation_options.js"></script>
|
|
|
- <script src="../../../_static/jquery.js"></script>
|
|
|
- <script src="../../../_static/underscore.js"></script>
|
|
|
- <script src="../../../_static/_sphinx_javascript_frameworks_compat.js"></script>
|
|
|
<script src="../../../_static/doctools.js"></script>
|
|
|
<script src="../../../_static/sphinx_highlight.js"></script>
|
|
|
<script src="../../../_static/scripts/furo.js"></script>
|
|
|
|
|
|
<script>
|
|
|
+
|
|
|
+ const createProjectsList = (projects, displayImages) => {
|
|
|
+ const ulElem = Object.assign(document.createElement('ul'),
|
|
|
+ {
|
|
|
+ className:'farama-header-menu-list',
|
|
|
+ }
|
|
|
+ )
|
|
|
+ for (let project of projects) {
|
|
|
+ const liElem = document.createElement("li");
|
|
|
+ const aElem = Object.assign(document.createElement("a"),
|
|
|
+ {
|
|
|
+ href: project.link
|
|
|
+ }
|
|
|
+ );
|
|
|
+ liElem.appendChild(aElem);
|
|
|
+ if (displayImages) {
|
|
|
+ const imgElem = Object.assign(document.createElement("img"),
|
|
|
+ {
|
|
|
+ src: project.image ? imagesBasepath + project.image : imagesBasepath + "/farama_black.svg",
|
|
|
+ alt: `${project.name} logo`,
|
|
|
+ className: "farama-black-logo-invert"
|
|
|
+ }
|
|
|
+ );
|
|
|
+ aElem.appendChild(imgElem);
|
|
|
+ }
|
|
|
+ aElem.appendChild(document.createTextNode(project.name));
|
|
|
+ ulElem.appendChild(liElem);
|
|
|
+ }
|
|
|
+ return ulElem;
|
|
|
+ }
|
|
|
+
|
|
|
// Create menu with Farama projects by using the API at farama.org/api/projects.json
|
|
|
const createCORSRequest = (method, url) => {
|
|
|
let xhr = new XMLHttpRequest();
|
|
@@ -1050,9 +1130,15 @@
|
|
|
xhr.onload = () => {
|
|
|
const jsonResponse = xhr.response;
|
|
|
const sections = {
|
|
|
- "Documentation": [],
|
|
|
- "Mature Projects": [],
|
|
|
- "Incubating Projects": [],
|
|
|
+ "Core Projects": [],
|
|
|
+ "Mature Projects": {
|
|
|
+ "Documentation": [],
|
|
|
+ "Repositories": [],
|
|
|
+ },
|
|
|
+ "Incubating Projects": {
|
|
|
+ "Documentation": [],
|
|
|
+ "Repositories": [],
|
|
|
+ },
|
|
|
"Foundation": [
|
|
|
{
|
|
|
name: "About",
|
|
@@ -1068,28 +1154,38 @@
|
|
|
}
|
|
|
]
|
|
|
}
|
|
|
+
|
|
|
+ // Categorize projects
|
|
|
Object.keys(jsonResponse).forEach(key => {
|
|
|
projectJson = jsonResponse[key];
|
|
|
if (projectJson.website !== null) {
|
|
|
projectJson.link = projectJson.website;
|
|
|
- sections["Documentation"].push(projectJson)
|
|
|
- } else if (projectJson.type == "mature") {
|
|
|
- projectJson.link = projectJson.github;
|
|
|
- sections["Mature Projects"].push(projectJson)
|
|
|
} else {
|
|
|
projectJson.link = projectJson.github;
|
|
|
- sections["Incubating Projects"].push(projectJson)
|
|
|
+ }
|
|
|
+ if (projectJson.type === "core") {
|
|
|
+ sections["Core Projects"].push(projectJson)
|
|
|
+ } else if (projectJson.type == "mature") {
|
|
|
+ if (projectJson.website !== null) {
|
|
|
+ sections["Mature Projects"]["Documentation"].push(projectJson)
|
|
|
+ } else {
|
|
|
+ sections["Mature Projects"]["Repositories"].push(projectJson)
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (projectJson.website !== null) {
|
|
|
+ sections["Incubating Projects"]["Documentation"].push(projectJson)
|
|
|
+ } else {
|
|
|
+ sections["Incubating Projects"]["Repositories"].push(projectJson)
|
|
|
+ }
|
|
|
}
|
|
|
})
|
|
|
|
|
|
const menuContainer = document.querySelector(".farama-header-menu__body");
|
|
|
|
|
|
Object.keys(sections).forEach((key, i) => {
|
|
|
- projects = sections[key];
|
|
|
const sectionElem = Object.assign(
|
|
|
document.createElement('div'), {
|
|
|
className:'farama-header-menu__section',
|
|
|
- style: "padding-left: 24px"
|
|
|
}
|
|
|
)
|
|
|
sectionElem.appendChild(Object.assign(document.createElement('span'),
|
|
@@ -1098,33 +1194,37 @@
|
|
|
innerText: key
|
|
|
}
|
|
|
))
|
|
|
- const ulElem = Object.assign(document.createElement('ul'),
|
|
|
- {
|
|
|
- className:'farama-header-menu-list',
|
|
|
- }
|
|
|
- )
|
|
|
- for (let project of projects) {
|
|
|
- const liElem = document.createElement("li");
|
|
|
- const aElem = Object.assign(document.createElement("a"),
|
|
|
- {
|
|
|
- href: project.link
|
|
|
- }
|
|
|
- );
|
|
|
- liElem.appendChild(aElem);
|
|
|
- if (key !== "Foundation") {
|
|
|
- const imgElem = Object.assign(document.createElement("img"),
|
|
|
+ // is not a list
|
|
|
+ if (sections[key].constructor !== Array) {
|
|
|
+ const subSections = sections[key];
|
|
|
+ const subSectionContainerElem = Object.assign(
|
|
|
+ document.createElement('div'), {
|
|
|
+ className:'farama-header-menu__subsections-container',
|
|
|
+ style: key == "Mature Projects" ? "display: flex" : ""
|
|
|
+ }
|
|
|
+ )
|
|
|
+ Object.keys(subSections).forEach((subKey, i) => {
|
|
|
+ const subSectionElem = Object.assign(
|
|
|
+ document.createElement('div'), {
|
|
|
+ className:'farama-header-menu__subsection',
|
|
|
+ }
|
|
|
+ )
|
|
|
+ subSectionElem.appendChild(Object.assign(document.createElement('span'),
|
|
|
{
|
|
|
- src: project.image ? imagesBasepath + project.image : imagesBasepath + "/farama_black.svg",
|
|
|
- alt: `${project.name} logo`,
|
|
|
- className: "farama-black-logo-invert"
|
|
|
+ className:'farama-header-menu__subsection-title' ,
|
|
|
+ innerText: subKey
|
|
|
}
|
|
|
- );
|
|
|
- aElem.appendChild(imgElem);
|
|
|
- }
|
|
|
- aElem.appendChild(document.createTextNode(project.name));
|
|
|
- ulElem.appendChild(liElem);
|
|
|
+ ))
|
|
|
+ const ulElem = createProjectsList(subSections[subKey], key !== "Foundation");
|
|
|
+ subSectionElem.appendChild(ulElem);
|
|
|
+ subSectionContainerElem.appendChild(subSectionElem);
|
|
|
+ })
|
|
|
+ sectionElem.appendChild(subSectionContainerElem);
|
|
|
+ } else {
|
|
|
+ const projects = sections[key];
|
|
|
+ const ulElem = createProjectsList(projects, true);
|
|
|
+ sectionElem.appendChild(ulElem);
|
|
|
}
|
|
|
- sectionElem.appendChild(ulElem);
|
|
|
menuContainer.appendChild(sectionElem)
|
|
|
});
|
|
|
}
|