表示調整
閉じる
挿絵表示切替ボタン
▼配色
▼行間
▼文字サイズ
▼メニューバー
×閉じる

ブックマークに追加しました

設定
0/400
設定を保存しました
エラーが発生しました
※文字以内
ブックマークを解除しました。

エラーが発生しました。

エラーの原因がわからない場合はヘルプセンターをご確認ください。

38/210

ここまでの”C:\MyTest\GameBook\src\app\home\home.page.ts”

"home.page.ts"は長いですが、半分近くはPage.jsonから自動的に作ったプロパティ定義です。

https://ncode.syosetu.com/n5283hn/34/


自動作成のプロパティ定義

・// Prpoperty From Page.json Start

・// Prpoperty From Page.json End

で囲まれた部分


自動作成の関数

・// Function Set Property Value From Page.json Start

・// Function Set Property Value From Page.json End

で囲まれた部分


自動生成の関数自体

・fnMakePropertyAndFunction(test:boolean){}


このページのソース全体

文字数(空白・改行含む):7006字

文字数(空白・改行含まない):5693字


うち、自動作成部分が

文字数(空白・改行含む):2932字

文字数(空白・改行含まない):2506字


また自動生成関数部分が

文字数(空白・改行含む):1588字

文字数(空白・改行含まない):1180字

import { Component, setTestabilityGetter } from '@angular/core';

import PageData from 'src/app/MyData/Page.json';

import { Title } from '@angular/platform-browser';


@Component({

selector: 'app-home',

templateUrl: 'home.page.html',

styleUrls: ['home.page.scss'],

})

export class HomePage {

//ThisPage

private _ThisPage : string;

public get ThisPage() : string {

return this._ThisPage;

}

public set ThisPage(v : string) {

this._ThisPage = v;

}

//選んだ選択肢

private _SelectPage : string;

public get SelectPage() : string {

return this._SelectPage;

}

public set SelectPage(v : string) {

this._SelectPage = v;

}

//選択肢表示・非表示

private _dispSelect1 : boolean;

public get dispSelect1() : boolean {

return this._dispSelect1;

}

public set dispSelect1(v : boolean) {

this._dispSelect1 = v;

}

private _dispSelect2 : boolean;

public get dispSelect2() : boolean {

return this._dispSelect2;

}

public set dispSelect2(v : boolean) {

this._dispSelect2 = v;

}

private _dispSelect3 : boolean;

public get dispSelect3() : boolean {

return this._dispSelect3;

}

public set dispSelect3(v : boolean) {

this._dispSelect3 = v;

}

//errorメッセージ表示

private _dispMessageErrorText : boolean;

public get dispMessageErrorText() : boolean {

return this._dispMessageErrorText;

}

public set dispMessageErrorText(v : boolean) {

this._dispMessageErrorText = v;

}


// Prpoperty From Page.json Start

private _PageText1 : string;

public get PageText1() : string {

return this._PageText1;

}

public set PageText1(v : string) {

this._PageText1 = v;

}


private _PageText2 : string;

public get PageText2() : string {

return this._PageText2;

}

public set PageText2(v : string) {

this._PageText2 = v;

}


private _PageText3 : string;

public get PageText3() : string {

return this._PageText3;

}

public set PageText3(v : string) {

this._PageText3 = v;

}


private _PageText4 : string;

public get PageText4() : string {

return this._PageText4;

}

public set PageText4(v : string) {

this._PageText4 = v;

}


private _PageText5 : string;

public get PageText5() : string {

return this._PageText5;

}

public set PageText5(v : string) {

this._PageText5 = v;

}


private _PageSelectNum : string;

public get PageSelectNum() : string {

return this._PageSelectNum;

}

public set PageSelectNum(v : string) {

this._PageSelectNum = v;

}


private _PageSelectText1 : string;

public get PageSelectText1() : string {

return this._PageSelectText1;

}

public set PageSelectText1(v : string) {

this._PageSelectText1 = v;

}


private _PageSelectText2 : string;

public get PageSelectText2() : string {

return this._PageSelectText2;

}

public set PageSelectText2(v : string) {

this._PageSelectText2 = v;

}


private _PageSelectText3 : string;

public get PageSelectText3() : string {

return this._PageSelectText3;

}

public set PageSelectText3(v : string) {

this._PageSelectText3 = v;

}


private _PageSelectPage1 : string;

public get PageSelectPage1() : string {

return this._PageSelectPage1;

}

public set PageSelectPage1(v : string) {

this._PageSelectPage1 = v;

}


private _PageSelectPage2 : string;

public get PageSelectPage2() : string {

return this._PageSelectPage2;

}

public set PageSelectPage2(v : string) {

this._PageSelectPage2 = v;

}


private _PageSelectPage3 : string;

public get PageSelectPage3() : string {

return this._PageSelectPage3;

}

public set PageSelectPage3(v : string) {

this._PageSelectPage3 = v;

}

// Prpoperty From Page.json End


constructor(private titleService: Title) {

//Book.jsonの構造がかわった時、trueセット

//プロパティやfunctionの自動生成

this.fnMakePropertyAndFunction(true);


this.ThisPage = "1";

this.fnSetPropValFromPage();

this.fnDispThisPage();

}

public fnSetTitle(newTitle: string) {

this.titleService.setTitle(newTitle);

}

fnOnClickNextPage(){

if(this.SelectPage != undefined){

this.ThisPage = this.SelectPage;

this.fnSetPropValFromPage();

this.fnDispThisPage();

this.dispMessageErrorText = false;

}else{

this.dispMessageErrorText = true;

}

}

// Function Set Property Value From Page.json Start

fnSetPropValFromPage(){

this.PageText1 = PageData[this.ThisPage].Text1;

this.PageText2 = PageData[this.ThisPage].Text2;

this.PageText3 = PageData[this.ThisPage].Text3;

this.PageText4 = PageData[this.ThisPage].Text4;

this.PageText5 = PageData[this.ThisPage].Text5;

this.PageSelectNum = PageData[this.ThisPage].SelectNum;

this.PageSelectText1 = PageData[this.ThisPage].SelectText1;

this.PageSelectText2 = PageData[this.ThisPage].SelectText2;

this.PageSelectText3 = PageData[this.ThisPage].SelectText3;

this.PageSelectPage1 = PageData[this.ThisPage].SelectPage1;

this.PageSelectPage2 = PageData[this.ThisPage].SelectPage2;

this.PageSelectPage3 = PageData[this.ThisPage].SelectPage3;

this.fnSetTitle(this.PageText1);

}

// Function Set Property Value From Page.json End

fnDispThisPage(){

//選択肢の表示・非表示

switch(this.PageSelectNum){

case "1":

this.dispSelect1 = true;

this.dispSelect2 = false;

this.dispSelect3 = false;

break;

case "2":

this.dispSelect1 = true;

this.dispSelect2 = true;

this.dispSelect3 = false;

break;

case "3":

this.dispSelect1 = true;

this.dispSelect2 = true;

this.dispSelect3 = true;

break;

default:

}

this.SelectPage = undefined; //ラジオボタンの選択解除

//エラーメッセージの非表示

this.dispMessageErrorText = false;

}

//Book.jsonの構造がかわった時用

fnMakePropertyAndFunction(test:boolean){

if(test){

let objProp = [];

objProp.push(" private _value : string;");

objProp.push(" public get value() : string {");

objProp.push(" return this._value;");

objProp.push(" }");

objProp.push(" public set value(v : string) {");

objProp.push(" this._value = v;");

objProp.push(" }");


let objTemp = PageData[1];

let strTempProperty ="// Prpoperty From Page.json Start";

let strTempFunction ="// Function Set Property Value From Page.json Start";

strTempFunction += "\n";

strTempFunction += " fnSetPropValFromPage(){";


for(let i=0;i<Object.keys(objTemp).length;i++){

//Property

let strReplaceWord = "Page" + Object.keys(objTemp)[i];

for(let j=0;j<objProp.length;j++){

strTempProperty += "\n";

strTempProperty += objProp[j].replace("value",strReplaceWord);

}

strTempProperty += "\n";

//function

strTempFunction += "\n this.";

strTempFunction += strReplaceWord;

strTempFunction += " = PageData[this.ThisPage].";

strTempFunction += Object.keys(objTemp)[i];

strTempFunction += ";";

}

strTempProperty +="// Prpoperty From Page.json End";


strTempFunction +="\n this.fnSetTitle(this.PageText1);";

strTempFunction +="\n }";

strTempFunction +="\n// Function Set Property Value From Page.json End";


console.log(strTempProperty);

console.log(strTempFunction);

}

}

}


評価をするにはログインしてください。
ブックマークに追加
ブックマーク機能を使うにはログインしてください。
― 新着の感想 ―
このエピソードに感想はまだ書かれていません。
感想一覧
+注意+

特に記載なき場合、掲載されている作品はすべてフィクションであり実在の人物・団体等とは一切関係ありません。
特に記載なき場合、掲載されている作品の著作権は作者にあります(一部作品除く)。
作者以外の方による作品の引用を超える無断転載は禁止しており、行った場合、著作権法の違反となります。

この作品はリンクフリーです。ご自由にリンク(紹介)してください。
この作品はスマートフォン対応です。スマートフォンかパソコンかを自動で判別し、適切なページを表示します。

↑ページトップへ